http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ce59b31c/test/integration/component/test_volumes.py ---------------------------------------------------------------------- diff --git a/test/integration/component/test_volumes.py b/test/integration/component/test_volumes.py index 998ba2c..3bad5f1 100644 --- a/test/integration/component/test_volumes.py +++ b/test/integration/component/test_volumes.py @@ -79,10 +79,14 @@ class Services: "name": "testISO", "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", # Source URL where ISO is located - "ostypeid": '01853327-513e-4508-9628-f1f55db1946f', + "ostypeid": 'bc66ada0-99e7-483b-befc-8fb0c2129b70', }, + "custom_volume": { + "customdisksize": 2, + "diskname": "Custom disk", + }, "sleep": 50, - "ostypeid": '01853327-513e-4508-9628-f1f55db1946f', + "ostypeid": 'bc66ada0-99e7-483b-befc-8fb0c2129b70', "mode": 'advanced', } @@ -1027,3 +1031,139 @@ class TestVolumes(cloudstackTestCase): "Check if volume exists in ListVolumes" ) return + + +class TestDeployVmWithCustomDisk(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestDeployVmWithCustomDisk, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"], + custom=True + ) + template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + cls.services["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = template.id + + # Create VMs, NAT Rules etc + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + + cls.services["account"] = cls.account.account.name + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + cls.account + ] + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + @attr(tags=["advanced", "configuration", "advancedns", "simulator", + "api", "basic", "eip", "sg"]) + def test_deployVmWithCustomDisk(self): + """Test custom disk sizes beyond range + """ + # Steps for validation + # 1. listConfigurations - custom.diskoffering.size.min + # and custom.diskoffering.size.max + # 2. deployVm with custom disk offering size < min + # 3. deployVm with custom disk offering min< size < max + # 4. deployVm with custom disk offering size > max + # Validate the following + # 2. and 4. of deploy VM should fail. + # Only case 3. should succeed. + # cleanup all created data disks from the account + + config = Configurations.list( + self.apiclient, + name="custom.diskoffering.size.min" + ) + self.assertEqual( + isinstance(config, list), + True, + "custom.diskoffering.size.min should be present in global config" + ) + # minimum size of custom disk (in GBs) + min_size = int(config[0].value) + self.debug("custom.diskoffering.size.min: %s" % min_size) + + config = Configurations.list( + self.apiclient, + name="custom.diskoffering.size.max" + ) + self.assertEqual( + isinstance(config, list), + True, + "custom.diskoffering.size.min should be present in global config" + ) + # maximum size of custom disk (in GBs) + max_size = int(config[0].value) + self.debug("custom.diskoffering.size.max: %s" % max_size) + + self.debug("Creating a volume with size less than min cust disk size") + self.services["custom_volume"]["customdisksize"] = (min_size - 1) + self.services["custom_volume"]["zoneid"] = self.zone.id + with self.assertRaises(Exception): + Volume.create_custom_disk( + self.apiclient, + self.services["custom_volume"], + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Create volume failed!") + + self.debug("Creating a volume with size more than max cust disk size") + self.services["custom_volume"]["customdisksize"] = (max_size + 1) + with self.assertRaises(Exception): + Volume.create_custom_disk( + self.apiclient, + self.services["custom_volume"], + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Create volume failed!") + + self.debug("Creating a volume with size more than min cust disk " + + "but less than max cust disk size" + ) + self.services["custom_volume"]["customdisksize"] = (min_size + 1) + try: + Volume.create_custom_disk( + self.apiclient, + self.services["custom_volume"], + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Create volume of cust disk size succeeded") + except Exception as e: + self.fail("Create volume failed with exception: %s" % e) + return
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ce59b31c/test/integration/lib/base.py ---------------------------------------------------------------------- diff --git a/test/integration/lib/base.py b/test/integration/lib/base.py index 4689972..5001daf 100644 --- a/test/integration/lib/base.py +++ b/test/integration/lib/base.py @@ -158,6 +158,45 @@ class User: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listUsers(cmd)) + @classmethod + def registerUserKeys(cls, apiclient, userid): + cmd = registerUserKeys.registerUserKeysCmd() + cmd.id = userid + return apiclient.registerUserKeys(cmd) + + def update(self, apiclient, **kwargs): + """Updates the user details""" + + cmd = updateUser.updateUserCmd() + cmd.id = self.id + [setattr(cmd, k, v) for k, v in kwargs.items()] + return (apiclient.updateUser(cmd)) + + @classmethod + def update(cls, apiclient, id, **kwargs): + """Updates the user details (class method)""" + + cmd = updateUser.updateUserCmd() + cmd.id = id + [setattr(cmd, k, v) for k, v in kwargs.items()] + return (apiclient.updateUser(cmd)) + + @classmethod + def login(cls, apiclient, username, password, domain=None, domainid=None): + """Logins to the CloudStack""" + + cmd = login.loginCmd() + cmd.username = username + # MD5 hashcoded password + mdf = hashlib.md5() + mdf.update(password) + cmd.password = mdf.hexdigest() + if domain: + cmd.domain = domain + if domainid: + cmd.domainid = domainid + return apiclient.login(cmd) + class VirtualMachine: """Manage virtual machine lifecycle""" @@ -174,7 +213,8 @@ class VirtualMachine: @classmethod def create(cls, apiclient, services, templateid=None, accountid=None, domainid=None, networkids=None, serviceofferingid=None, - securitygroupids=None, projectid=None, mode='basic'): + securitygroupids=None, projectid=None, startvm=None, + diskofferingid=None, hostid=None, mode='basic'): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -219,6 +259,12 @@ class VirtualMachine: if projectid: cmd.projectid = projectid + if startvm is not None: + cmd.startvm = startvm + + if hostid: + cmd.hostid = hostid + virtual_machine = apiclient.deployVirtualMachine(cmd) # VM should be in Running state after deploy @@ -392,12 +438,17 @@ class Volume: return Volume(apiclient.createVolume(cmd).__dict__) @classmethod - def create_custom_disk(cls, apiclient, services, - account=None, domainid=None): + def create_custom_disk(cls, apiclient, services, account=None, + domainid=None, diskofferingid=None): """Create Volume from Custom disk offering""" cmd = createVolume.createVolumeCmd() cmd.name = services["diskname"] - cmd.diskofferingid = services["customdiskofferingid"] + + if diskofferingid: + cmd.diskofferingid = diskofferingid + elif "customdiskofferingid" in services: + cmd.diskofferingid = services["customdiskofferingid"] + cmd.size = services["customdisksize"] cmd.zoneid = services["zoneid"]