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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
|
#! /usr/bin/perl
=head1 NAME
rbd_functional_tests.pl - Script to test the RBD functionality.
=head1 SYNOPSIS
Use:
perl rbd_functional_tests.pl [--help]
Examples:
perl rbd_functional_tests.pl
or
perl rbd_functional_tests.pl --help
=head1 ARGUMENTS
rbd_functional_tests.pl takes the following arguments:
--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 strict;
use warnings;
use Cwd;
use RbdLib qw(perform_action log_results 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_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 $RADOS_LS get_command_output verify_action debug_msg tpass tfail display_func_result $CLI_FLAG);
use Pod::Usage();
use Getopt::Long();
my $help;
Getopt::Long::GetOptions(
'help' => \$help
);
Pod::Usage::pod2usage( -verbose => 1 ) if ($help);
my $pool_name = "rbd";
#===========Variables used in the script========
my $img_name = "test_img";
my $snap_name = "snap1";
my $snap_name2 = "snap2";
my $snap_name3 = "snap3";
my $snap_name4 = "snap4";
my $new_rbd_img = "new_rbd_img";
my $non_existing_img = "rbdimage";
my $cp_new = "new";
my $exp_file = "rbd_test_file1";
my $exp_file1 = "rbd_test_file2";
my $exp_file2 = "rbd_test_file3";
my $rbd_imp_file = "test_file";
my $rbd_imp_image = "new_imp_img";
my $content = "This is a test file";
my $rbd_snap_new = "new";
my $neg_img_name = "neg_img";
my $max_img_name = "max_img";
my $img_name1 = "test_img1";
my $rbd_imp_test = "new_test_file";
my $non_pool_name = "no_pool";
my $no_snap = "no_snap";
my $img_name_mv = "new_img_mv";
my $test_log = "logfile.txt";
my $success = "test_completed.txt";
my $fail = "log.txt";
my $obj_initial = "000000000000";
my $obj_second = "000000000001";
my $exec_cmd;
our $MSG;
our $CLI_FLAG = "FALSE";
my $TC3_LOG = "verify import of file to rbd image and export the same image to file";
my $TC5_LOG = "Export rbd image to already existing non-empty file";
my $TC6_LOG = "Import file to an existing rbd image";
my $TC7_LOG = "verify import of an empty local file to rbd image";
my $TC8_LOG = "verify import of nonexisting file to rbd image";
my $TC9_LOG = "verify import of a directory to rbd image";
my $TC11_LOG = "verify export from an non-existing rbd image";
sub _create_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");
}
}
#To map rbd image to device
sub rbd_mapp {
my $img_name = shift;
# Execute "modprobe rbd"
my $cmd = get_command_output("sudo modprobe rbd");
if ( !$cmd ) {
perform_action( $RBD_MAP, "$pool_name\/$img_name", 0 );
my $ret = rbd_showmapped1($img_name);
print "ret is $ret \n";
return $ret;
#perform_action( $RBD_MAP, "$pool_name\/$non_existing_img", 2 );
}
}
# To list rbd map
sub rbd_showmapped1 {
my $img = shift;
my $ret_map = get_command_output($RBD_SHOWMAPPED);
my @lines = split( /\n/, $ret_map );
shift(@lines);
foreach (@lines) {
if ( $_ =~ /(\d+)\s+(\S+)\s+($img)\s+\-\s+(\S+)/ ) {
print "match $2 and $3 and $4 \n";
return $4;
}
}
return 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 unmap rbd device
sub rbd_unmap_dev {
my $dev = shift;
my $rcode = perform_action( $RBD_UNMAP, $dev, 0 );
return $rcode;
}
# Delete the RBD image used by the client
sub del_mapped_img {
debug_msg("start of test");
my $img = rand();
my $dev;
my $rc_create =
perform_action( $RBD_CREATE, "$img,pool $pool_name,size 100", 0 );
if ( !$rc_create ) {
$dev = rbd_mapp($img);
if ($dev) {
my $rc_del = perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
if ($rc_del) {
tpass("TC22 - Delete mapped rbd img");
perform_action( $RBD_UNMAP, $dev, 0 );
perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
}
else {
tfail("TC22 - Delete mapped rbd img");
}
}
}
debug_msg("end of test");
#log_results();
}
# To create a test file and write to it
sub create_test_file {
my ( $test_file, $dd_ifile ) = @_;
print "dd is $dd_ifile \n";
my $command = "dd if=$dd_ifile of=$test_file bs=1024 count=5000";
my $cmd_op = get_command_output($command);
if ( $cmd_op =~ /records/ ) {
my $csum = get_cksum($test_file);
return $csum;
}
else {
return -1;
}
}
# get cksum of given file
sub get_cksum {
my ($t_file) = @_;
my $csum = get_command_output("cksum $t_file");
my $cksum = ( split / /, $csum )[0];
return $cksum;
}
#import file to rbd image and verify if objects created
sub import_verify_objs {
my ( $img, $file ) = @_;
my $rc = perform_action( $RBD_IMPORT, "$file $img", 0 );
if ( !$rc ) {
my $rc1 = check_rados_objs($img);
debug_msg("import $file $img passed") && return 0 if ( !$rc1 );
}
debug_msg("import $file $img failed");
return 1;
}
sub import_resize_checkobjs {
my $img = "image1";
my $file = "imp_file";
my $dd_if = "/dev/zero";
my $exp_to_file = "/tmp/new";
my $rcc = create_test_file( $file, $dd_if );
if ( $rcc != -1 ) {
my $rc1 = import_verify_objs( $img, $file );
if ( !$rc1 ) {
my $rc2 =
perform_action( $RBD_RESIZE, "$pool_name\/$img --size 0", 0 );
if ( !$rc2 ) {
my $rc3 = check_rados_objs($img);
if ($rc3) {
tpass("TC2 passed: Import file to an image, resize image and verify");
=head - this one hangs
my $rc2 = perform_action( $RBD_EXPORT,"$pool_name\/$img $exp_to_file",0);
if ($rc2) {
tpass( "TC12 Passed - Export image of size 0" );
} else {
tfail( "TC12 Failed - Export image of size 0" );
}
=cut
}
else {
tfail("TC2 failed: Import file to an image, resize and verify");
}
}
}
}
perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
remove_test_files($file);
remove_test_files($exp_to_file);
}
sub remove_test_files {
my $file = shift;
my $cmd = get_command_output("rm -rf $file");
if ( $cmd !~ /./ ) {
debug_msg("$file deleted");
}
else {
debug_msg("$file NOT deleted");
}
}
sub import_export {
my $new_img = "testin";
my $imp_from_file = "/tmp/file1";
my $exp_to_file = "/tmp/file2";
my ( $dd_ip_file, $tc, $tc_log ) = @_;
my $csum = create_test_file( $imp_from_file, $dd_ip_file );
if ( $csum != -1 ) {
my $rc1 = import_verify_objs( $new_img, $imp_from_file );
if ( !$rc1 ) {
my $rc2 = perform_action( $RBD_EXPORT, "$new_img $exp_to_file", 0 );
my $csum2 = get_cksum($exp_to_file);
if ( !$rc2 ) {
if ( $csum == $csum2 ) { tpass("TC$tc passed: $tc_log"); }
else { tfail("TC$tc failed: $tc_log") }
}
}
}
#log_results();
my $a = perform_action( $RBD_REMOVE, "$pool_name\/$new_img", 0 );
remove_test_files($exp_to_file);
remove_test_files($imp_from_file);
}
sub import_rename_export {
my $new_img = "testing_img1";
my $new1_img = "testing_img2";
my $imp_from_file = "/tmp/file1";
my $dd_ifile = "/dev/zero";
my $exp_to_file = "/tmp/file2";
my $csum = create_test_file( $imp_from_file, $dd_ifile );
if ( $csum != -1 ) {
my $rc1 = import_verify_objs( $new_img, $imp_from_file );
my $rc_mv =
perform_action( $RBD_RENAME,
"$pool_name/$new_img $pool_name/$new1_img", 0 )
if ( !$rc1 );
if ( !$rc_mv ) {
my $rc2 = perform_action( $RBD_EXPORT, "$new_img $exp_to_file", 0 );
if ($rc2) {
tpass("TC4 passed: verify import file to an image , rename image and export image");
}
else {
tfail("TC4 failed: verify import file to an image , rename image and export image");
}
}
}
#log_results();
perform_action( $RBD_REMOVE, "$pool_name\/$new1_img", 0 );
remove_test_files($imp_from_file);
}
sub imp_exp_existing {
my ( $cmd, $imgg, $file, $tc, $tc_log ) = @_;
my $dd_if = "/dev/zero";
my $rc2 = " ";
my $rc_create = perform_action( $RBD_CREATE, "$imgg, pool $pool_name, size 1024", 0 );
print ":rc is $rc_create \n";
if ( !$rc_create ) {
my $cksum = create_test_file( $file, $dd_if );
if ( $cksum != -1 ) {
$rc2 = perform_action( "$cmd", "$file $pool_name\/$imgg", 0 )
if ( $cmd eq 'rbd import' );
$rc2 = perform_action( "$cmd", "$pool_name\/$imgg $file", 0 )
if ( $cmd eq 'rbd export' );
if ($rc2) {
tpass("TC$tc passed: $tc_log");
}
else {
tfail("TC$tc failed: $tc_log");
}
}
}
perform_action( $RBD_REMOVE, "$pool_name\/$imgg", 0 );
remove_test_files( $file );
}
sub import_tcs {
my $new_img = rand();
my $rc1;
my ( $option, $tc, $tc_log ) = @_;
get_command_output("touch $option") if ( $tc == 7 );
get_command_output("mkdir $option") if ( $tc == 9 );
if ( ( $tc == 7 ) || ( $tc == 9 ) || ( $tc == 8 ) ) {
$rc1 = perform_action( $RBD_IMPORT, "$option $new_img", 0 );
}
elsif ( $tc == 11 ) {
$rc1 = perform_action( $RBD_EXPORT, "$new_img $option", 0 );
}
if ($rc1) {
tpass("TC$tc passed: $tc_log");
}
else {
tfail("TC$tc failed: $tc_log");
}
remove_test_files($option);
#log_results();
}
sub get_prefix_obj {
my $img = shift;
my $rbd_info_op = verify_action( $RBD_INFO, "$img", 0 );
my @get_prefix_l = split( "\n", $rbd_info_op );
my $get_prefix = ( split /:/, $get_prefix_l[3] )[-1];
$get_prefix =~ s/^\s+//;
return $get_prefix;
}
sub get_img_size {
my $img = shift;
my $rbd_info_op = verify_action( $RBD_INFO, "$img", 0 );
my @get_size_l = split( "\n", $rbd_info_op );
my $get_size = ( split / /, $get_size_l[1] )[1];
return $get_size;
}
sub check_rados_basic_ls {
my ($image) = @_;
my $rbd_image = "$image\.rbd";
my $cmd_output = verify_action( $RADOS_LS, "-p $pool_name", 0 );
if ( ( $cmd_output =~ /rbd_directory/ )
&& ( $cmd_output =~ /$rbd_image/ ) )
{
return 0;
}
else {
return 1;
}
}
sub check_rados_objs {
my ($img) = @_;
my $get_obj_prefix = get_prefix_obj($img);
my $obj1 = "$get_obj_prefix\.$obj_initial";
my $obj2 = "$get_obj_prefix\.$obj_second";
my @get_rados_objs = verify_action( $RADOS_LS, "-p $pool_name", 0 );
if ( ( grep /$obj1/, @get_rados_objs )
&& ( grep /$obj2/, @get_rados_objs ) )
{
return 0;
}
return 1;
}
sub create_check_objs {
my $cmd_rc =
perform_action( $RBD_CREATE, "$img_name,pool $pool_name,size 1024", 0 );
my $rc = check_rados_basic_ls($img_name);
if ( !$rc ) {
tpass("TC1 passed: rados ls passed");
}
else {
tfail("TC1 failed: rados ls failed");
}
#log_results();
}
sub create_snap_resize_rollback {
my $img = rand();
my $snp = rand();
debug_msg("Start of Test");
my $rc_c = create_snapshot( $img, $snp );
if ( !$rc_c ) {
my $rc1 =
perform_action( $RBD_RESIZE, "$pool_name\/$img --size 50", 0 );
if ( !$rc1 ) {
my $rc_sr = rollback_snapshots( $img, $snp );
if ( !$rc_sr ) {
tpass("TC13 passed: create,resize and rollback");
perform_action( $SNAP_PURGE, "$pool_name\/$img", 0 );
perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
}
else {
tfail("TC13 failed: create,resize and rollback");
}
}
}
debug_msg("End of the Test");
#log_results();
}
sub create_snap_rollback {
my $img = rand();
my $snp = rand();
debug_msg("Start of Test");
my $rc_c = create_snapshot( $img, $snp );
if ( !$rc_c ) {
my $rc_sr = rollback_snapshots( $img, $snp );
if ( !$rc_sr ) {
tpass("TC15 passed: create snapshot and rollback snapshot immediately");
perform_action( $SNAP_PURGE, "$pool_name\/$img", 0 );
perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
}
else {
tfail("TC15 failed: create snapshot and rollback snapshot immediately");
}
}
debug_msg("End of the Test");
#log_results();
}
sub create_delete_rollback {
my $img = rand();
my $snp = rand();
debug_msg("Start of Test");
my $rc_c = create_snapshot( $img, $snp );
if ( !$rc_c ) {
my $rc1 = perform_action( $SNAP_REMOVE, "$pool_name\/$img\@$snp", 0 );
if ( !$rc1 ) {
my $rc_sr = rollback_snapshots( $img, $snp );
if ($rc_sr) {
tpass("TC16 passed: create,delete and rollback");
my $rc_srm =
perform_action( $SNAP_PURGE, "$pool_name\/$img", 2 );
if ($rc_srm) {
tpass("TC17 passed: snap purge on image with no snapshots");
}
else {
tfail("TC17 passed: snap purge on image with no snapshot failed");
}
}
else {
tfail("TC16 failed: create,delete and rollback");
}
}
}
my $rc_rm = perform_action( $RBD_REMOVE, "$pool_name\/$img", 0 );
debug_msg("End of the Test");
#log_results();
}
sub create_snapshot {
my ( $image, $snap ) = @_;
my $rc_create =
perform_action( $RBD_CREATE, "$image,pool $pool_name,size 100", 0 );
if ( !$rc_create ) {
my $rc_snap =
perform_action( $SNAP_CREATE, "--snap $snap $pool_name\/$image", 0 );
return $rc_snap;
}
}
sub rollback_snapshots {
my ( $img, $snap ) = @_;
my $rc_sr =
perform_action( $SNAP_ROLLBACK, "--snap $snap $pool_name\/$img", 0 );
if ( !$rc_sr ) {
my $img_size1 = get_img_size($img);
if ( $img_size1 == 102400 ) {
return 0;
}
}
return 1;
}
#===Main===
my $test_img = rand();
my $test_file = rand();
my $test_dir = rand();
_pre_clean_up();
display_ceph_os_info();
_create_pool();
create_check_objs();
import_resize_checkobjs();
import_export( "/dev/zero", 3, $TC3_LOG );
import_rename_export();
imp_exp_existing( $RBD_EXPORT, $test_img, $test_file, 5 , $TC5_LOG);
imp_exp_existing( $RBD_IMPORT, $test_img, $test_file, 6 , $TC6_LOG);
import_tcs( $test_file, 7, $TC7_LOG );
import_tcs( $test_file, 8 , $TC8_LOG);
import_tcs( $test_dir, 9 , $TC9_LOG);
import_tcs( $test_file, 11, $TC11_LOG );
#del_mapped_img () dont execute this when cluster and client is on the same m/c
create_snap_resize_rollback();
create_snap_rollback();
create_delete_rollback();
display_func_result();
|