DaanHoogland commented on code in PR #8755: URL: https://github.com/apache/cloudstack/pull/8755#discussion_r1666373277
########## test/integration/plugins/storpool/TestStorPoolTiers.py: ########## @@ -0,0 +1,554 @@ +# 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. + +import pprint +import uuid + +from marvin.cloudstackAPI import (listResourceDetails, addResourceDetail, changeOfferingForVolume) +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.codes import FAILED +from marvin.lib.base import (DiskOffering, + ServiceOffering, + StoragePool, + VirtualMachine, + SecurityGroup, + ResourceDetails + ) +from marvin.lib.common import (get_domain, + get_template, + list_disk_offering, + list_storage_pools, + list_volumes, + list_service_offering, + list_zones) +from marvin.lib.utils import random_gen, cleanup_resources +from nose.plugins.attrib import attr +from storpool import spapi + +from sp_util import (TestData, StorPoolHelper) + + +class TestStorPoolTiers(cloudstackTestCase): + @classmethod + def setUpClass(cls): + super(TestStorPoolTiers, cls).setUpClass() + try: + cls.setUpCloudStack() + except Exception: + cls.cleanUpCloudStack() + raise + + @classmethod + def setUpCloudStack(cls): + config = cls.getClsConfig() + StorPoolHelper.logger = cls + + zone = config.zones[0] + assert zone is not None + + cls.spapi = spapi.Api(host=zone.spEndpoint, port=zone.spEndpointPort, auth=zone.spAuthToken, multiCluster=True) + testClient = super(TestStorPoolTiers, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.unsupportedHypervisor = False + cls.hypervisor = testClient.getHypervisorInfo() + if cls.hypervisor.lower() in ("hyperv", "lxc"): + cls.unsupportedHypervisor = True + return + + cls._cleanup = [] + + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates + cls.domain = get_domain(cls.apiclient) + cls.zone = list_zones(cls.apiclient, name=zone.name)[0] + + td = TestData() + cls.testdata = td.testdata + cls.helper = StorPoolHelper() + + disk_offerings_tier1_tags = cls.testdata[TestData.diskOfferingTier1Tag] + disk_offerings_tier2_tags = cls.testdata[TestData.diskOfferingTier2Tag] + disk_offerings_tier1_template = cls.testdata[TestData.diskOfferingTier1Template] + disk_offerings_tier2_template = cls.testdata[TestData.diskOfferingTier2Template] + disk_offerings_tier2_tags_template = cls.testdata[TestData.diskOfferingWithTagsAndTempl] + + cls.qos = "SP_QOSCLASS" + cls.spTemplate = "SP_TEMPLATE" + + cls.disk_offerings_tier1_tags = cls.getDiskOffering(disk_offerings_tier1_tags, cls.qos, "ssd") + + cls.disk_offerings_tier2_tags = cls.getDiskOffering(disk_offerings_tier2_tags, cls.qos, "virtual") + + cls.disk_offerings_tier1_template = cls.getDiskOffering(disk_offerings_tier1_template, cls.spTemplate, "ssd") + + cls.disk_offerings_tier2_template = cls.getDiskOffering(disk_offerings_tier2_template, cls.spTemplate, + "virtual") + cls.disk_offerings_tier2_tags_template = cls.getDiskOffering(disk_offerings_tier2_tags_template, cls.spTemplate, + "virtual") + cls.resourceDetails(cls.qos, cls.disk_offerings_tier2_tags_template.id, "virtual") + + cls.account = cls.helper.create_account( + cls.apiclient, + cls.services["account"], + accounttype=1, + domainid=cls.domain.id, + roleid=1 + ) + cls._cleanup.append(cls.account) + + securitygroup = SecurityGroup.list(cls.apiclient, account=cls.account.name, domainid=cls.account.domainid)[0] + cls.helper.set_securityGroups(cls.apiclient, account=cls.account.name, domainid=cls.account.domainid, + id=securitygroup.id) + + storpool_primary_storage = cls.testdata[TestData.primaryStorage] + + storpool_service_offerings = cls.testdata[TestData.serviceOffering] + + cls.template_name = storpool_primary_storage.get("name") + + storage_pool = list_storage_pools( + cls.apiclient, + name=cls.template_name + ) + + service_offerings = list_service_offering( + cls.apiclient, + name=cls.template_name + ) + + disk_offerings = list_disk_offering( + cls.apiclient, + name="ssd" + ) + + if storage_pool is None: + storage_pool = StoragePool.create(cls.apiclient, storpool_primary_storage) + else: + storage_pool = storage_pool[0] + cls.storage_pool = storage_pool + cls.debug(pprint.pformat(storage_pool)) + if service_offerings is None: + service_offerings = ServiceOffering.create(cls.apiclient, storpool_service_offerings) + else: + service_offerings = service_offerings[0] + # The version of CentOS has to be supported + template = get_template( + cls.apiclient, + cls.zone.id, + account="system" + ) + + if template == FAILED: + assert False, "get_template() failed to return template\ + with description %s" % cls.services["ostype"] + + cls.services["domainid"] = cls.domain.id + cls.services["small"]["zoneid"] = cls.zone.id + cls.services["templates"]["ostypeid"] = template.ostypeid + cls.services["zoneid"] = cls.zone.id + + cls.service_offering = service_offerings + cls.debug(pprint.pformat(cls.service_offering)) + + cls.template = template + cls.random_data_0 = random_gen(size=100) + cls.test_dir = "/tmp" + cls.random_data = "random.data" + return + + @classmethod + def getDiskOffering(cls, dataDiskOffering, qos, resValue): + disk_offerings = list_disk_offering(cls.apiclient, name=dataDiskOffering.get("name")) + if disk_offerings is None: + disk_offerings = DiskOffering.create(cls.apiclient, services=dataDiskOffering, custom=True) + cls.resourceDetails(qos, disk_offerings.id, resValue) + else: + disk_offerings = disk_offerings[0] + cls.resourceDetails(qos, disk_offerings.id, ) + return disk_offerings + + @classmethod + def tearDownClass(cls): + cls.cleanUpCloudStack() + + @classmethod + def cleanUpCloudStack(cls): + try: + # Cleanup resources used + cleanup_resources(cls.apiclient, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + + if self.unsupportedHypervisor: + self.skipTest("Skipping test because unsupported hypervisor\ + %s" % self.hypervisor) + return + + def tearDown(self): + return + + @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") + def test_01_check_tags_on_deployed_vm_and_datadisk(self): + virtual_machine_tier1_tag = self.deploy_vm_and_check_tier_tag() + virtual_machine_tier1_tag.stop(self.apiclient, forced=True) + + @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") + def test_02_change_offering_on_attached_root_disk(self): + virtual_machine_tier1_tag = self.deploy_vm_and_check_tier_tag() + + root_volume = list_volumes(self.apiclient, virtualmachineid=virtual_machine_tier1_tag.id, type="ROOT", + listall=True) + self.changeOfferingForVolume(root_volume[0].id, self.disk_offerings_tier2_tags.id, root_volume[0].size) + root_volume = list_volumes(self.apiclient, virtualmachineid=virtual_machine_tier1_tag.id, type="ROOT", + listall=True) + self.vc_policy_tags(volumes=root_volume, vm=virtual_machine_tier1_tag, qos_or_template=self.qos, + disk_offering_id=self.disk_offerings_tier2_tags.id, attached=True) + virtual_machine_tier1_tag.stop(self.apiclient, forced=True) + + def test_03_change_offering_on_attached_data_disk(self): + virtual_machine_tier1_tag = self.deploy_vm_and_check_tier_tag() + + root_volume = list_volumes(self.apiclient, virtualmachineid=virtual_machine_tier1_tag.id, type="DATADISK", + listall=True) + self.changeOfferingForVolume(root_volume[0].id, self.disk_offerings_tier2_tags.id, root_volume[0].size) + root_volume = list_volumes(self.apiclient, virtualmachineid=virtual_machine_tier1_tag.id, type="DATADISK", + listall=True) + self.vc_policy_tags(volumes=root_volume, vm=virtual_machine_tier1_tag, qos_or_template=self.qos, + disk_offering_id=self.disk_offerings_tier2_tags.id, attached=True) + virtual_machine_tier1_tag.stop(self.apiclient, forced=True) + + @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") + def test_04_check_templates_on_deployed_vm_and_datadisk(self): + virtual_machine_template_tier1 = VirtualMachine.create( + self.apiclient, + {"name": "StorPool-%s" % uuid.uuid4()}, + zoneid=self.zone.id, + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + overridediskofferingid=self.disk_offerings_tier1_template.id, + diskofferingid=self.disk_offerings_tier1_template.id, + size=2, + hypervisor=self.hypervisor, + rootdisksize=10 + ) Review Comment: ```suggestion virtual_machine_template_tier1 = VirtualMachine.create( self.apiclient, {"name": "StorPool-%s" % uuid.uuid4()}, zoneid=self.zone.id, templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, overridediskofferingid=self.disk_offerings_tier1_template.id, diskofferingid=self.disk_offerings_tier1_template.id, size=2, hypervisor=self.hypervisor, rootdisksize=10 ) self.cleanup.append(virtual_machine_template_tier1) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org