From 7536c4019cae029f5a2b7f81d770701ebe146993 Mon Sep 17 00:00:00 2001 From: pritisarap12 Date: Tue, 5 May 2015 14:07:05 +0530 Subject: [PATCH 1/3] CLOUDSTACK-8308-Adding-automation-test-cases-for-VM/Volume-snapshot-testpath-testpath-snapshot-limits --Integrating review changes --- .../testpaths/testpath_snapshot_limits.py | 341 ++++++++++++++++++ tools/marvin/marvin/codes.py | 7 - 2 files changed, 341 insertions(+), 7 deletions(-) create mode 100644 test/integration/testpaths/testpath_snapshot_limits.py diff --git a/test/integration/testpaths/testpath_snapshot_limits.py b/test/integration/testpaths/testpath_snapshot_limits.py new file mode 100644 index 000000000000..a62414c26128 --- /dev/null +++ b/test/integration/testpaths/testpath_snapshot_limits.py @@ -0,0 +1,341 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" Test cases for Storage and Snapshot Limits Test Path +""" + +from nose.plugins.attrib import attr +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import (cleanup_resources, + validateList) +from marvin.lib.base import (Account, + ServiceOffering, + DiskOffering, + Volume, + Resources, + VirtualMachine, + Snapshot + ) +from marvin.lib.common import (get_domain, + get_zone, + get_template + ) + +from marvin.codes import (BACKEDUP, PASS) + +class TestStorageSnapshotsLimits(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + testClient = super(TestStorageSnapshotsLimits, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.testdata = testClient.getParsedTestDataConfig() + cls.hypervisor = cls.testClient.getHypervisorInfo() + + # Get Zone, Domain and templates + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + + cls.template = get_template( + cls.apiclient, + cls.zone.id, + cls.testdata["ostype"]) + + cls._cleanup = [] + + try: + + # Create an account + cls.account = Account.create( + cls.apiclient, + cls.testdata["account"], + domainid=cls.domain.id + ) + cls._cleanup.append(cls.account) + + # Create user api client of the account + cls.userapiclient = testClient.getUserApiClient( + UserName=cls.account.name, + DomainName=cls.account.domain + ) + + # Create Service offering + cls.service_offering = ServiceOffering.create( + cls.apiclient, + cls.testdata["service_offering"], + ) + cls._cleanup.append(cls.service_offering) + + cls.disk_offering = DiskOffering.create( + cls.apiclient, + cls.testdata["disk_offering"], + ) + + cls._cleanup.append(cls.disk_offering) + + cls.vm = VirtualMachine.create( + cls.userapiclient, + cls.testdata["small"], + templateid=cls.template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + zoneid=cls.zone.id, + ) + + except Exception as e: + cls.tearDownClass() + raise e + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.apiclient, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + def tearDown(self): + try: + cleanup_resources(self.apiclient, self.cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + @attr(tags=["basic", "advanced"], required_hardware="true") + def test_01_storage_snapshots_limits(self): + """ Storage and Snapshot Limit + 1. Create Snapshot of ROOT disk. + 2. Verify the Secondary Storage value\ + is increased by the size of snapshot. + 3. Delete Snaphshot. + 4. Verify the Secondary\ + Storage value is decreased by the size of snapshot. + 5. Set the Snapshot limit of Account. + 6. Create Snasphots till limit is reached. + 7. Create Snapshot of ROOT Volume.\ + Creation should fail. + 8. Delete few Snapshots. + 9. Create Snapshot again. + Creation should succeed. + """ + + # Get ROOT Volume + root_volumes_list = Volume.list( + self.userapiclient, + virtualmachineid=self.vm.id, + type='ROOT', + listall=True + ) + + self.assertEqual( + isinstance( + root_volumes_list, + list), + True, + "Check listVolumes for ROOT Disk returns a valid list") + + self.assertNotEqual(len(root_volumes_list), + 0, + "Check listVolumes response for ROOT Disk") + + root_volume = root_volumes_list[0] + + data_volume_created = Volume.create( + self.userapiclient, + self.testdata["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) + + self.vm.attach_volume( + self.userapiclient, + data_volume_created + ) + + data_volumes_list = Volume.list( + self.userapiclient, + id=data_volume_created.id + ) + + data_volume = data_volumes_list[0] + + + # Get Secondary Storage Value from Database + qryresult_before_snapshot = self.dbclient.execute( + " select id, account_name, secondaryStorageTotal\ + from account_view where account_name = '%s';" % + self.account.name) + + self.assertNotEqual( + len(qryresult_before_snapshot), + 0, + "Check sql query to return SecondaryStorageTotal of account") + + secStorageBeforeSnapshot = qryresult_before_snapshot[0][2] + + # Step 1 + snapshot = Snapshot.create( + self.userapiclient, + root_volume.id) + + snapshots_list = Snapshot.list(self.userapiclient, + id=snapshot.id) + + status = validateList(snapshots_list) + self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + + # Verify Snapshot state + self.assertEqual( + snapshots_list[0].state.lower() in [ + BACKEDUP, + ], + True, + "Snapshot state is not as expected. It is %s" % + snapshots_list[0].state + ) + + # Step 2 + qryresult_after_snapshot = self.dbclient.execute( + " select id, account_name, secondaryStorageTotal\ + from account_view where account_name = '%s';" % + self.account.name) + + self.assertNotEqual( + len(qryresult_after_snapshot), + 0, + "Check sql query to return SecondaryStorageTotal of account") + + secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2] + + snapshot_size = snapshots_list[0].physicalsize + secStorageIncreased = secStorageBeforeSnapshot + \ + snapshot_size + + self.assertEqual( + secStorageIncreased, + secStorageAfterSnapshotCreated, + "Secondary storage Total after Snapshot\ + should be incremented by size of snapshot.") + + # Step 3 + snapshot.delete(self.apiclient) + + snapshots_list = Snapshot.list(self.userapiclient, + id=snapshot.id) + + self.assertEqual( + snapshots_list, + None, + "Snapshot not deleted." + ) + + # Step 4 + qryresult_after_snapshot_deleted = self.dbclient.execute( + " select id, account_name, secondaryStorageTotal\ + from account_view where account_name = '%s';" % + self.account.name) + + self.assertNotEqual( + len(qryresult_after_snapshot_deleted), + 0, + "Check sql query to return SecondaryStorageTotal of account") + + secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2] + + secStorageDecreased = secStorageAfterSnapshotCreated - \ + snapshot_size + + self.assertEqual( + secStorageDecreased, + secStorageAfterSnapshotDeleted, + "Secondary storage Total after Snapshot\ + should be incremented by size of snapshot.") + + # Step 5 + # Set Snapshot Limit for account + Resources.updateLimit(self.apiclient, resourcetype=3, + max=1, account=self.account.name, + domainid=self.account.domainid) + + # Step 6 + snapshot = Snapshot.create( + self.userapiclient, + root_volume.id) + + snapshots_list = Snapshot.list(self.userapiclient, + id=snapshot.id) + + status = validateList(snapshots_list) + self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + + # Verify Snapshot state + self.assertEqual( + snapshots_list[0].state.lower() in [ + BACKEDUP, + ], + True, + "Snapshot state is not as expected. It is %s" % + snapshots_list[0].state + ) + + # Step 7 + with self.assertRaises(Exception): + Snapshot.create( + self.userapiclient, + data_volume.id) + + # Step 8 + snapshot.delete(self.userapiclient) + + snapshots_list = Snapshot.list(self.userapiclient, + id=snapshot.id) + + self.assertEqual( + snapshots_list, + None, + "Snapshot not deleted." + ) + + # Step 9 + snapshot = Snapshot.create( + self.userapiclient, + root_volume.id) + + snapshots_list = Snapshot.list(self.userapiclient, + id=snapshot.id) + + status = validateList(snapshots_list) + self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + + # Verify Snapshot state + self.assertEqual( + snapshots_list[0].state.lower() in [ + BACKEDUP, + ], + True, + "Snapshot state is not as expected. It is %s" % + snapshots_list[0].state + ) + + return diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py index f9388f4e7a03..977b86992de2 100644 --- a/tools/marvin/marvin/codes.py +++ b/tools/marvin/marvin/codes.py @@ -133,10 +133,3 @@ ''' VMWAREDVS = "vmwaredvs" -''' -Storage Pool Tags -''' -CLUSTERTAG1 = "cwps1" -CLUSTERTAG2 = "cwps2" -ZONETAG1 = "zwps1" -ZONETAG2 = "zwps2" From 94de6926f53edd7186c6e011f505c596e34ed937 Mon Sep 17 00:00:00 2001 From: pritisarap12 Date: Fri, 17 Apr 2015 14:28:39 +0530 Subject: [PATCH 2/3] CLOUDSTACK-8308-Adding-automation-test-cases-for-VM/Volume-snapshot-testpath-testpath-snapshot-limits --Adding review changes --Cleanup data volume created --- .../testpaths/testpath_snapshot_limits.py | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/test/integration/testpaths/testpath_snapshot_limits.py b/test/integration/testpaths/testpath_snapshot_limits.py index a62414c26128..94d5e95c688b 100644 --- a/test/integration/testpaths/testpath_snapshot_limits.py +++ b/test/integration/testpaths/testpath_snapshot_limits.py @@ -34,7 +34,8 @@ get_template ) -from marvin.codes import (BACKEDUP, PASS) +from marvin.codes import (BACKEDUP, PASS, FAIL) + class TestStorageSnapshotsLimits(cloudstackTestCase): @@ -121,7 +122,7 @@ def tearDown(self): return @attr(tags=["basic", "advanced"], required_hardware="true") - def test_01_storage_snapshots_limits(self): + def test_05_storage_snapshots_limits(self): """ Storage and Snapshot Limit 1. Create Snapshot of ROOT disk. 2. Verify the Secondary Storage value\ @@ -142,20 +143,11 @@ def test_01_storage_snapshots_limits(self): root_volumes_list = Volume.list( self.userapiclient, virtualmachineid=self.vm.id, - type='ROOT', - listall=True + type='ROOT' ) - self.assertEqual( - isinstance( - root_volumes_list, - list), - True, - "Check listVolumes for ROOT Disk returns a valid list") - - self.assertNotEqual(len(root_volumes_list), - 0, - "Check listVolumes response for ROOT Disk") + status = validateList(root_volumes_list) + self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume = root_volumes_list[0] @@ -168,6 +160,8 @@ def test_01_storage_snapshots_limits(self): diskofferingid=self.disk_offering.id ) + self.cleanup.append(data_volume_created) + self.vm.attach_volume( self.userapiclient, data_volume_created @@ -180,16 +174,16 @@ def test_01_storage_snapshots_limits(self): data_volume = data_volumes_list[0] - # Get Secondary Storage Value from Database qryresult_before_snapshot = self.dbclient.execute( " select id, account_name, secondaryStorageTotal\ from account_view where account_name = '%s';" % self.account.name) - self.assertNotEqual( - len(qryresult_before_snapshot), - 0, + status = validateList(qryresult_before_snapshot) + self.assertEqual( + status[0], + PASS, "Check sql query to return SecondaryStorageTotal of account") secStorageBeforeSnapshot = qryresult_before_snapshot[0][2] @@ -203,7 +197,7 @@ def test_01_storage_snapshots_limits(self): id=snapshot.id) status = validateList(snapshots_list) - self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + self.assertEqual(status[0], PASS, "Snapshots List Validation Failed") # Verify Snapshot state self.assertEqual( @@ -221,9 +215,10 @@ def test_01_storage_snapshots_limits(self): from account_view where account_name = '%s';" % self.account.name) - self.assertNotEqual( - len(qryresult_after_snapshot), - 0, + status = validateList(qryresult_after_snapshot) + self.assertEqual( + status[0], + PASS, "Check sql query to return SecondaryStorageTotal of account") secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2] @@ -244,11 +239,8 @@ def test_01_storage_snapshots_limits(self): snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id) - self.assertEqual( - snapshots_list, - None, - "Snapshot not deleted." - ) + status = validateList(snapshots_list) + self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.") # Step 4 qryresult_after_snapshot_deleted = self.dbclient.execute( @@ -256,9 +248,10 @@ def test_01_storage_snapshots_limits(self): from account_view where account_name = '%s';" % self.account.name) - self.assertNotEqual( - len(qryresult_after_snapshot_deleted), - 0, + status = validateList(qryresult_after_snapshot_deleted) + self.assertEqual( + status[0], + PASS, "Check sql query to return SecondaryStorageTotal of account") secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2] @@ -287,7 +280,7 @@ def test_01_storage_snapshots_limits(self): id=snapshot.id) status = validateList(snapshots_list) - self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + self.assertEqual(status[0], PASS, "Snapshots List Validation Failed") # Verify Snapshot state self.assertEqual( @@ -311,11 +304,8 @@ def test_01_storage_snapshots_limits(self): snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id) - self.assertEqual( - snapshots_list, - None, - "Snapshot not deleted." - ) + status = validateList(snapshots_list) + self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.") # Step 9 snapshot = Snapshot.create( @@ -326,7 +316,7 @@ def test_01_storage_snapshots_limits(self): id=snapshot.id) status = validateList(snapshots_list) - self.assertEqual(status[0],PASS,"Snapshots List Validation Failed") + self.assertEqual(status[0], PASS, "Snapshots List Validation Failed") # Verify Snapshot state self.assertEqual( @@ -338,4 +328,9 @@ def test_01_storage_snapshots_limits(self): snapshots_list[0].state ) + self.vm.detach_volume( + self.userapiclient, + data_volumes_list[0] + ) + return From ab194949bb282efbf3082f6411f05c3fda8ecd8c Mon Sep 17 00:00:00 2001 From: pritisarap12 Date: Thu, 23 Apr 2015 13:44:33 +0530 Subject: [PATCH 3/3] CLOUDSTACK-8308-Adding-automation-test-cases-for-VM/Volume-snapshot-testpath-testpath-snapshot-limits --Removing snapsot states as it is already there in the codes.py --- tools/marvin/marvin/codes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py index 977b86992de2..921b619d0563 100644 --- a/tools/marvin/marvin/codes.py +++ b/tools/marvin/marvin/codes.py @@ -132,4 +132,3 @@ Switch Type ''' VMWAREDVS = "vmwaredvs" -