def test_02_edit_service_offering(self):
        """Test to update existing service offering"""

        # Validate the following:
        # 1. updateServiceOffering should return
        #    a valid information for newly created offering

        #Generate new name & displaytext from random data
        random_displaytext = random_gen()
        random_name = random_gen()

        self.debug("Updating service offering with ID: %s" %
                   self.service_offering_1.id)

        cmd = updateServiceOffering.updateServiceOfferingCmd()
        #Add parameters for API call
        cmd.id = self.service_offering_1.id
        cmd.displaytext = random_displaytext
        cmd.name = random_name
        self.apiclient.updateServiceOffering(cmd)

        list_service_response = list_service_offering(
            self.apiclient,
            id=self.service_offering_1.id
        )
        self.assertEqual(
            isinstance(list_service_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.assertNotEqual(
            len(list_service_response),
            0,
            "Check Service offering is updated"
        )

        self.assertEqual(
            list_service_response[0].displaytext,
            random_displaytext,
            "Check server displaytext in updateServiceOffering"
        )
        self.assertEqual(
            list_service_response[0].name,
            random_name,
            "Check server name in updateServiceOffering"
        )

        return
示例#2
0
    def create_aff_grp(self, aff_grp=None, acc=None, domainid=None):

        aff_grp["name"] = "aff_grp_" + random_gen(size=6)

        try:
            aff_grp = AffinityGroup.create(self.apiclient, aff_grp, acc, domainid)
            return aff_grp
        except Exception as e:
            raise Exception("Error: Creation of Affinity Group failed : %s" % e)
示例#3
0
    def test_add_ip_to_nic(self, value):
        """ Add secondary IP to NIC of a VM"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add secondary IP to the default nic of VM
        # 4. Try to add the same IP again
        # 5. Try to add secondary IP providing wrong virtual machine id
        # 6. Try to add secondary IP with correct virtual machine id but wrong IP address

        # Validations:
        # 1. Step 3 should succeed
        # 2. Step 4 should fail
        # 3. Step 5 should should fail
        # 4. Step 6 should fail

        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
        self.cleanup.append(self.account)

        if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
            self.skipTest("Skipping test as %s network is not supported in basic zone" % value)

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress=ipaddress_1.ipaddress)
            self.debug("Adding already added secondary IP %s to NIC of vm %s succeeded, should have failed" %
                    (ipaddress_1.ipaddress, virtual_machine.id))
        except Exception as e:
            self.debug("Failed while adding already added secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.addIp(self.apiclient, id=(virtual_machine.nic[0].id + random_gen()))
            self.fail("Adding secondary IP with wrong NIC id succeded, it shoud have failed")
        except Exception as e:
            self.debug("Failed while adding secondary IP to wrong NIC")

        try:
            NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress = "255.255.255.300")
            self.fail("Adding secondary IP with wrong ipaddress succeded, it should have failed")
        except Exception as e:
            self.debug("Failed while adding wrong secondary IP to NIC of VM %s" % virtual_machine.id)
        return
    def create_aff_grp(self, aff_grp=None, acc=None, domainid=None):

        aff_grp["name"] = "aff_grp_" + random_gen(size=6)

        try:
            aff_grp = AffinityGroup.create(self.apiclient, aff_grp, acc,
                                           domainid)
            return aff_grp
        except Exception as e:
            raise Exception("Error: Creation of Affinity Group failed : %s" %
                            e)
示例#5
0
 def configure_Stickiness_Policy(self, lb_rule, method, paramDict=None):
     """Configure the stickiness policy on lb rule"""
     try:
         result = lb_rule.createSticky(
                          self.apiclient,
                          methodname=method,
                          name="-".join([method, random_gen()]),
                          param=paramDict
                          )
         self.debug("Response: %s" % result)
         return result
     except Exception as e:
         self.fail("Configure sticky policy failed with exception: %s" % e)
示例#6
0
    def test_02_edit_service_offering(self):
        """Test to update existing service offering"""

        # Validate the following:
        # 1. updateServiceOffering should return
        #    a valid information for newly created offering

        #Generate new name & displaytext from random data
        random_displaytext = random_gen()
        random_name = random_gen()

        self.debug("Updating service offering with ID: %s" %
                   self.service_offering_1.id)

        cmd = updateServiceOffering.updateServiceOfferingCmd()
        #Add parameters for API call
        cmd.id = self.service_offering_1.id
        cmd.displaytext = random_displaytext
        cmd.name = random_name
        self.apiclient.updateServiceOffering(cmd)

        list_service_response = list_service_offering(
            self.apiclient, id=self.service_offering_1.id)
        self.assertEqual(isinstance(list_service_response, list), True,
                         "Check list response returns a valid list")

        self.assertNotEqual(len(list_service_response), 0,
                            "Check Service offering is updated")

        self.assertEqual(list_service_response[0].displaytext,
                         random_displaytext,
                         "Check server displaytext in updateServiceOffering")
        self.assertEqual(list_service_response[0].name, random_name,
                         "Check server name in updateServiceOffering")

        return
    def create_Volume_from_Snapshot(self, snapshot):
        try:
            self.debug("Creating volume from snapshot: %s" % snapshot.name)

            cmd = createVolume.createVolumeCmd()
            cmd.name = "-".join([
                                self.services["volume"]["diskname"],
                                random_gen()])
            cmd.snapshotid = snapshot.id
            cmd.zoneid = self.zone.id
            cmd.size = self.services["volume"]["size"]
            cmd.account = self.account.name
            cmd.domainid = self.account.domainid
            return cmd
        except Exception as e:
            self.fail("Failed to create volume from snapshot: %s - %s" %
                                                        (snapshot.name, e))
示例#8
0
    def create_Volume_from_Snapshot(self, snapshot):
        try:
            self.debug("Creating volume from snapshot: %s" % snapshot.name)

            cmd = createVolume.createVolumeCmd()
            cmd.name = "-".join(
                [self.services["volume"]["diskname"],
                 random_gen()])
            cmd.snapshotid = snapshot.id
            cmd.zoneid = self.zone.id
            cmd.size = self.services["volume"]["size"]
            cmd.account = self.account.name
            cmd.domainid = self.account.domainid
            return cmd
        except Exception as e:
            self.fail("Failed to create volume from snapshot: %s - %s" %
                      (snapshot.name, e))
示例#9
0
    def test_remove_ip_from_nic(self, value):
        """ Remove secondary IP from NIC of a VM"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add secondary IP to the default nic of VM
        # 4. Remove the secondary IP
        # 5. Try to remove secondary ip by giving incorrect ipaddress id

        # Validations:
        # 1. Step 4 should succeed
        # 2. Step 5 should fail

        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
        self.cleanup.append(self.account)

        if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
            self.skipTest("Skipping test as %s network is not supported in basic zone" % value)

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id)
        except Exception as e:
            self.fail("Removing seondary IP %s from NIC failed as expected with Exception %s" % (ipaddress_1.id,e))

        try:
            NIC.removeIp(self.apiclient, ipaddressid=(ipaddress_1.id + random_gen()))
            self.fail("Removing invalid IP address, it should have failed")
        except Exception as e:
            self.debug("Removing invalid IP failed as expected with Exception %s" % e)
        return
    def create_Template_from_Snapshot(self, snapshot):
        try:
            self.debug("Creating template from snapshot: %s" % snapshot.name)

            cmd = createTemplate.createTemplateCmd()
            cmd.displaytext = self.services["template"]["displaytext"]
            cmd.name = "-".join([self.services["template"]["name"],
                                 random_gen()])

            ncmd = listOsTypes.listOsTypesCmd()
            ncmd.description = self.services["template"]["ostype"]
            ostypes = self.apiclient.listOsTypes(ncmd)

            if not isinstance(ostypes, list):
                raise Exception(
                    "Unable to find Ostype id with desc: %s" %
                                        self.services["template"]["ostype"])
            cmd.ostypeid = ostypes[0].id
            cmd.snapshotid = snapshot.id

            return cmd
        except Exception as e:
            self.fail("Failed to create template from snapshot: %s - %s" %
                                                        (snapshot.name, e))
示例#11
0
    def create_Template_from_Snapshot(self, snapshot):
        try:
            self.debug("Creating template from snapshot: %s" % snapshot.name)

            cmd = createTemplate.createTemplateCmd()
            cmd.displaytext = self.services["template"]["displaytext"]
            cmd.name = "-".join(
                [self.services["template"]["name"],
                 random_gen()])

            ncmd = listOsTypes.listOsTypesCmd()
            ncmd.description = self.services["template"]["ostype"]
            ostypes = self.apiclient.listOsTypes(ncmd)

            if not isinstance(ostypes, list):
                raise Exception("Unable to find Ostype id with desc: %s" %
                                self.services["template"]["ostype"])
            cmd.ostypeid = ostypes[0].id
            cmd.snapshotid = snapshot.id

            return cmd
        except Exception as e:
            self.fail("Failed to create template from snapshot: %s - %s" %
                      (snapshot.name, e))
示例#12
0
 def setUp(self):
     self.apiClient = self.testClient.getApiClient()
     self.userApiClient = self.testClient.getUserApiClient(
         account='test' + utils.random_gen(), 'ROOT')
示例#13
0
    def createUserApiClient(self, UserName, DomainName, acctType=0):
        if not self.isAdminContext():
            return self.apiClient

        listDomain = listDomains.listDomainsCmd()
        listDomain.listall = True
        listDomain.name = DomainName
        try:
            domains = self.apiClient.listDomains(listDomain)
            domId = domains[0].id
        except:
            cdomain = createDomain.createDomainCmd()
            cdomain.name = DomainName
            domain = self.apiClient.createDomain(cdomain)
            domId = domain.id

        cmd = listAccounts.listAccountsCmd()
        cmd.name = UserName
        cmd.domainid = domId
        try:
            accounts = self.apiClient.listAccounts(cmd)
            acctId = accounts[0].id
        except:
            createAcctCmd = createAccount.createAccountCmd()
            createAcctCmd.accounttype = acctType
            createAcctCmd.domainid = domId
            createAcctCmd.email = "test-" + random_gen()\
                + "@cloudstack.org"
            createAcctCmd.firstname = UserName
            createAcctCmd.lastname = UserName
            createAcctCmd.password = '******'
            createAcctCmd.username = UserName
            acct = self.apiClient.createAccount(createAcctCmd)
            acctId = acct.id

        listuser = listUsers.listUsersCmd()
        listuser.username = UserName

        listuserRes = self.apiClient.listUsers(listuser)
        userId = listuserRes[0].id
        apiKey = listuserRes[0].apikey
        securityKey = listuserRes[0].secretkey

        if apiKey is None:
            registerUser = registerUserKeys.registerUserKeysCmd()
            registerUser.id = userId
            registerUserRes = self.apiClient.registerUserKeys(registerUser)
            apiKey = registerUserRes.apikey
            securityKey = registerUserRes.secretkey

        mgtDetails = self.mgmtDetails
        mgtDetails.apiKey = apiKey
        mgtDetails.securityKey = securityKey

        newUserConnection =\
            cloudstackConnection.cloudConnection(mgtDetails,
                                                 self.connection.asyncTimeout,
                                                 self.connection.logger)
        self.userApiClient =\
            cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
        self.userApiClient.connection = newUserConnection
        self.userApiClient.hypervisor = self.apiClient.hypervisor
        return self.userApiClient
示例#14
0
    def test_list_nics(self, value):
        """Test listing nics associated with the ip address"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add secondary IP to the default nic of VM
        # 4. Try to list the secondary ips without passing vm id
        # 5. Try to list secondary IPs by passing correct vm id
        # 6. Try to list secondary IPs by passing correct vm id and its nic id
        # 7. Try to list secondary IPs by passing incorrect vm id and correct nic id
        # 8. Try to list secondary IPs by passing correct vm id and incorrect nic id
        # 9. Try to list secondary IPs by passing incorrect vm id and incorrect nic id

        # Validations:
        # 1. Step 4 should fail
        # 2. Step 5 should succeed
        # 3. Step 6 should succeed
        # 4. Step 7 should fail
        # 5. Step 8 should fail
        # 6. Step 9 should fail


        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
        self.cleanup.append(self.account)

        if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
            self.skipTest("Skipping test as %s network is not supported in basic zone" % value)

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            nics = NIC.list(self.apiclient)
            self.fail("Listing NICs without passign VM id succeeded, it should have failed, list is %s" % nics)
        except Exception as e:
            self.debug("Listing NICs without passing virtual machine id failed as expected")

        try:
            NIC.list(self.apiclient, virtualmachineid=virtual_machine.id)
        except Exception as e:
            self.fail("Listing NICs for virtual machine %s failed with Exception %s" % (virtual_machine.id, e))

        try:
            NIC.list(self.apiclient, virtualmachineid=virtual_machine.id, nicid=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Listing NICs for virtual machine %s and nic id %s failed with Exception %s" %
                    (virtual_machine.id, virtual_machine.nic[0].id, e))

        try:
            nics = NIC.list(self.apiclient, virtualmachineid=(virtual_machine.id + random_gen()), nicid=virtual_machine.nic[0].id)
            self.fail("Listing NICs with wrong virtual machine id and right nic id succeeded, should have failed")
        except Exception as e:
            self.debug("Listing NICs with wrong virtual machine id and right nic failed as expected with Exception %s" % e)

        try:
            nics = NIC.list(self.apiclient, virtualmachineid=virtual_machine.id, nicid=(virtual_machine.nic[0].id + random_gen()))
            self.fail("Listing NICs with correct virtual machine id but wrong nic id succeeded, should have failed")
        except Exception as e:
            self.debug("Listing NICs with correct virtual machine id but wrong nic id failed as expected with Exception %s" % e)

        try:
            nics = NIC.list(self.apiclient, virtualmachineid=(virtual_machine.id+random_gen()), nicid=(virtual_machine.nic[0].id + random_gen()))
            self.fail("Listing NICs with wrong virtual machine id and wrong nic id succeeded, should have failed")
        except Exception as e:
            self.debug("Listing NICs with wrong virtual machine id and wrong nic id failed as expected with Exception %s" % e)

        return
示例#15
0
    def createUserApiClient(self, UserName, DomainName, acctType=0):
        if not self.isAdminContext():
            return self.apiClient

        listDomain = listDomains.listDomainsCmd()
        listDomain.listall = True
        listDomain.name = DomainName
        try:
            domains = self.apiClient.listDomains(listDomain)
            domId = domains[0].id
        except:
            cdomain = createDomain.createDomainCmd()
            cdomain.name = DomainName
            domain = self.apiClient.createDomain(cdomain)
            domId = domain.id

        cmd = listAccounts.listAccountsCmd()
        cmd.name = UserName
        cmd.domainid = domId
        try:
            accounts = self.apiClient.listAccounts(cmd)
            acctId = accounts[0].id
        except:
            createAcctCmd = createAccount.createAccountCmd()
            createAcctCmd.accounttype = acctType
            createAcctCmd.domainid = domId
            createAcctCmd.email = "test-" + random_gen()\
                + "@cloudstack.org"
            createAcctCmd.firstname = UserName
            createAcctCmd.lastname = UserName
            createAcctCmd.password = '******'
            createAcctCmd.username = UserName
            acct = self.apiClient.createAccount(createAcctCmd)
            acctId = acct.id

        listuser = listUsers.listUsersCmd()
        listuser.username = UserName

        listuserRes = self.apiClient.listUsers(listuser)
        userId = listuserRes[0].id
        apiKey = listuserRes[0].apikey
        securityKey = listuserRes[0].secretkey

        if apiKey is None:
            registerUser = registerUserKeys.registerUserKeysCmd()
            registerUser.id = userId
            registerUserRes = self.apiClient.registerUserKeys(registerUser)
            apiKey = registerUserRes.apikey
            securityKey = registerUserRes.secretkey

        mgtDetails = self.mgmtDetails
        mgtDetails.apiKey = apiKey
        mgtDetails.securityKey = securityKey

        newUserConnection =\
            cloudstackConnection.cloudConnection(mgtDetails,
                                                 self.connection.asyncTimeout,
                                                 self.connection.logger)
        self.userApiClient =\
            cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
        self.userApiClient.connection = newUserConnection
        self.userApiClient.hypervisor = self.apiClient.hypervisor
        return self.userApiClient
 def setUp(self):
     self.apiClient = self.testClient.getApiClient()
     self.userApiClient = self.testClient.getUserApiClient(account='test'+utils.random_gen(), 'ROOT')