|
31 | 31 | ) |
32 | 32 | from marvin.lib.common import (get_domain, |
33 | 33 | get_zone, |
34 | | - get_template |
| 34 | + get_template, |
| 35 | + createChecksum, |
| 36 | + list_volumes |
35 | 37 | ) |
36 | 38 |
|
37 | | -from marvin.codes import (BACKED_UP, PASS, FAIL) |
| 39 | +from marvin.codes import (BACKED_UP, PASS, FAIL, ROOT) |
| 40 | +import time |
38 | 41 |
|
39 | 42 |
|
40 | 43 | class TestStorageSnapshotsLimits(cloudstackTestCase): |
@@ -99,6 +102,7 @@ def setUpClass(cls): |
99 | 102 | domainid=cls.account.domainid, |
100 | 103 | serviceofferingid=cls.service_offering.id, |
101 | 104 | zoneid=cls.zone.id, |
| 105 | + mode=cls.zone.networktype |
102 | 106 | ) |
103 | 107 |
|
104 | 108 | except Exception as e: |
@@ -137,7 +141,6 @@ def tearDown(self): |
137 | 141 | PASS, |
138 | 142 | "DATA Volume List Validation Failed") |
139 | 143 |
|
140 | | - if data_volumes_list: |
141 | 144 | self.vm.detach_volume( |
142 | 145 | self.userapiclient, |
143 | 146 | data_volumes_list[0] |
@@ -359,3 +362,129 @@ def test_01_storage_snapshots_limits(self): |
359 | 362 | ) |
360 | 363 |
|
361 | 364 | return |
| 365 | + |
| 366 | + @attr(tags=["advanced", "basic"], required_hardware="true") |
| 367 | + def test_02_snapshot_size_check(self): |
| 368 | + """ Check Snapshots size in database |
| 369 | + 1. Create file on ROOT disk of deployed VM. |
| 370 | + 2. Create Snapshot of ROOT disk. |
| 371 | + 3. Check if physiacal_size parameter of snapshot_store_ref table |
| 372 | + has physical size of snapshot |
| 373 | + """ |
| 374 | + if self.hypervisor.lower() not in ["xenserver", "vmware"]: |
| 375 | + self.skipTest("Test not to be run on %s" % self.hypervisor) |
| 376 | + |
| 377 | + root_volumes_list = list_volumes( |
| 378 | + self.apiclient, |
| 379 | + virtualmachineid=self.vm.id, |
| 380 | + type=ROOT, |
| 381 | + listall=True |
| 382 | + ) |
| 383 | + |
| 384 | + status = validateList(root_volumes_list) |
| 385 | + self.assertEqual( |
| 386 | + status[0], |
| 387 | + PASS, |
| 388 | + "Check listVolumes response for ROOT Disk") |
| 389 | + |
| 390 | + root_volume = root_volumes_list[0] |
| 391 | + |
| 392 | + # Get Secondary Storage Value from Database |
| 393 | + qryresult_before_snapshot = self.dbclient.execute( |
| 394 | + " select id, account_name, secondaryStorageTotal\ |
| 395 | + from account_view where account_name = '%s';" % |
| 396 | + self.account.name) |
| 397 | + |
| 398 | + self.assertNotEqual( |
| 399 | + len(qryresult_before_snapshot), |
| 400 | + 0, |
| 401 | + "Check sql query to return SecondaryStorageTotal of account") |
| 402 | + |
| 403 | + storage_qry_result_old = qryresult_before_snapshot[0] |
| 404 | + secondary_storage_old = storage_qry_result_old[2] |
| 405 | + |
| 406 | + createChecksum( |
| 407 | + self.testdata, |
| 408 | + self.vm, |
| 409 | + root_volume, |
| 410 | + "rootdiskdevice") |
| 411 | + |
| 412 | + time.sleep(30) |
| 413 | + |
| 414 | + root_vol_snapshot = Snapshot.create( |
| 415 | + self.apiclient, |
| 416 | + root_volume.id) |
| 417 | + |
| 418 | + snapshots_list = Snapshot.list(self.apiclient, |
| 419 | + id=root_vol_snapshot.id) |
| 420 | + |
| 421 | + status = validateList(snapshots_list) |
| 422 | + self.assertEqual(status[0], PASS, "Check listSnapshots response") |
| 423 | + # Verify Snapshot state |
| 424 | + self.assertEqual( |
| 425 | + snapshots_list[0].state.lower() in [ |
| 426 | + BACKED_UP, |
| 427 | + ], |
| 428 | + True, |
| 429 | + "Snapshot state is not as expected. It is %s" % |
| 430 | + snapshots_list[0].state |
| 431 | + ) |
| 432 | + |
| 433 | + self.assertEqual( |
| 434 | + snapshots_list[0].volumeid, |
| 435 | + root_volume.id, |
| 436 | + "Snapshot volume id is not matching with the vm's volume id") |
| 437 | + |
| 438 | + qryresult_snp_id = self.dbclient.execute( |
| 439 | + "select id\ |
| 440 | + from snapshots where uuid = '%s';" % |
| 441 | + snapshots_list[0].id) |
| 442 | + |
| 443 | + self.assertNotEqual( |
| 444 | + len(qryresult_snp_id), |
| 445 | + 0, |
| 446 | + "Check sql query to return physical size of the snapshot") |
| 447 | + |
| 448 | + snp_id_result = qryresult_snp_id[0] |
| 449 | + snp_id = snp_id_result[0] |
| 450 | + |
| 451 | + qryresult_physical_size = self.dbclient.execute( |
| 452 | + " select id, store_id, physical_size\ |
| 453 | + from snapshot_store_ref where snapshot_id = '%s' \ |
| 454 | + and store_role='Image';" % |
| 455 | + snp_id) |
| 456 | + |
| 457 | + self.assertNotEqual( |
| 458 | + len(qryresult_physical_size), |
| 459 | + 0, |
| 460 | + "Check sql query to return SecondaryStorageTotal of account") |
| 461 | + |
| 462 | + snapshot_physical_size_result = qryresult_physical_size[0] |
| 463 | + snapshot_physical_size = snapshot_physical_size_result[ |
| 464 | + 2] |
| 465 | + |
| 466 | + # Step 3 |
| 467 | + qryresult_after_snapshot = self.dbclient.execute( |
| 468 | + " select id, account_name, secondaryStorageTotal\ |
| 469 | + from account_view where account_name = '%s';" % |
| 470 | + self.account.name) |
| 471 | + self.assertNotEqual( |
| 472 | + len(qryresult_after_snapshot), |
| 473 | + 0, |
| 474 | + "Check sql query to return SecondaryStorageTotal of account") |
| 475 | + |
| 476 | + storage_qry_result_from_database = qryresult_after_snapshot[0] |
| 477 | + secondary_storage_new = storage_qry_result_from_database[ |
| 478 | + 2] |
| 479 | + |
| 480 | + secondary_storage_after_snapshot = secondary_storage_new - \ |
| 481 | + secondary_storage_old |
| 482 | + |
| 483 | + self.assertEqual( |
| 484 | + snapshot_physical_size, |
| 485 | + secondary_storage_after_snapshot, |
| 486 | + "Check if physical_size attribute of snapshot_store_ref table \ |
| 487 | + stores correct value" |
| 488 | + ) |
| 489 | + |
| 490 | + return |
0 commit comments