File: rbd_cli_tests.pl

package info (click to toggle)
ceph 10.2.11-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,660 kB
  • sloc: cpp: 851,974; ansic: 54,245; python: 45,589; sh: 30,008; java: 20,516; asm: 10,148; perl: 8,435; makefile: 5,956; php: 909
file content (386 lines) | stat: -rwxr-xr-x 12,940 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#! /usr/bin/perl

=head1 NAME

rbd_cli_tests.pl - Script to test the RBD CLI commands and report the  
test results

=head1 SYNOPSIS

Use:
        perl rbd_cli_tests.pl [--pool pool_name][--help]

Examples:
        perl rbd_cli_tests.pl --pool test_pool 
	or
	perl rbd_cli_tests.pl  --help

=head1 DESCRIPTION

This script intends to test the RBD CLI commands for the scenarios mentioned below
and reports the test results

Positive cases 
Negative cases
-- Boundary value testing
-- Incorrect Parameter values/ Incorrect field values
-- Insufficient parameters / Extra parameters    

=head1 ARGUMENTS

rbd_cli_tests.pl takes the following arguments:
   --pool
   (optional) If not specified, rbd pool is used. 
   --help
   (optional) Displays the usage message.

If cephx is enabled, set 'export CEPH_ARGS="--keyring /etc/ceph/ceph.keyring --id <user>"' 
and execute the script as root.

For Example,for "nova" user, 'export CEPH_ARGS="--keyring /etc/ceph/ceph.keyring --id nova"'

=cut

use Cwd;
use RbdLib qw(perform_action create_image resize_image rename_image copy_image list_image info_image export_image import_image remove_image create_snapshots protect_snapshot unprotect_snapshot clone_image rollback_snapshots purge_snapshots list_snapshots remove_snapshot rbd_map rbd_unmap rbd_showmapped display_result _pre_clean_up _post_clean_up _create_rados_pool display_ceph_os_info $RADOS_MKPOOL $RADOS_RMPOOL $RBD_CREATE $RBD_RESIZE $RBD_INFO $RBD_REMOVE $RBD_RENAME $RBD_MV $RBD_LS $RBD_LIST $RBD_CLONE $RBD_EXPORT $RBD_IMPORT $RBD_CP $RBD_COPY $SNAP_CREATE $SNAP_PROTECT $SNAP_UNPROTECT $SNAP_LS $SNAP_LIST $SNAP_ROLLBACK $SNAP_PURGE $SNAP_REMOVE $POOL_RM_SUCCESS $POOL_MK_SUCCESS $RBD_EXISTS_ERR $RBD_WATCH $RBD_MAP $RBD_UNMAP $RBD_SHOWMAPPED $RBD_CHILDREN $RBD_FLATTEN get_command_output debug_msg $CLI_FLAG);

use Pod::Usage();
use Getopt::Long();

use strict;
my ( $help, $pool );

Getopt::Long::GetOptions(
    'pool=s' => \$pool,
    'help'   => \$help
);

Pod::Usage::pod2usage( -verbose => 1 ) if ($help);

our $pool_name = "rbd";
$pool_name = $pool if ($pool);

#===========Variables used in the script========

our $img_name         = "test_img";
our $snap_name        = "snap1";
our $snap_name2       = "snap2";
our $snap_name3       = "snap3";
our $snap_name4       = "snap4";
our $snap_name5       = "snap5";
our $snap_new         = "snap_new";
our $clone_new        = "clone_new";
our $clone_new1        = "clone_new1";
our $clone_new2        = "clone_new2";
our $snap_test        = "snap_test";
our $new_rbd_img      = "new_rbd_img";
our $non_existing_img = "rbdimage";
our $cp_new           = "newest";
our $exp_file         = "rbd_test_file1";
our $exp_file1        = "rbd_test_file2";
our $exp_file2        = "rbd_test_file3";
our $rbd_imp_file     = "test_file";
our $rbd_imp_image    = "new_imp_img";
our $content          = "This is a test file";
our $rbd_snap_new     = "new";
our $neg_img_name     = "neg_img";
our $new_img_name     = "new_img";
our $max_img_name     = "max_img";
our $img_name1        = "testing_img1";
our $rbd_imp_test     = "new_test_file";
our $non_pool_name = "no_pool";
our $no_snap       = "no_snap";
our $img_name_mv   = "new_img_mv";
our $test_log      = "logfile.txt";
our $success       = "test_completed.txt";
our $fail          = "log.txt";
our $exec_cmd;
our $MSG;
our $pool_name;
our $CLI_FLAG = "TRUE";

# Tests for create image
sub create_image {
    perform_action ( $RBD_CREATE, "$img_name,pool $pool_name,size 1024", 0 );

    perform_action( $RBD_CREATE, "$img_name_mv,pool $pool_name,size 1024", 0 );
    perform_action( $RBD_CREATE, "$img_name_mv,pool $pool_name,size 0,order 22",
        1 );
    perform_action( $RBD_CREATE, "$img_name1,pool $pool_name,size 0",     0 );
    perform_action( $RBD_CREATE, "$neg_img_name,pool $pool_name,size -1", 2 );
    perform_action( $RBD_CREATE, "$img_name1 pool $pool_name",            2 );
    perform_action( $RBD_CREATE, "--size 1024",                           2 );
    perform_action( $RBD_CREATE,
        "$max_img_name,pool $pool_name,size 1024000000000", 0 );
    perform_action( $RBD_CREATE, "$img_name1,pool $pool_name,size 2048,order",
        2 );
    perform_action( $RBD_CREATE, "$img_name1,pool $pool_name,size,order 22",
        2 );
    perform_action( $RBD_CREATE,
        "$new_img_name,pool $pool_name,size 1024,new-format", 0 );

}

# Tests to create snapshot
sub create_snapshots {
    perform_action( $SNAP_CREATE, "--snap $snap_name $pool_name\/$img_name",
        0 );
    perform_action( $SNAP_CREATE, "--snap $snap_name $pool_name\/$img_name",
        1 );
    perform_action( $SNAP_CREATE, "$snap_name", 2 );

    perform_action($SNAP_CREATE,"--snap $snap_name2 $pool_name\/$img_name",0);
    perform_action( $SNAP_CREATE, "--snap $snap_name3 $pool_name\/$img_name",
        0 );
    perform_action( $SNAP_CREATE, "--snap $snap_name4 $pool_name\/$img_name",
        0 );
    perform_action( $SNAP_CREATE, "--snap $snap_new $pool_name\/$new_img_name",
        0 );
}

# Tests to protect snapshot
sub protect_snapshot {
    perform_action( $SNAP_PROTECT, "--snap $snap_new $pool_name\/$new_img_name",
        0 );
    perform_action( $SNAP_PROTECT, "--snap $snap_new $pool_name\/$new_img_name",
        2 );
    perform_action( $SNAP_PROTECT, "--snap $snap_name4 $pool_name\/$img_name",
        2 );
    perform_action( $SNAP_PROTECT, "--snap $snap_test $pool_name\/$img_name",
        2 );
}

# Tests to unprotect snapshot
sub unprotect_snapshot {
    perform_action( $SNAP_UNPROTECT, "--snap $snap_new $pool_name\/$new_img_name",
        0 );
    perform_action( $SNAP_UNPROTECT, "--snap $snap_new $pool_name\/$new_img_name",
        2 );
    perform_action( $SNAP_UNPROTECT, "--snap $snap_name4 $pool_name\/$img_name",
        2 );
    perform_action( $SNAP_UNPROTECT, "--snap $snap_test $pool_name\/$img_name",
        2 );
}

# clone protected snapshot
sub clone_image {
    perform_action( $RBD_CLONE, "$pool_name\/$new_img_name\@$snap_new $pool_name\/$clone_new",
        0 );
    perform_action( $RBD_CLONE, "$pool_name\/$new_img_name\@$snap_new $pool_name\/$clone_new",
        1 );
    perform_action( $RBD_CLONE, "$pool_name\/$new_img_name\@$snap_name5 $pool_name\/$clone_new1",
        2 );
    perform_action( $RBD_CLONE, "$pool_name\/$img_name\@$snap_test $pool_name\/$clone_new1",
        2 );
    perform_action( $RBD_CLONE, "$pool_name\/$img_name\@$snap_name5 $pool_name\/$clone_new2",
        2 );
    perform_action( $RBD_CLONE, "$pool_name\/$img_name\@$snap_new",
        2 );
    perform_action( $RBD_CLONE, "$pool_name\/$img_name",
        2 );
}

#flatten image
sub rbd_flatten {
    perform_action( $RBD_FLATTEN, "$pool_name\/$clone_new", 0);
    perform_action( $RBD_FLATTEN, "$pool_name\/$clone_new", 2);
    perform_action( $RBD_FLATTEN, "$pool_name\/$clone_new2", 2);
    perform_action( $RBD_FLATTEN, "$pool_name\/$new_img_name", 2);
}

# Tests to rollback snapshot
sub rollback_snapshot {
    perform_action( $SNAP_ROLLBACK, "--snap $snap_name2 $pool_name\/$img_name",
        0 );
    perform_action( $SNAP_ROLLBACK,
        "--snap $rbd_snap_new $pool_name\/$img_name", 2 );
    perform_action( $SNAP_ROLLBACK,
        "--snap $snap_name $pool_name\/$new_rbd_img", 2 );
}

# Tests to purge snapshots
sub purge_snapshots {
    perform_action( $SNAP_PURGE, "$pool_name\/$img_name",    0 );
    perform_action( $SNAP_PURGE, "$pool_name\/$new_rbd_img", 2 );
    perform_action( $SNAP_PURGE, "$pool_name\/$new_img_name", 2 );
}

# Tests to list snapshots for an image
sub list_snapshots {
    perform_action( $SNAP_LIST, "$pool_name\/$non_existing_img", 2 );
}

# Tests for remove snapshots
sub remove_snapshot {
    perform_action( $SNAP_REMOVE, "$pool_name\/$img_name\@$snap_name",      0 );
    perform_action( $SNAP_REMOVE, "$pool_name\/$new_img_name\@$snap_new",      2 );
    perform_action( $SNAP_REMOVE, "$non_pool_name\/$img_name\@$snap_name3", 2 );
    perform_action( $SNAP_REMOVE, "$pool_name\/$img_name\@$snap_name2",     0 );
    perform_action( $SNAP_REMOVE, "$pool_name\/$non_existing_img",          2 );
    perform_action( $SNAP_REMOVE, " ",                                      2 );
}

# Tests for resize image
sub resize_image {
    perform_action( $RBD_RESIZE, "$img_name,size 1024,pool $pool_name", 0 );
    perform_action( $RBD_RESIZE, "$non_existing_img,size 1024,pool $pool_name",
        2 );
}

# Tests for list rbd image
sub list_image {
    perform_action( $RBD_LIST, "$non_pool_name", 2 );
}

# Tests to copy rbd image
sub copy_image {
    perform_action( $RBD_CP, "$pool_name\/$img_name $pool_name\/$cp_new", 0 );
    perform_action( $RBD_CP, "$pool_name\/$non_existing_img",             2 );
}

# Tests for rbd info
sub info_image {
    perform_action( $RBD_INFO, "$pool_name\/$img_name", 0 );
    perform_action( $RBD_INFO, "--snap $snap_name $pool_name\/$img_name_mv",
        2 );
    perform_action( $RBD_INFO, "--snap $no_snap $pool_name\/$img_name", 2 );
    perform_action( $RBD_INFO, "$pool_name\/$non_existing_img",         2 );
}

# Tests for rename image
sub rename_image {
    perform_action( $RBD_RENAME,
        "$pool_name\/$img_name_mv $pool_name\/$new_rbd_img", 0 );
    perform_action(  $RBD_MV,
        "$pool_name\/$new_rbd_img $pool_name\/$img_name_mv", 0 );
}

# Tests for remove image
sub remove_image {
    perform_action( $RBD_REMOVE,"$pool_name\/$img_name",0);
    perform_action( $RBD_REMOVE, "$pool_name\/$new_rbd_img", 2 );
    perform_action( $RBD_REMOVE, "$pool_name\/$rbd_imp_image", 0 );
    perform_action( $RBD_REMOVE, "$pool_name\/$cp_new",            0 );
    perform_action( $RBD_REMOVE, " ",                                2 );
}

# Tests for export rbd image
sub export_image {
    perform_action( $RBD_EXPORT, "$pool_name\/$img_name $exp_file", 0 );
    perform_action( $RBD_EXPORT, "$pool_name\/$img_name .",         2 );
    perform_action( $RBD_EXPORT, "$pool_name\/$img_name",           0 );
    perform_action( $RBD_EXPORT,
        "--snap $snap_name $pool_name\/$img_name $exp_file1", 0 );
    perform_action( $RBD_EXPORT,
        "--snap $no_snap $pool_name\/$img_name $exp_file1", 2 );
    perform_action( $RBD_EXPORT,
        "--snap $snap_name $pool_name\/$non_existing_img $exp_file2", 2 );
}

# Tests for import file to rbd image
sub import_image {
    my $i = create_test_file( $rbd_imp_file, $content );
    if ( $i == 0 ) {
        perform_action( $RBD_IMPORT, "$rbd_imp_file $pool_name\/$rbd_imp_image", 0 );
    }
    create_test_file( "$rbd_imp_test", 0 );
    perform_action( $RBD_IMPORT, "$rbd_imp_test $pool_name\/$rbd_imp_image", 2);
    perform_action( $RBD_IMPORT, "$exp_file $pool_name\/$rbd_imp_image", 2 );
}

# To map rbd image to device
sub rbd_map {

    # Execute "modprobe rbd"
    my $cmd = get_command_output("sudo modprobe rbd");
    if ( !$cmd ) {
        perform_action( $RBD_MAP, "$pool_name\/$img_name", 0 );
        rbd_showmapped();
        perform_action( $RBD_MAP, "$pool_name\/$non_existing_img", 2 );
    }
}

# To list rbd map
sub rbd_showmapped {
    perform_action( $RBD_SHOWMAPPED, "", 0 );
}

# To unmap rbd device
sub rbd_unmap {
    perform_action( $RBD_UNMAP, "/dev/rbd0", 0 );
    sleep(10);
    perform_action( $RBD_UNMAP, "/dev/rbd10", 2 );
}

# To create a test file and write to it
sub create_test_file {
    my ( $test_arg, $content ) = @_;
    my $command = "touch $test_arg";
    my $cmd     = get_command_output($command);
    if ( ( !$cmd ) && ($content) ) {
        $command = "echo $content > $test_arg";
        $cmd     = get_command_output($command);
        if ( !$cmd ) {
            my $cmd = get_command_output("ls -l $test_arg");
        }
        else {
            return 1;
        }
    }
    else {
        return 1;
    }
    return 0;
}

# deletes and creates a given rados pool  
sub _create_rados_pool {
    $exec_cmd = get_command_output("$RADOS_RMPOOL $pool_name");
    if (   ( $exec_cmd =~ /$POOL_RM_SUCCESS/ )
        || ( $exec_cmd =~ /does not exist/ ) )
    {
        debug_msg("Pool $pool_name deleted");
    }
    $exec_cmd = get_command_output("$RADOS_MKPOOL $pool_name");
    if (   ( $exec_cmd =~ /$POOL_MK_SUCCESS/ )
        || ( $exec_cmd =~ /$RBD_EXISTS_ERR/ ) )
    {
        debug_msg("Pool $pool_name created");
    }
}

sub _del_pool {
    $exec_cmd = get_command_output("$RADOS_RMPOOL $pool_name");
    if (   ( $exec_cmd =~ /$POOL_RM_SUCCESS/ )
        || ( $exec_cmd =~ /does not exist/ ) )
    {
        debug_msg("Pool $pool_name deleted");
    }
}

#== Main starts here===

_pre_clean_up();
display_ceph_os_info();
_create_rados_pool();
create_image();
list_image();
rename_image();
resize_image();
info_image();
create_snapshots();
protect_snapshot();
export_image();
import_image();
list_snapshots();
rollback_snapshot();
remove_snapshot();
purge_snapshots();
clone_image();
rbd_flatten();
unprotect_snapshot();
copy_image();
remove_image();
display_result();
_post_clean_up();
_del_pool();