From 9e8414463d5a548c94b256f949f6b625b591b522 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Thu, 27 Aug 2020 15:57:19 +0200 Subject: [PATCH 1/4] empty frame (proposal) --- .../testpaths/testpath_migration_matrix.py | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 test/integration/testpaths/testpath_migration_matrix.py diff --git a/test/integration/testpaths/testpath_migration_matrix.py b/test/integration/testpaths/testpath_migration_matrix.py new file mode 100644 index 000000000000..4288571d1ac9 --- /dev/null +++ b/test/integration/testpaths/testpath_migration_matrix.py @@ -0,0 +1,222 @@ +# 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 Delta Snapshots Test Path +""" +import time +from marvin.lib.base import ServiceOffering, Configurations, VirtualMachine, Account, Volume, DiskOffering, StoragePool +from marvin.lib.utils import cleanup_resources +from nose.plugins.attrib import attr +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.common import (get_domain, + get_zone, + get_template + ) + +class TestStorageMigrations(cloudstackTestCase): + """ + test a matrix of migration based on a input of available storages and assuming users 'admin' and 'user' + """ + + user_dimension = [ "admin" ] # should be [ "admin", "user"] + system_dimension = [ "6.7" ] # should be [ "6.5", "6.7"] + source_pool_dimension = [ "NFS" ] + targets_pool_dimension = [ "VSAN" ] + # we should use a pool_matrix of + # [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] * [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] + + @classmethod + def setUpClass(cls): + testClient = super(TestStorageMigrations, 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._cleanup = [] + + cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ + cls.skiptest = False + + # for now untill we want to be more generic + if cls.hypervisor.lower() not in ["vmware"]: + cls.skiptest = True + + 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.template = get_template( + cls.apiclient, + cls.zone.id, + cls.testdata["ostype"] + ) + + cls.vm = VirtualMachine.create( + cls.apiclient, + cls.testdata["small"], + templateid=cls.template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + zoneid=cls.zone.id, + mode=cls.zone.networktype + ) + cls._cleanup.append(cls.vm) + cls.disk_offering = DiskOffering.create( + cls.apiclient, + cls.testdata["disk_offering"] + ) + cls._cleanup.append(cls.disk_offering) + + except Exception as e: + cls.tearDownClass() + raise e + return + + def setUp(self): + if self.skiptest: + self.skipTest( + "not testing migration on %s" % + self.hypervisor) + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.apiclient, reversed(cls._cleanup)) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def tearDown(self): + try: + cleanup_resources(self.apiclient, reversed(self.cleanup)) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + @attr(tags=["advanced", "basic"], required_hardware="true") + def test_the_matrix(self): + """ + run the defined tests + :return: + """ + return + + def test_a_migration(self, source, target): + """ + Do a single iteration of the test sequence, + creating the volume on the source migrating and then deleting the volume from the target. + + :param source: source pool to igrate from + :param target: target pool to migrate to + :return: + """ + volume = self.setup_source(source) + self.migrate(volume, target) + self.validate(volume, target) + self.remove_volume(volume) + return + + def setup_source(self, source): + """ + + :param source: the pool to set a volume up on + :return: the marvin volume object + """ + # create a volume with tags for the right primary + # attach the volume to a running vm to have it on primary + # detach the volume + vol = Volume.create( + self.apiclient, + self.testdata["volume"], + diskofferingid=self.disk_offering.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + ) + + self.cleanup.append(vol) + + self.vm.attach_volume( + self.apiclient, + vol + ) + + pools = StoragePool.listForMigration( + self.apiclient, + id=vol.id + ) + + if not pools: + self.skipTest( + "No suitable storage pools found for volume migration.\ + Skipping") + + self.vm.detach_volume(self.apiclient, vol) + + return vol + + def remove_volume(self, volume): + """ + + :param volume: the id of the volume + :return: + """ + volume.delete(self.apiclient) + return + + def migrate(self, volume, target): + """ + + :param volume: + :param target: + :return: + """ + return + + def validate(self, volume, target): + """ + + :param volume: + :param target: + :return: + """ + return \ No newline at end of file From c7da4b032625d1166d7032bb6863d2b9e30b3a0e Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Fri, 28 Aug 2020 19:56:19 +0200 Subject: [PATCH 2/4] first test failing --- .../testpaths/testpath_migration_matrix.py | 87 +++++++++++-------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/test/integration/testpaths/testpath_migration_matrix.py b/test/integration/testpaths/testpath_migration_matrix.py index 4288571d1ac9..cf56731fcc4f 100644 --- a/test/integration/testpaths/testpath_migration_matrix.py +++ b/test/integration/testpaths/testpath_migration_matrix.py @@ -18,7 +18,7 @@ """ import time from marvin.lib.base import ServiceOffering, Configurations, VirtualMachine, Account, Volume, DiskOffering, StoragePool -from marvin.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources, format_volume_to_ext3 from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase from marvin.lib.common import (get_domain, @@ -29,12 +29,16 @@ class TestStorageMigrations(cloudstackTestCase): """ test a matrix of migration based on a input of available storages and assuming users 'admin' and 'user' + as of now this test class makes a lot of assumtions. more defencive programming is needed to do away with those. + - a set of source-pools is assumed with diskOfferings and tags of the same names + - tagging may yet be in the way of migrations, possible improvement there + TODO the implementation of the matrix traversal is not implemented yet """ user_dimension = [ "admin" ] # should be [ "admin", "user"] system_dimension = [ "6.7" ] # should be [ "6.5", "6.7"] - source_pool_dimension = [ "NFS" ] - targets_pool_dimension = [ "VSAN" ] + source_pool_dimension = [ "nfs-67" ] + targets_pool_dimension = [ "nfs-65" ] # we should use a pool_matrix of # [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] * [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] @@ -88,7 +92,7 @@ def setUpClass(cls): ) cls.vm = VirtualMachine.create( - cls.apiclient, + cls.userapiclient, cls.testdata["small"], templateid=cls.template.id, accountid=cls.account.name, @@ -135,37 +139,45 @@ def tearDown(self): @attr(tags=["advanced", "basic"], required_hardware="true") def test_the_matrix(self): """ - run the defined tests + run the defined tests in a double loop from sources to targets :return: """ + for source_name in self.source_pool_dimension: + for target_name in self.targets_pool_dimension: + if source_name != target_name: + self.test_a_migration(source_name, target_name) return - def test_a_migration(self, source, target): + def test_a_migration(self, source_name, target_name): """ Do a single iteration of the test sequence, creating the volume on the source migrating and then deleting the volume from the target. - :param source: source pool to igrate from - :param target: target pool to migrate to + :param source_name: source pool to migrate from + :param target_name: target pool to migrate to :return: """ - volume = self.setup_source(source) - self.migrate(volume, target) - self.validate(volume, target) + # TODO validate pool results + source_pool = StoragePool.list(self.apiclient, name=source_name)[0] + target_pool = StoragePool.list(self.apiclient, name=target_name)[0] + volume = self.setup_source(source_pool) + result_to_validate = self.migrate(volume, target_pool) + self.validate(volume, migration_result=result_to_validate, target=target_pool) self.remove_volume(volume) return def setup_source(self, source): """ + # create a volume + # attach the volume to a running vm to have it on primary + # migrate to the source primary + # detach the volume :param source: the pool to set a volume up on :return: the marvin volume object """ - # create a volume with tags for the right primary - # attach the volume to a running vm to have it on primary - # detach the volume vol = Volume.create( - self.apiclient, + self.userapiclient, self.testdata["volume"], diskofferingid=self.disk_offering.id, zoneid=self.zone.id, @@ -173,24 +185,17 @@ def setup_source(self, source): domainid=self.account.domainid, ) - self.cleanup.append(vol) + print("created volume with id: '{id}' and name: '{name}".format(id=vol.id, name=vol.name)) - self.vm.attach_volume( - self.apiclient, - vol - ) + # NOTE either self.cleanup.append(vol) at this point or the more localised/explicit remove(vol) in the test method + # TODO improve marvin so cleanup doesn't break if an explicit remove had already be done - pools = StoragePool.listForMigration( - self.apiclient, - id=vol.id - ) + # make sure the volume is implemented + self.vm.attach_volume(self.userapiclient, vol) + self.vm.detach_volume(self.userapiclient, vol) - if not pools: - self.skipTest( - "No suitable storage pools found for volume migration.\ - Skipping") - - self.vm.detach_volume(self.apiclient, vol) + #put it on the origin point of this migration test + vol.migrate(self.userapiclient, storageid=source.id) return vol @@ -205,18 +210,30 @@ def remove_volume(self, volume): def migrate(self, volume, target): """ + as the method signature sugests - :param volume: - :param target: - :return: + :param volume: the object to migrate + :param target: pool to migrate to + :return: None if no target pool found, the result of the migration command otherwise """ - return + pools = StoragePool.listForMigration( + self.userapiclient, + id=volume.id + ) + + for pool in pools: + if pool.name == target.name: + return volume.migrate(self.userapiclient, storageid=pool.id) + return None - def validate(self, volume, target): + def validate(self, volume, migration_result, target): """ :param volume: :param target: :return: """ + if migration_result == None: + raise Exception("No migration result to verify") + print migration_result return \ No newline at end of file From e90968907b3c0f041550e93e3ad505490922b0e7 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Sat, 29 Aug 2020 00:25:44 +0200 Subject: [PATCH 3/4] :thought on result capturing --- test/integration/testpaths/testpath_migration_matrix.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/testpaths/testpath_migration_matrix.py b/test/integration/testpaths/testpath_migration_matrix.py index cf56731fcc4f..42b1c3610e53 100644 --- a/test/integration/testpaths/testpath_migration_matrix.py +++ b/test/integration/testpaths/testpath_migration_matrix.py @@ -140,6 +140,9 @@ def tearDown(self): def test_the_matrix(self): """ run the defined tests in a double loop from sources to targets + + TODO set up a multidimensonal dictionary to capture results in + :return: """ for source_name in self.source_pool_dimension: From 23900a3fe864f150ce47c505ca82f24897540385 Mon Sep 17 00:00:00 2001 From: Vladimir Petrov Date: Mon, 21 Sep 2020 14:54:54 +0300 Subject: [PATCH 4/4] Reworked, only-admin user, using the same volume for entire test. --- .../testpaths/testpath_migration_matrix.py | 141 +++++++----------- 1 file changed, 56 insertions(+), 85 deletions(-) diff --git a/test/integration/testpaths/testpath_migration_matrix.py b/test/integration/testpaths/testpath_migration_matrix.py index 42b1c3610e53..8cfdd74bae56 100644 --- a/test/integration/testpaths/testpath_migration_matrix.py +++ b/test/integration/testpaths/testpath_migration_matrix.py @@ -17,7 +17,8 @@ """ Test cases for Delta Snapshots Test Path """ import time -from marvin.lib.base import ServiceOffering, Configurations, VirtualMachine, Account, Volume, DiskOffering, StoragePool +from marvin.lib.base import ServiceOffering, Configurations, VirtualMachine, Account, Volume, DiskOffering, StoragePool, \ + Role from marvin.lib.utils import cleanup_resources, format_volume_to_ext3 from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase @@ -35,10 +36,8 @@ class TestStorageMigrations(cloudstackTestCase): TODO the implementation of the matrix traversal is not implemented yet """ - user_dimension = [ "admin" ] # should be [ "admin", "user"] - system_dimension = [ "6.7" ] # should be [ "6.5", "6.7"] - source_pool_dimension = [ "nfs-67" ] - targets_pool_dimension = [ "nfs-65" ] + source_pool_dimension = [ "nfs-65", "vsanDatastore-6.5", "ref-trl-1513-v-M7-alex-mattioli-esxi-pri5" ] + targets_pool_dimension = [ "nfs-65", "vsanDatastore-6.5", "ref-trl-1513-v-M7-alex-mattioli-esxi-pri5" ] # we should use a pool_matrix of # [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] * [ "NFS", "VMFS5", "VMFS6", "VVOLS", "VSAN", "DSC"] @@ -58,17 +57,19 @@ def setUpClass(cls): cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ cls.skiptest = False - # for now untill we want to be more generic + # for now until we want to be more generic if cls.hypervisor.lower() not in ["vmware"]: cls.skiptest = True try: + # Get root admin role + cls.rootadminrole = Role.list(cls.apiclient)[0] # Create an account cls.account = Account.create( cls.apiclient, cls.testdata["account"], - domainid=cls.domain.id + roleid=cls.rootadminrole.id ) cls._cleanup.append(cls.account) @@ -141,44 +142,11 @@ def test_the_matrix(self): """ run the defined tests in a double loop from sources to targets - TODO set up a multidimensonal dictionary to capture results in + TODO set up a multidimensional dictionary to capture results in :return: """ - for source_name in self.source_pool_dimension: - for target_name in self.targets_pool_dimension: - if source_name != target_name: - self.test_a_migration(source_name, target_name) - return - - def test_a_migration(self, source_name, target_name): - """ - Do a single iteration of the test sequence, - creating the volume on the source migrating and then deleting the volume from the target. - - :param source_name: source pool to migrate from - :param target_name: target pool to migrate to - :return: - """ - # TODO validate pool results - source_pool = StoragePool.list(self.apiclient, name=source_name)[0] - target_pool = StoragePool.list(self.apiclient, name=target_name)[0] - volume = self.setup_source(source_pool) - result_to_validate = self.migrate(volume, target_pool) - self.validate(volume, migration_result=result_to_validate, target=target_pool) - self.remove_volume(volume) - return - - def setup_source(self, source): - """ - # create a volume - # attach the volume to a running vm to have it on primary - # migrate to the source primary - # detach the volume - - :param source: the pool to set a volume up on - :return: the marvin volume object - """ + print(">>> Creating volume") vol = Volume.create( self.userapiclient, self.testdata["volume"], @@ -187,56 +155,59 @@ def setup_source(self, source): account=self.account.name, domainid=self.account.domainid, ) - - print("created volume with id: '{id}' and name: '{name}".format(id=vol.id, name=vol.name)) - - # NOTE either self.cleanup.append(vol) at this point or the more localised/explicit remove(vol) in the test method - # TODO improve marvin so cleanup doesn't break if an explicit remove had already be done - - # make sure the volume is implemented + print(">>> Attach volume to the VM") self.vm.attach_volume(self.userapiclient, vol) + print(">>> Detach volume from the VM") self.vm.detach_volume(self.userapiclient, vol) - #put it on the origin point of this migration test - vol.migrate(self.userapiclient, storageid=source.id) - - return vol - - def remove_volume(self, volume): - """ + print(">>> Starting migrations") + for source_name in self.source_pool_dimension: + for target_name in self.targets_pool_dimension: + if source_name != target_name: + self.test_a_migration(vol, source_name, target_name) - :param volume: the id of the volume - :return: - """ - volume.delete(self.apiclient) + print(">>> Delete volume") + vol.delete(self.apiclient) return - def migrate(self, volume, target): - """ - as the method signature sugests - - :param volume: the object to migrate - :param target: pool to migrate to - :return: None if no target pool found, the result of the migration command otherwise - """ - pools = StoragePool.listForMigration( - self.userapiclient, - id=volume.id - ) - - for pool in pools: - if pool.name == target.name: - return volume.migrate(self.userapiclient, storageid=pool.id) - return None - - def validate(self, volume, migration_result, target): + def test_a_migration(self, volume, source_name, target_name): """ + Do a single iteration of the test sequence, + moving the volume to the source destination and then testing the actual migration from there to the target - :param volume: - :param target: + :param volume: the volume we want to migrate + :param source_name: source pool to migrate from + :param target_name: target pool to migrate to :return: """ - if migration_result == None: - raise Exception("No migration result to verify") - print migration_result - return \ No newline at end of file + # TODO validate pool results + source_pool = StoragePool.list(self.apiclient, name=source_name)[0] + target_pool = StoragePool.list(self.apiclient, name=target_name)[0] + voldata = volume.list(self.apiclient, id=volume.id) + + # Move our volume to the source datastore + if source_pool.name != voldata[0].storage: + try: + print(">>> Setup volume migration from %s to source datastore %s" % (voldata[0].storage, source_pool.name)) + result1 = volume.migrate(self.userapiclient, storageid=source_pool.id, volumeid=volume.id) + if source_pool.name == result1.storage: + print("SUCCESS!") + else: + print("ERROR: Something went wrong, volume storage is still %s" % volume.storage) + except Exception as e: + print(">>> ERROR: Setup volume migration to source datastore %s failed with error %s " % (source_pool.name, e)) + return + else: + print(">>> Current source datastore is the desired one - no need for setup") + + # Migrate our volume to the target datastore + try: + print(">>> Migrating volume from %s to %s" % (source_pool.name, target_pool.name)) + result2 = volume.migrate(self.userapiclient, volumeid=volume.id, storageid=target_pool.id) + if target_pool.name == result2.storage: + print("SUCCESS!") + else: + print("ERROR: Something went wrong, volume storage is still %s" % volume.storage) + except Exception as e: + print(">>> ERROR: Volume migration to target datastore %s failed with error %s " % (target_pool.name, e)) + return