File: pt-mysql-summary_encryption.t

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (161 lines) | stat: -rw-r--r-- 4,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env perl

BEGIN {
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};

use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use PerconaTest;
use Sandbox;
use DSNParser;
require VersionParser;
use Test::More;
use File::Temp qw( tempdir );

local $ENV{PTDEBUG} = "";

my $dp         = new DSNParser(opts=>$dsn_opts);
my $sb         = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $has_keyring_plugin;

my $db_flavor = VersionParser->new($master_dbh)->flavor();
if ( $db_flavor =~ m/Percona Server/ ) {
    my $rows = $master_dbh->selectall_hashref("SHOW PLUGINS", "name");
    while (my ($key, $values) = each %$rows) {
        if ($key =~ m/^keyring_/) {
            $has_keyring_plugin=1;
            last;
        }
    }
}

if (!$has_keyring_plugin) {
    plan skip_all => 'Keyring plugins are not enabled.';
} elsif ( $sandbox_version lt '5.7' || $db_flavor !~ m/Percona Server/) {
    plan skip_all => 'These tests need Percona Server 5.7+';
}

my ($tool) = $PROGRAM_NAME =~ m/([\w-]+)_encryption\.t$/;

# mysqldump from earlier versions doesn't seem to work with 5.6,
# so use the actual mysqldump from each MySQL bin which should
# always be compatible with itself.
my $env = qq\CMD_MYSQLDUMP="$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqldump"\;

#
# --save-samples
#

my $dir = tempdir( "percona-testXXXXXXXX", CLEANUP => 1 );

`$env $trunk/bin/$tool --sleep 1 --save-samples $dir -- --defaults-file=/tmp/12345/my.sandbox.cnf`;

ok(
   -e $dir,
   "Using --save-samples doesn't mistakenly delete the target dir"
);

# If the box has a default my.cnf (e.g. /etc/my.cnf) there
# should be 15 files, else 14.
my @files = glob("$dir/*");
my $n_files = scalar @files;
ok(
   $n_files >= 15 && $n_files <= 18,
   "And leaves all files in there"
) or diag($n_files, `ls -l $dir`);

undef($dir);  # rm the dir because CLEANUP => 1

#
# --databases
#

my $out = `$env $trunk/bin/$tool --sleep 1 --databases mysql 2>/dev/null -- --defaults-file=/tmp/12345/my.sandbox.cnf`;

like(
   $out,
   qr/Database Tables Views SPs Trigs Funcs   FKs Partn\s+\Qmysql\E/,
   "--databases works"
);

like(
   $out,
   qr/# InnoDB #.*Version.*# MyISAM #/s,
   "InnoDB section present"
);

like(
   $out,
   qr/Users \| 2/,
   "Security works"
);

# --read-samples
for my $i (2..7) {
   ok(
      no_diff(
         sub {
            local $ENV{_NO_FALSE_NEGATIVES} = 1;
            print `$env $trunk/bin/$tool --read-samples $trunk/t/pt-mysql-summary/samples/temp00$i  -- --defaults-file=/tmp/12345/my.sandbox.cnf | tail -n+3 | perl -wlnpe 's/Skipping schema analysis.*/Specify --databases or --all-databases to dump and summarize schemas/' | grep -v jemalloc`
         },
         "t/pt-mysql-summary/samples/expected_output_temp_enc00$i.txt",
      ),
      "--read-samples works for t/pt-mysql-summary/temp_enc00$i",
   ) or diag($test_diff);
}

# Test that --help works under sh

my $sh   = `sh   $trunk/bin/$tool --help`;
my $bash = `bash $trunk/bin/$tool --help`;

is(
   $sh,
   $bash,
   "--help works under sh and bash"
);

$master_dbh->do("DROP DATABASE IF EXISTS test");
$master_dbh->do("CREATE DATABASE test");
$master_dbh->do("CREATE TABLE test.t1(a INT PRIMARY KEY) ENCRYPTION='Y'");
$master_dbh->do("CREATE TABLESPACE foo ADD DATAFILE 'foo.ibd' ENCRYPTION='Y'");
$master_dbh->do("ALTER TABLE test.t1 TABLESPACE=foo");
$master_dbh->do("CREATE TABLE test.t2(a INT PRIMARY KEY) ENCRYPTION='Y'");

$out = `bash $trunk/bin/$tool --list-encrypted-tables`;

like(
   $out,
   qr/Encryption/,
   "Encryption section included in report"
) or diag $out;

like(
   $out,
   qr/Keyring plugins/,
   "Keyring plugins included in report"
) or diag $out;

like(
   $out,
   qr/Encrypted tables/,
   "Encrypted tables included in report"
) or diag $out;

like(
   $out,
   qr/Encrypted tablespaces/,
   "Encrypted tablespaces included in report"
) or diag $out;

$master_dbh->do("DROP TABLE IF EXISTS test.t1");
$master_dbh->do("DROP TABLE IF EXISTS test.t2");
$master_dbh->do("DROP DATABASE IF EXISTS test");
$master_dbh->do("DROP TABLESPACE foo");

done_testing;