|
16 | 16 | # under the License.
|
17 | 17 |
|
18 | 18 | # Import Local Modules
|
19 |
| -from marvin.codes import FAILED, KVM |
| 19 | +from marvin.codes import FAILED, KVM, PASS |
20 | 20 | from nose.plugins.attrib import attr
|
21 | 21 | from marvin.cloudstackTestCase import cloudstackTestCase, unittest
|
22 |
| -from marvin.lib.utils import random_gen, cleanup_resources |
| 22 | +from marvin.lib.utils import random_gen, cleanup_resources, validateList |
23 | 23 | from marvin.lib.base import (Account,
|
24 | 24 | ServiceOffering,
|
25 | 25 | VirtualMachine,
|
26 |
| - VmSnapshot) |
| 26 | + VmSnapshot, |
| 27 | + Volume, |
| 28 | + Snapshot) |
27 | 29 | from marvin.lib.common import (get_zone,
|
28 | 30 | get_domain,
|
29 | 31 | get_template)
|
@@ -273,3 +275,116 @@ def test_03_delete_vm_snapshots(self):
|
273 | 275 | None,
|
274 | 276 | "Check list vm snapshot has be deleted"
|
275 | 277 | )
|
| 278 | + |
| 279 | +class TestSnapshots(cloudstackTestCase): |
| 280 | + |
| 281 | + @classmethod |
| 282 | + def setUpClass(cls): |
| 283 | + try: |
| 284 | + cls._cleanup = [] |
| 285 | + cls.testClient = super(TestSnapshots, cls).getClsTestClient() |
| 286 | + cls.api_client = cls.testClient.getApiClient() |
| 287 | + cls.services = cls.testClient.getParsedTestDataConfig() |
| 288 | + cls.hypervisor = cls.testClient.getHypervisorInfo() |
| 289 | + if cls.hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"): |
| 290 | + raise unittest.SkipTest( |
| 291 | + "VM snapshot feature is not supported on KVM, Hyper-V or LXC") |
| 292 | + # Get Domain, Zone, Template |
| 293 | + cls.domain = get_domain(cls.api_client) |
| 294 | + cls.zone = get_zone( |
| 295 | + cls.api_client, |
| 296 | + cls.testClient.getZoneForTests()) |
| 297 | + cls.template = get_template( |
| 298 | + cls.api_client, |
| 299 | + cls.zone.id, |
| 300 | + cls.services["ostype"] |
| 301 | + ) |
| 302 | + if cls.zone.localstorageenabled: |
| 303 | + cls.storagetype = 'local' |
| 304 | + cls.services["service_offerings"][ |
| 305 | + "tiny"]["storagetype"] = 'local' |
| 306 | + else: |
| 307 | + cls.storagetype = 'shared' |
| 308 | + cls.services["service_offerings"][ |
| 309 | + "tiny"]["storagetype"] = 'shared' |
| 310 | + |
| 311 | + cls.services['mode'] = cls.zone.networktype |
| 312 | + cls.services["virtual_machine"]["hypervisor"] = cls.hypervisor |
| 313 | + cls.services["virtual_machine"]["zoneid"] = cls.zone.id |
| 314 | + cls.services["virtual_machine"]["template"] = cls.template.id |
| 315 | + cls.services["custom_volume"]["zoneid"] = cls.zone.id |
| 316 | + # Creating Disk offering, Service Offering and Account |
| 317 | + cls.service_offering = ServiceOffering.create( |
| 318 | + cls.api_client, |
| 319 | + cls.services["service_offerings"]["tiny"] |
| 320 | + ) |
| 321 | + cls._cleanup.append(cls.service_offering) |
| 322 | + cls.account = Account.create( |
| 323 | + cls.api_client, |
| 324 | + cls.services["account"], |
| 325 | + domainid=cls.domain.id |
| 326 | + ) |
| 327 | + cls._cleanup.append(cls.account) |
| 328 | + except Exception as e: |
| 329 | + cls.tearDownClass() |
| 330 | + raise Exception("Warning: Exception in setup : %s" % e) |
| 331 | + return |
| 332 | + |
| 333 | + def setUp(self): |
| 334 | + |
| 335 | + self.apiclient = self.testClient.getApiClient() |
| 336 | + self.cleanup = [] |
| 337 | + |
| 338 | + def tearDown(self): |
| 339 | + # Clean up, terminate the created resources |
| 340 | + cleanup_resources(self.apiclient, self.cleanup) |
| 341 | + return |
| 342 | + |
| 343 | + @classmethod |
| 344 | + def tearDownClass(cls): |
| 345 | + try: |
| 346 | + cleanup_resources(cls.api_client, cls._cleanup) |
| 347 | + except Exception as e: |
| 348 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 349 | + |
| 350 | + return |
| 351 | + |
| 352 | + @attr(tags=["advanced", "basic", "smoke"], required_hardware="true") |
| 353 | + def test_01_test_vm_volume_snapshot(self): |
| 354 | + """ |
| 355 | + @Desc: Test that Volume snapshot for root volume not allowed |
| 356 | + when VM snapshot is present for the VM |
| 357 | + @Steps: |
| 358 | + 1: Deploy a VM and create a VM snapshot for VM |
| 359 | + 2: Try to create snapshot for the root volume of the VM, |
| 360 | + It should fail |
| 361 | + """ |
| 362 | + |
| 363 | + # Creating Virtual Machine |
| 364 | + virtual_machine = VirtualMachine.create( |
| 365 | + self.apiclient, |
| 366 | + self.services["virtual_machine"], |
| 367 | + accountid=self.account.name, |
| 368 | + domainid=self.account.domainid, |
| 369 | + serviceofferingid=self.service_offering.id, |
| 370 | + ) |
| 371 | + |
| 372 | + VmSnapshot.create( |
| 373 | + self.apiclient, |
| 374 | + virtual_machine.id, |
| 375 | + ) |
| 376 | + |
| 377 | + volumes = Volume.list(self.apiclient, |
| 378 | + virtualmachineid=virtual_machine.id, |
| 379 | + type="ROOT", |
| 380 | + listall=True) |
| 381 | + |
| 382 | + self.assertEqual(validateList(volumes)[0], PASS, |
| 383 | + "Failed to get root volume of the VM") |
| 384 | + |
| 385 | + volume = volumes[0] |
| 386 | + |
| 387 | + with self.assertRaises(Exception): |
| 388 | + Snapshot.create(self.apiclient, |
| 389 | + volume_id=volume.id) |
| 390 | + return |
0 commit comments