def test_es_1863_register_template_s3_domain_admin_user(self): """ @Desc: Test whether cloudstack allows Domain admin or user to register a template using S3/Swift object store. @Steps: Step1: create a Domain and users in it. Step2: Register a template as Domain admin. Step3: Register a template as Domain user. Step4: Template should be registered successfully. """ # Step1: create a Domain and users in it. self.newdomain = Domain.create(self.apiClient, self.services["domain"]) # create account in the domain self.account_domain = Account.create( self.apiClient, self.services["account"], domainid=self.newdomain.id ) self.cleanup.append(self.account_domain) self.cleanup.append(self.newdomain) # Getting authentication for user in newly created Account in domain self.domain_user = self.account_domain.user[0] self.domain_userapiclient = self.testClient.getUserApiClient( self.domain_user.username, self.newdomain.name ) # Step2: Register a template as Domain admin. self.services["templateregister"]["ostype"] = self.services["ostype"] self.domain_template = Template.register( self.apiClient, self.services["templateregister"], zoneid=self.zone.id, account=self.account_domain.name, domainid=self.newdomain.id, hypervisor=self.hypervisor ) # Wait for template to download self.domain_template.download(self.api_client) # Wait for template status to be changed across time.sleep(60) # Step3: Register a template as Domain user. self.domain_user_template = Template.register( self.domain_userapiclient, self.services["templateregister"], zoneid=self.zone.id, account=self.account_domain.name, domainid=self.newdomain.id, hypervisor=self.hypervisor ) # Wait for template to download self.domain_user_template.download(self.api_client) # Wait for template status to be changed across time.sleep(60) # TODO: Step4: Template should be registered successfully. return
def getKubernetesTemplate(cls, cks_templates=None): if cks_templates is None: cks_templates = cls.services["cks_templates"] hypervisor = cls.hypervisor.lower() if hypervisor not in cks_templates.keys(): cls.debug("Provided hypervisor has no CKS template") return FAILED, False cks_template = cks_templates[hypervisor] cmd = listTemplates.listTemplatesCmd() cmd.name = cks_template['name'] cmd.templatefilter = 'all' cmd.zoneid = cls.zone.id cmd.hypervisor = hypervisor templates = cls.apiclient.listTemplates(cmd) if validateList(templates)[0] != PASS: details = None if hypervisor in ["vmware"]: details = [{"keyboard": "us"}] template = Template.register(cls.apiclient, cks_template, zoneid=cls.zone.id, hypervisor=hypervisor.lower(), randomize_name=False, details=details) template.download(cls.apiclient) return template, False for template in templates: if template.isready and template.ispublic: return Template(template.__dict__), True return FAILED, False
def test_listtemplate(self): # Register template under one domain admin(root/domain1->account 1) template_register = Template.register( self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account1.name, domainid=self.domain1.id) template_register.download(self.apiclient) self.download(self.apiclient, template_register.id) listtemplate = Template.list( self.apiclient, zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account2.name, domainid=self.account2.domainid, templatefilter="executable") self.assertEqual( listtemplate, None, "Check templates are not listed - CLOUDSTACK-10149" ) return
def setUpClass(cls): # We want to fail quicker if it's failure socket.setdefaulttimeout(60) cls.testClient = super(TestVPCRedundancy, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.hypervisor = cls.testClient.getHypervisorInfo() cls.template = Template.register(cls.api_client, cls.services["template"][cls.hypervisor.lower( )], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.api_client) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"]) cls._cleanup = [cls.service_offering, cls.template] cls.logger = logging.getLogger('TestVPCRedundancy') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) return
def test_listtemplate(self): # Register template under one domain admin(root/domain1->account 1) template_register = Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account1.name, domainid=self.domain1.id) template_register.download(self.apiclient) # self.cleanup.append(self.template_register) time.sleep(self.testdata["sleep"]) timeout = self.testdata["timeout"] while True: listTemplateResponse = Template.list(self.apiclient, templatefilter="all", id=template_register.id, account=self.account1.name, domainid=self.domain1.id) status = validateList(listTemplateResponse) self.assertEquals(PASS, status[0], "Template creation failed") listtemplate = Template.list(self.apiclient, zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account2.name, domainid=self.account2.domainid, templatefilter="all") self.assertEqual(listtemplate, None, "Check templates are not listed") return
def setUpClass(cls): cls.logger = logging.getLogger('TestVPCSite2SiteVPN') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestVpcSite2SiteVpn, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["compute_offering"] ) cls.account = Account.create( cls.apiclient, services=cls.services["account"]) cls.hypervisor = cls.services["default_hypervisor"] cls.logger.debug("Downloading Template: %s from: %s" % (cls.services["template"][ cls.hypervisor]["name"], cls.services["template"][cls.hypervisor]["url"])) cls.template = Template.register(cls.apiclient, cls.services["template"][ cls.hypervisor], cls.zone.id, hypervisor=cls.hypervisor, account=cls.account.name, domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services[ "compute_offering"] cls.services["virtual_machine"][ "hypervisor"] = cls.services["default_hypervisor"] cls.cleanup = [cls.account]
def test_vm_nic_adapter_vmxnet3(self): """ # 1. Register a template for VMware with nicAdapter vmxnet3 # 2. Deploy a VM using this template # 3. Create an isolated network # 4. Add network to VM # 5. Verify that the NIC adapter for VM for both the nics # is vmxnet3 """ if self.hypervisor.lower() not in ["vmware"]: self.skipTest("This test case is written specifically\ for Vmware hypervisor") # Register a private template in the account with nic adapter vmxnet3 template = Template.register( self.userapiclient, self.testdata["configurableData"]["vmxnet3template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, details=[{"nicAdapter": self.testdata["configurableData"]["vmxnet3template"]["nicadapter"]}] ) self.cleanup.append(template) template.download(self.apiclient) templates = Template.list( self.userapiclient, listall=True, id=template.id, templatefilter="self") self.assertEqual( validateList(templates)[0], PASS, "Templates list validation failed") self.testdata["virtual_machine"]["zoneid"] = self.zone.id self.testdata["virtual_machine"]["template"] = template.id virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id) isolated_network = Network.create( self.apiclient, self.testdata["isolated_network"], self.account.name, self.account.domainid, networkofferingid=self.isolated_network_offering.id) virtual_machine.add_nic(self.apiclient, isolated_network.id) # TODO: Add steps to check the Nic Adapter type in VCenter # using VCenter APIs return
def registerTemplate(self, inProject=False): """Register and download template by default in the account/domain, in project if stated so""" try: builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.child_do_admin.name if not inProject else None, domainid=self.child_do_admin.domainid if not inProject else None, projectid=self.project.id if inProject else None) template.download(self.apiclient) templates = Template.list(self.apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0], PASS,\ "templates list validation failed") self.templateSize = (templates[0].size / (1024**3)) except Exception as e: return [FAIL, e] return [PASS, None]
def test_02_deploy_vm_account_limit_reached(self): """Test Try to deploy VM with admin account where account has used the resources but @ domain they are available # Validate the following # 1. Try to register template with admin account where account has used the # resources but @ domain they are available # 2. Template registration should fail""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate() self.assertEqual(response[0], PASS, response[1]) expectedCount = self.templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.child_do_admin.id) self.assertEqual(response[0], PASS, response[1]) accountLimit = self.templateSize response = self.updateSecondaryStorageLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) return
def test_listtemplate(self): # Register template under one domain admin(root/domain1->account 1) template_register = Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account1.name, domainid=self.domain1.id) template_register.download(self.apiclient) self.download(self.apiclient, template_register.id) listtemplate = Template.list(self.apiclient, zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account2.name, domainid=self.account2.domainid, templatefilter="executable") self.assertEqual(listtemplate, None, "Check templates are not listed - CLOUDSTACK-10149") return
def setUp(self): self.apiclient = self.testClient.getApiClient() self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.services = Services().services self.services["virtual_machine"]["zoneid"] = self.zone.id self.account = Account.create(self.apiclient, self.services["account"], domainid=self.domain.id) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template"]["url"] = builtin_info[0] self.services["template"]["hypervisor"] = builtin_info[1] self.services["template"]["format"] = builtin_info[2] # Register new template self.template = Template.register( self.apiclient, self.services["template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor, ) self.debug( "Registered a template of format: %s with ID: %s" % (self.services["template"]["format"], self.template.id) ) try: self.template.download(self.apiclient) except Exception as e: raise Exception("Template download failed: %s" % e) self.cleanup = [self.account] return
def setUpClass(cls): testClient = super(TestSnapshotRootDisk, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.pod = get_pod(cls.apiclient, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.hypervisorNotSupported = False cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in [ 'hyperv', 'lxc' ] or 'kvm-centos6' in cls.testClient.getZoneForTests(): cls.hypervisorNotSupported = True cls._cleanup = [] if not cls.hypervisorNotSupported: macchinina = Templates().templates["macchinina"] cls.template = Template.register( cls.apiclient, macchinina[cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["domainid"] = cls.domain.id cls.services["small"]["zoneid"] = cls.zone.id cls.services["templates"]["ostypeid"] = cls.template.ostypeid cls.services["zoneid"] = cls.zone.id # Create VMs, NAT Rules etc cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"]) cls.virtual_machine = cls.virtual_machine_with_disk = \ VirtualMachine.create( cls.apiclient, cls.services["small"], templateid=cls.template.id, accountid=cls.account.name, domainid=cls.account.domainid, zoneid=cls.zone.id, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.account) cls._cleanup.append(cls.template) return
def setUpClass(cls): testClient = super(TestSnapshotRootDisk, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.hypervisorNotSupported = False cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in ['hyperv', 'lxc'] or 'kvm-centos6' in cls.testClient.getZoneForTests(): cls.hypervisorNotSupported = True cls._cleanup = [] if not cls.hypervisorNotSupported: macchinina = Templates().templates["macchinina"] cls.template = Template.register(cls.apiclient, macchinina[cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["domainid"] = cls.domain.id cls.services["small"]["zoneid"] = cls.zone.id cls.services["templates"]["ostypeid"] = cls.template.ostypeid cls.services["zoneid"] = cls.zone.id # Create VMs, NAT Rules etc cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) cls.virtual_machine = cls.virtual_machine_with_disk = \ VirtualMachine.create( cls.apiclient, cls.services["small"], templateid=cls.template.id, accountid=cls.account.name, domainid=cls.account.domainid, zoneid=cls.zone.id, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) cls._cleanup.append(cls.virtual_machine) cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.account) cls._cleanup.append(cls.template) return
def test_01_register_template(self, value): """Test register template # Validate the following: 1. Create a root domain admin/ child domain admin account 2. Register and download a template according to hypervisor type 3. Verify that the template is listed 4. Verify that the secondary storage count for the account equals the size of the template 5. Delete the template 6. Verify that the secondary storage resource count of the account equals 0 """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list(self.apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0],PASS,\ "templates list validation failed") templateSize = (templates[0].size / (1024**3)) expectedCount = templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: template.delete(self.apiclient) except Exception as e: self.fail("Failed to delete template: %s" % e) expectedCount = 0 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_es_47_list_os_types_win_2012(self): """ @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is set to true @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947 @Steps: Step1: register windows 2012 VM template as windows 8 template Step2: deploy a VM with windows2012 template and Verify that VM creation is successful """ if not is_config_suitable(apiclient=self.apiClient, name='apply.allocation.algorithm.to.pods', value='true'): self.skipTest('apply.allocation.algorithm.to.pods ' 'should be true. skipping') # register windows 2012 VM template as windows 8 template self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest( "windows VM is not supported on %s" % self.hypervisor.lower()) self.win2012_template = Template.register( self.apiClient, self.services["win2012template"], zoneid=self.zone.id, account=self.account.name, domainid=self.domain.id, hypervisor=self.hypervisor ) # Wait for template to download self.win2012_template.download(self.apiClient) self.cleanup.append(self.win2012_template) # Wait for template status to be changed across time.sleep(60) # Deploy self.debug("Deploying win 2012 VM in account: %s" % self.account.name) self.services["virtual_machine"]["displayname"] = "win2012" self.services["virtual_machine"]["zoneid"] = self.zone.id self.services["virtual_machine"]["template"] = self.win2012_template.id vm1 = VirtualMachine.create( self.apiClient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id ) self.cleanup.append(vm1) # Verify VM state self.assertEqual( vm1.state, 'Running', "Check VM state is Running or not" ) return
def test_Scale_VM(self): """ @desc: 1. Enable dynamic scaling in Global settings 2. Register an CentOS 7 tempplate(with tools) and tick dynamic scaling 3. Deploy VM with this template 4.Start the VM and try to change service offering """ self.hypervisor = str(get_hypervisor_type(self.api_client)).lower() if self.hypervisor != "xenserver": self.skipTest("This test can be run only on xenserver") self.updateConfigurAndRestart("enable.dynamic.scale.vm","true") template = Template.register( self.userapiclient, self.services["CentOS7template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid ) self.assertIsNotNone(template,"Failed to register CentOS 7 template") self.debug( "Registered a template with format {} and id {}".format( self.services["CentOS7template"]["format"],template.id) ) template.download(self.userapiclient) self.cleanup.append(template) vm = VirtualMachine.create( self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=template.id, zoneid=self.zone.id ) self.assertIsNotNone(vm,"Failed to deploy virtual machine") self.cleanup.append(vm) response = VirtualMachine.list(self.userapiclient,id=vm.id) status = validateList(response) self.assertEqual(status[0],PASS,"list vm response returned invalid list") self.assertEqual(status[1].state,"Running", "vm is not running") service_offering = ServiceOffering.create( self.apiClient, self.services["service_offerings"]["big"] ) time.sleep(self.services["sleep"]) vm.scale(self.userapiclient,service_offering.id) scaleresponse = VirtualMachine.list(self.userapiclient,id=vm.id) scalestatus = validateList(scaleresponse) self.assertEqual(scalestatus[0],PASS,"list vm response returned invalid list") self.assertEqual(scalestatus[1].serviceofferingname,service_offering.name, " service offering is not same") self.assertEqual(scalestatus[1].serviceofferingid,service_offering.id, " service offering ids are not same") return
def setUpClass(cls): cls.logger = logging.getLogger('TestVPCRemoteAccessVPN') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) cls.startTime = time.time() testClient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.compute_offering = ServiceOffering.create( cls.apiclient, cls.services["compute_offering"]) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) if cls.services["default_hypervisor"] == "kvm": cls.template = Template.register( cls.apiclient, cls.services["template_kvm"], cls.zone.id, hypervisor=cls.services["template_kvm"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id) else: cls.template = Template.register( cls.apiclient, cls.services["template_xen"], cls.zone.id, hypervisor=cls.services["template_xen"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id) if cls.template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services[ "compute_offering"] cls.services["virtual_machine"]["hypervisor"] = cls.services[ "default_hypervisor"] cls.cleanup = [cls.account]
def setUpClass(cls): cls.logger = logging.getLogger("TestVPCRemoteAccessVPN") cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) cls.startTime = time.time() testClient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.compute_offering = ServiceOffering.create(cls.apiclient, cls.services["compute_offering"]) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) if cls.services["default_hypervisor"] == "kvm": cls.template = Template.register( cls.apiclient, cls.services["template_kvm"], cls.zone.id, hypervisor=cls.services["template_kvm"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id, ) else: cls.template = Template.register( cls.apiclient, cls.services["template_xen"], cls.zone.id, hypervisor=cls.services["template_xen"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id, ) if cls.template == FAILED: assert False, ( "get_template() failed to return template with description %s" % cls.services["compute_offering"] ) cls.services["virtual_machine"]["hypervisor"] = cls.services["default_hypervisor"] cls.cleanup = [cls.account]
def test_03_attach_ISO_in_RHEL7OSVM(self): """ @desc:Incorrect guest os mapping in vmware for Rhel7. Add a valid RHEL7 URL to execute this test case Step1 :Register an RHEL 7 template Step2 :Launch a VM Step3: Try to attach VMware Tools ISO Step4: Verify VMware tools ISO attached correctly """ self.hypervisor = str(get_hypervisor_type(self.api_client)).lower() if self.hypervisor != "vmware": self.skipTest("This test can be run only on vmware") self.services["Rhel7template"][ "url"] = "http://10.147.28.7/templates/rhel71.ova", template = Template.register(self.userapiclient, self.services["Rhel7template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) self.debug("Registered a template with format {} and id {}".format( self.services["Rhel7template"]["format"], template.id)) template.download(self.userapiclient) self.cleanup.append(template) vm = VirtualMachine.create(self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=template.id, zoneid=self.zone.id) self.cleanup.append(vm) response = VirtualMachine.list(self.userapiclient, id=vm.id) status = validateList(response) self.assertEqual(status[0], PASS, "list vm response returned invalid list") list_default_iso_response = list_isos(self.api_client, name="vmware-tools.iso", account="system", isready="true") status = validateList(list_default_iso_response) self.assertEqual(PASS, status[0], "ISO list is empty") self.debug("Registered a ISO with name {}".format( list_default_iso_response[0].name)) try: vm.attach_iso(self.userapiclient, list_default_iso_response[0]) except CloudstackAPIException as e: self.fail("Attached ISO failed : %s" % e) response = VirtualMachine.list(self.userapiclient, id=vm.id) status = validateList(response) self.assertEqual(status[0], PASS, "list vm response returned invalid list") attachedIsoName = response[0].isoname self.assertEqual(attachedIsoName, "vmware-tools.iso", "vmware-tools.iso not attached") return
def test_Scale_VM(self): """ @desc: 1. Enable dynamic scaling in Global settings 2. Register an CentOS 7 tempplate(with tools) and tick dynamic scaling 3. Deploy VM with this template 4.Start the VM and try to change service offering """ self.hypervisor = str(get_hypervisor_type(self.api_client)).lower() if self.hypervisor != "xenserver": self.skipTest("This test can be run only on xenserver") self.updateConfigurAndRestart("enable.dynamic.scale.vm", "true") template = Template.register(self.userapiclient, self.services["CentOS7template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) self.assertIsNotNone(template, "Failed to register CentOS 7 template") self.debug("Registered a template with format {} and id {}".format( self.services["CentOS7template"]["format"], template.id)) template.download(self.userapiclient) self.cleanup.append(template) vm = VirtualMachine.create(self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=template.id, zoneid=self.zone.id) self.assertIsNotNone(vm, "Failed to deploy virtual machine") self.cleanup.append(vm) response = VirtualMachine.list(self.userapiclient, id=vm.id) status = validateList(response) self.assertEqual(status[0], PASS, "list vm response returned invalid list") self.assertEqual(status[1].state, "Running", "vm is not running") service_offering = ServiceOffering.create( self.apiClient, self.services["service_offerings"]["big"]) time.sleep(self.services["sleep"]) vm.scale(self.userapiclient, service_offering.id) scaleresponse = VirtualMachine.list(self.userapiclient, id=vm.id) scalestatus = validateList(scaleresponse) self.assertEqual(scalestatus[0], PASS, "list vm response returned invalid list") self.assertEqual(scalestatus[1].serviceofferingname, service_offering.name, " service offering is not same") self.assertEqual(scalestatus[1].serviceofferingid, service_offering.id, " service offering ids are not same") return
def setUpClass(cls): cls.logger = logging.getLogger('TestInternalLb') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestInternalLb, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.compute_offering = ServiceOffering.create( cls.apiclient, cls.services["compute_offering"] ) cls.account = Account.create( cls.apiclient, services=cls.services["account"]) if cls.services["default_hypervisor"] == "kvm": cls.template = Template.register(cls.apiclient, cls.services["template_kvm"], cls.zone.id, hypervisor=cls.services[ "template_kvm"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id) else: cls.template = Template.register(cls.apiclient, cls.services["template_xen"], cls.zone.id, hypervisor=cls.services[ "template_xen"]["hypervisor"], account=cls.account.name, domainid=cls.domain.id) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.logger.debug("Successfully created account: %s, id: \ %s" % (cls.account.name, cls.account.id)) cls.cleanup = [cls.account] return
def setUpClass(cls): cls.logger = logging.getLogger("TestInternalLb") cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestInternalLb, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.logger.debug("Creating compute offering: %s" % cls.services["compute_offering"]["name"]) cls.compute_offering = ServiceOffering.create(cls.apiclient, cls.services["compute_offering"]) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.hypervisor = testClient.getHypervisorInfo() cls.logger.debug( "Downloading Template: %s from: %s" % ( cls.services["template"][cls.hypervisor.lower()], cls.services["template"][cls.hypervisor.lower()]["url"], ) ) cls.template = Template.register( cls.apiclient, cls.services["template"][cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), account=cls.account.name, domainid=cls.domain.id, ) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.logger.debug( "Successfully created account: %s, id: \ %s" % (cls.account.name, cls.account.id) ) cls._cleanup = [cls.account, cls.compute_offering] return
def setUpClass(cls): cls.testClient = super(TestDirectDownloadTemplates, cls).getClsTestClient() cls.apiclient = cls.testClient.getApiClient() cls.hypervisor = cls.testClient.getHypervisorInfo() cls.dbclient = cls.testClient.getDbConnection() cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.pod = get_pod(cls.apiclient, cls.zone.id) cls.services = cls.testClient.getParsedTestDataConfig() cls._cleanup = [] cls.hypervisorNotSupported = False if cls.hypervisor.lower() not in ['kvm', 'lxc']: cls.hypervisorNotSupported = True if not cls.hypervisorNotSupported: cls.services["test_templates"]["kvm"]["directdownload"] = "true" cls.template = Template.register( cls.apiclient, cls.services["test_templates"]["kvm"], zoneid=cls.zone.id, hypervisor=cls.hypervisor) cls._cleanup.append(cls.template) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["hypervisor"] = cls.hypervisor cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"]) cls._cleanup.append(cls.service_offering) cls.network_offering = NetworkOffering.create( cls.apiclient, cls.services["l2-network_offering"], ) cls.network_offering.update(cls.apiclient, state='Enabled') cls.services["network"][ "networkoffering"] = cls.network_offering.id cls.l2_network = Network.create( cls.apiclient, cls.services["l2-network"], zoneid=cls.zone.id, networkofferingid=cls.network_offering.id) cls._cleanup.append(cls.l2_network) cls._cleanup.append(cls.network_offering) return
def setUpClass(cls): cls.logger = logging.getLogger('TestInternalLb') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestInternalLb, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.logger.debug("Creating compute offering: %s" % cls.services["compute_offering"]["name"]) cls.compute_offering = ServiceOffering.create( cls.apiclient, cls.services["compute_offering"]) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.hypervisor = testClient.getHypervisorInfo() cls.logger.debug( "Downloading Template: %s from: %s" % (cls.services["template"][cls.hypervisor.lower()], cls.services["template"][cls.hypervisor.lower()]["url"])) cls.template = Template.register( cls.apiclient, cls.services["template"][cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), account=cls.account.name, domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.logger.debug("Successfully created account: %s, id: \ %s" % (cls.account.name, cls.account.id)) cls._cleanup = [cls.template, cls.account, cls.compute_offering] return
def test_03_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to register template with admin account where account has not used the # resources but @ project they are not available # 2. Template registration should error out saying ResourceAllocationException # with "resource limit exceeds""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate(inProject=True) self.assertEqual(response[0], PASS, response[1]) try: projects = Project.list(self.userapiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual( validateList(projects)[0], PASS, "projects list validation failed") self.assertEqual( self.templateSize, projects[0].secondarystoragetotal, "Resource count %s\ not matching with the expcted count: %s" % (projects[0].secondarystoragetotal, self.templateSize)) projectLimit = self.templateSize response = self.updateSecondaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.userapiclient, self.services["template_2"], zoneid=self.zone.id, projectid=self.project.id) template.delete(self.userapiclient) return
def setUpClass(cls): cls.logger = logging.getLogger('TestVPCSite2SiteVPN') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestVpcSite2SiteVpn, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.compute_offering = ServiceOffering.create( cls.apiclient, cls.services["compute_offering"] ) cls.account = Account.create( cls.apiclient, services=cls.services["account"]) cls.hypervisor = testClient.getHypervisorInfo() cls.logger.debug("Downloading Template: %s from: %s" % (cls.services["template"][ cls.hypervisor.lower()], cls.services["template"][cls.hypervisor.lower()]["url"])) cls.template = Template.register(cls.apiclient, cls.services["template"][cls.hypervisor.lower( )], cls.zone.id, hypervisor=cls.hypervisor.lower(), account=cls.account.name, domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.logger.debug("Successfully created account: %s, id: \ %s" % (cls.account.name, cls.account.id)) cls.networkoffering = NetworkOffering.list( cls.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks") assert cls.networkoffering is not None and len( cls.networkoffering) > 0, "No VPC based network offering" cls._cleanup = [cls.template, cls.account, cls.compute_offering] return
def test_listtemplate(self): # Register template under one domain admin(root/domain1->account 1) template_register = Template.register( self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account1.name, domainid=self.domain1.id, ) template_register.download(self.apiclient) # self.cleanup.append(self.template_register) time.sleep(self.testdata["sleep"]) timeout = self.testdata["timeout"] while True: listTemplateResponse = Template.list( self.apiclient, templatefilter="all", id=template_register.id, account=self.account1.name, domainid=self.domain1.id, ) status = validateList(listTemplateResponse) self.assertEquals(PASS, status[0], "Template creation failed") listtemplate = Template.list( self.apiclient, zoneid=self.zone.id, hypervisor=self.hypervisor, account=self.account2.name, domainid=self.account2.domainid, templatefilter=self.testdata["templatefilter"], ) self.assertEqual(listtemplate, None, "Check templates are not listed") return
def test_03_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to register template with admin account where account has not used the # resources but @ project they are not available # 2. Template registration should error out saying ResourceAllocationException # with "resource limit exceeds""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate(inProject=True) self.assertEqual(response[0], PASS, response[1]) try: projects = Project.list(self.userapiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual(validateList(projects)[0], PASS, "projects list validation failed") self.assertEqual(self.templateSize, projects[0].secondarystoragetotal, "Resource count %s\ not matching with the expcted count: %s" % (projects[0].secondarystoragetotal, self.templateSize)) projectLimit = self.templateSize response = self.updateSecondaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.userapiclient, self.services["template_2"], zoneid=self.zone.id, projectid=self.project.id) template.delete(self.userapiclient) return
def setUpClass(cls): # We want to fail quicker if it's failure socket.setdefaulttimeout(60) cls.testClient = super(TestVPCRedundancy, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.hypervisor = cls.testClient.getHypervisorInfo() cls.template = Template.register( cls.api_client, cls.services["template"][cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.api_client) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"]) cls._cleanup = [cls.service_offering, cls.template] cls.logger = logging.getLogger('TestVPCRedundancy') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) return
def test_01_create_template(self): """Test create public & private template """ # Validate the following: # 1. Upload a templates in raw img format. Create a Vm instances from # raw img template. # 2. Upload a templates in zip file format. Create a Vm instances from # zip template. # 3. Upload a templates in tar format.Create a Vm instances from tar # template. # 4. Upload a templates in tar gzip format.Create a Vm instances from # tar gzip template. # 5. Upload a templates in tar bzip format. Create a Vm instances from # tar bzip template. # 6. Verify VMs & Templates is up and in ready state builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["templates"][0]["url"] = builtin_info[0] self.services["templates"][0]["hypervisor"] = builtin_info[1] self.services["templates"][0]["format"] = builtin_info[2] # Register new template template = Template.register( self.apiclient, self.services["templates"][0], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( self.services["templates"][0]["format"], template.id )) # Wait for template to download template.download(self.apiclient) self.cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) timeout = self.services["timeout"] while True: list_template_response = Template.list( self.apiclient, templatefilter='all', id=template.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) if isinstance(list_template_response, list): break elif timeout == 0: raise Exception("List template failed!") time.sleep(5) timeout = timeout - 1 # Verify template response to check whether template added successfully self.assertEqual( isinstance(list_template_response, list), True, "Check for list template response return valid data" ) self.assertNotEqual( len(list_template_response), 0, "Check template available in List Templates" ) template_response = list_template_response[0] self.assertEqual( template_response.isready, True, "Template state is not ready, it is %s" % template_response.isready ) # Deploy new virtual machine using template virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, mode=self.services["mode"] ) self.debug("creating an instance with template ID: %s" % template.id) vm_response = VirtualMachine.list(self.apiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid) self.assertEqual( isinstance(vm_response, list), True, "Check for list VMs response after VM deployment" ) # Verify VM response to check whether VM deployment was successful self.assertNotEqual( len(vm_response), 0, "Check VMs available in List VMs response" ) vm = vm_response[0] self.assertEqual( vm.state, 'Running', "Check the state of VM created from Template" ) return
def setUpClass(cls): testClient = super(TestScaleVm, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][ 0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ cls._cleanup = [] cls.unsupportedHypervisor = False cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in ('kvm', 'hyperv', 'lxc'): cls.unsupportedHypervisor = True return # Get Zone, Domain and templates domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype if cls.hypervisor.lower() in ['simulator', 'vmware']: cls.template = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"]) if cls.template == FAILED: assert False, "get_template() failed to return template\ with description %s" % cls.services["ostype"] cls.template = Template.update(cls.template, cls.apiclient, isdynamicallyscalable='true') else: cls.template = Template.register(cls.apiclient, cls.services["CentOS7template"], zoneid=cls.zone.id) cls._cleanup.append(cls.template) cls.template.download(cls.apiclient) time.sleep(60) # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = cls.template.id # Create account, service offerings, vm. cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=domain.id) cls._cleanup.append(cls.account) cls.small_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"]) cls._cleanup.append(cls.small_offering) cls.big_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["big"]) cls._cleanup.append(cls.big_offering) Configurations.update(cls.apiclient, name="enable.dynamic.scale.vm", value="true") cls.small_offering_dynamic_scaling_disabled = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], dynamicscalingenabled=False) cls.big_offering_dynamic_scaling_disabled = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], dynamicscalingenabled=False) # create a virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering.id, mode=cls.services["mode"]) # create a virtual machine which cannot be dynamically scalable cls.virtual_machine_with_service_offering_dynamic_scaling_disabled = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering_dynamic_scaling_disabled.id, mode=cls.services["mode"]) # create a virtual machine which cannot be dynamically scalable cls.virtual_machine_not_dynamically_scalable = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering.id, mode=cls.services["mode"], dynamicscalingenabled=False) cls._cleanup = [ cls.small_offering, cls.big_offering, cls.small_offering_dynamic_scaling_disabled, cls.big_offering_dynamic_scaling_disabled, cls.account ]
def test_04_copy_template(self, value): """Test copy template between zones Steps and validations: This test requires at least two zones present in the setup 1. Create a root domain/child domain admin account 2. Register and download a template in the account 3. Verify the secondary storage resource count of the account equals the size of the template 4. Copy this template to other zone 5. Verify that the secondary storage resource count is now doubled as there are two templates now in two zones under the admin account """ zones = list_zones(self.apiclient) self.assertEqual( validateList(zones)[0], PASS, "zones list validation faield") if len(zones) < 2: self.skipTest( "At least 2 zones should be present for this test case") response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list(self.apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0],PASS,\ "templates list validation failed") templateSize = (templates[0].size / (1024**3)) expectedCount = templateSize response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) templateDestinationZoneId = None for zone in zones: if template.zoneid != zone.id: templateDestinationZoneId = zone.id break template.copy(self.apiclient, destzoneid=templateDestinationZoneId, sourcezoneid=template.zoneid) expectedCount = (templateSize * 2) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_vm_nic_adapter_vmxnet3(self): """ # 1. Register a template for VMware with nicAdapter vmxnet3 # 2. Deploy a VM using this template # 3. Create an isolated network # 4. Add network to VM # 5. Verify that the NIC adapter for VM for both the nics # is vmxnet3 """ if self.hypervisor.lower() not in ["vmware"]: self.skipTest("This test case is written specifically\ for Vmware hypervisor") # Register a private template in the account with nic adapter vmxnet3 template = Template.register( self.userapiclient, self.testdata["configurableData"]["vmxnet3template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, details=[{ "nicAdapter": self.testdata["configurableData"]["vmxnet3template"] ["nicadapter"] }]) self.cleanup.append(template) template.download(self.apiclient) templates = Template.list(self.userapiclient, listall=True, id=template.id, templatefilter="self") self.assertEqual( validateList(templates)[0], PASS, "Templates list validation failed") self.testdata["virtual_machine"]["zoneid"] = self.zone.id self.testdata["virtual_machine"]["template"] = template.id virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id) isolated_network = Network.create( self.apiclient, self.testdata["isolated_network"], self.account.name, self.account.domainid, networkofferingid=self.isolated_network_offering.id) virtual_machine.add_nic(self.apiclient, isolated_network.id) # TODO: Add steps to check the Nic Adapter type in VCenter # using VCenter APIs return
def test_03_restore_vm_with_new_template(self): """ Test restoring a vm with different template than the one it was created with """ hosts = Host.list( self.apiclient, type="Routing", listall=True ) host_list_validation_result = validateList(hosts) self.assertEqual(host_list_validation_result[0], PASS, "host list validation failed due to %s" % host_list_validation_result[2]) hypervisor = host_list_validation_result[1].hypervisor for k, v in self.services["templates"].items(): if k.lower() == hypervisor.lower(): # Register new template template = Template.register( self.apiclient, v, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( v["format"], template.id )) self.debug( "Downloading template with ID: %s" % ( template.id )) template.download(self.apiclient) self._cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) self.verify_template_listing(template) # Restore a vm with the new template. self.vm_with_reset.restore(self.apiclient, templateid=template.id) self.vm_without_reset.restore(self.apiclient, templateid=template.id) # Make sure the VMs now have the new template ID # Make sure the Ip address of the VMs haven't changed self.debug("Checking template id of VM with isVolatile=True") vms = VirtualMachine.list( self.apiclient, id=self.vm_with_reset.id, listall=True ) vm_list_validation_result = validateList(vms) self.assertEqual(vm_list_validation_result[0], PASS, "VM list validation failed due to %s" % vm_list_validation_result[2]) vm_with_reset = vm_list_validation_result[1] self.assertNotEqual(self.vm_with_reset.templateid, vm_with_reset.templateid, "VM created with IsVolatile=True has same templateid : %s after restore" %vm_with_reset.templateid ) self.assertNotEqual(self.vm_with_reset.templateid, template.id, "VM created with IsVolatile=True has wrong templateid after restore Got:%s Expected: %s" %(self.vm_with_reset.templateid, template.id) ) # Make sure it has the same IP after reboot self.assertEqual(self.vm_with_reset.nic[0].ipaddress, vm_with_reset.nic[0].ipaddress, "VM created with IsVolatile=True doesn't have same ip after restore. Got : %s Expected : %s" %(vm_with_reset.nic[0].ipaddress, self.vm_with_reset.nic[0].ipaddress) ) # Check if the the root disk was not destroyed for isVolatile=False self.debug("Checking template id of VM with isVolatile=False") vms = VirtualMachine.list( self.apiclient, id=self.vm_without_reset.id, listall=True ) vm_list_validation_result = validateList(vms) self.assertEqual(vm_list_validation_result[0], PASS, "VM list validation failed due to %s" % vm_list_validation_result[2]) vm_without_reset = vm_list_validation_result[1] self.assertNotEqual(self.vm_without_reset.templateid, vm_without_reset.templateid, "VM created with IsVolatile=False has same templateid : %s after restore" %vm_with_reset.templateid ) self.assertNotEqual(self.vm_without_reset.templateid, template.id, "VM created with IsVolatile=False has wrong templateid after restore Got:%s Expected: %s" %(self.vm_without_reset.templateid, template.id) ) # Make sure it has the same IP after reboot self.assertEqual(self.vm_without_reset.nic[0].ipaddress, vm_without_reset.nic[0].ipaddress, "VM created with IsVolatile=False doesn't have same ip after restore. Got : %s Expected : %s" %(vm_without_reset.nic[0].ipaddress, self.vm_without_reset.nic[0].ipaddress) ) return
def setUpClass(cls): cls.testClient = super(TestKubernetesCluster, cls).getClsTestClient() cls.apiclient = cls.testClient.getApiClient() cls.services = cls.testClient.getParsedTestDataConfig() cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.hypervisor = cls.testClient.getHypervisorInfo() cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ cls.cks_template_name_key = "cloud.kubernetes.cluster.template.name." + cls.hypervisor.lower( ) cls.setup_failed = False cls.initial_configuration_cks_enabled = Configurations.list( cls.apiclient, name="cloud.kubernetes.service.enabled")[0].value if cls.initial_configuration_cks_enabled not in ["true", True]: cls.debug( "Enabling CloudStack Kubernetes Service plugin and restarting management server" ) Configurations.update(cls.apiclient, "cloud.kubernetes.service.enabled", "true") cls.restartServer() cls.cks_template = None cls.initial_configuration_cks_template_name = None cls.cks_service_offering = None cls.kubernetes_version_ids = [] if cls.setup_failed == False: try: cls.kuberetes_version_1 = cls.addKubernetesSupportedVersion( '1.14.9', 'http://staging.yadav.xyz/cks/binaries-iso/setup-1.14.9.iso' ) cls.kubernetes_version_ids.append(cls.kuberetes_version_1.id) except Exception as e: cls.setup_failed = True cls.debug( "Failed to get Kubernetes version ISO in ready state, http://staging.yadav.xyz/cks/binaries-iso/setup-1.14.9.iso, %s" % e) if cls.setup_failed == False: try: cls.kuberetes_version_2 = cls.addKubernetesSupportedVersion( '1.15.0', 'http://staging.yadav.xyz/cks/binaries-iso/setup-1.15.0.iso' ) cls.kubernetes_version_ids.append(cls.kuberetes_version_2.id) except Exception as e: cls.setup_failed = True cls.debug( "Failed to get Kubernetes version ISO in ready state, http://staging.yadav.xyz/cks/binaries-iso/setup-1.15.0.iso, %s" % e) if cls.setup_failed == False: try: cls.kuberetes_version_3 = cls.addKubernetesSupportedVersion( '1.16.0', 'http://staging.yadav.xyz/cks/binaries-iso/setup-1.16.0.iso' ) cls.kubernetes_version_ids.append(cls.kuberetes_version_3.id) except Exception as e: cls.setup_failed = True cls.debug( "Failed to get Kubernetes version ISO in ready state, http://staging.yadav.xyz/cks/binaries-iso/setup-1.16.0.is, %s" % e) if cls.setup_failed == False: try: cls.kuberetes_version_4 = cls.addKubernetesSupportedVersion( '1.16.3', 'http://staging.yadav.xyz/cks/binaries-iso/setup-1.16.3.iso' ) cls.kubernetes_version_ids.append(cls.kuberetes_version_4.id) except Exception as e: cls.setup_failed = True cls.debug( "Failed to get Kubernetes version ISO in ready state, http://staging.yadav.xyz/cks/binaries-iso/setup-1.16.3.is, %s" % e) cks_template_data = { "name": "Kubernetes-Service-Template", "displaytext": "Kubernetes-Service-Template", "format": "qcow2", "hypervisor": "kvm", "ostype": "CoreOS", "url": "http://staging.yadav.xyz/cks/templates/coreos_production_cloudstack_image-kvm.qcow2.bz2", "ispublic": "True", "isextractable": "True" } # "http://dl.openvm.eu/cloudstack/coreos/x86_64/coreos_production_cloudstack_image-kvm.qcow2.bz2" cks_template_data_details = [] if cls.hypervisor.lower() == "vmware": cks_template_data[ "url"] = "http://staging.yadav.xyz/cks/templates/coreos_production_cloudstack_image-vmware.ova" # "http://dl.openvm.eu/cloudstack/coreos/x86_64/coreos_production_cloudstack_image-vmware.ova" cks_template_data["format"] = "OVA" cks_template_data_details = [{ "keyboard": "us", "nicAdapter": "Vmxnet3", "rootDiskController": "pvscsi" }] elif cls.hypervisor.lower() == "xenserver": cks_template_data[ "url"] = "http://staging.yadav.xyz/cks/templates/coreos_production_cloudstack_image-xen.vhd.bz2" # "http://dl.openvm.eu/cloudstack/coreos/x86_64/coreos_production_cloudstack_image-xen.vhd.bz2" cks_template_data["format"] = "VHD" elif cls.hypervisor.lower() == "kvm": cks_template_data["requireshvm"] = "True" if cls.setup_failed == False: cls.cks_template = Template.register( cls.apiclient, cks_template_data, zoneid=cls.zone.id, hypervisor=cls.hypervisor, details=cks_template_data_details) cls.debug("Waiting for CKS template with ID %s to be ready" % cls.cks_template.id) try: cls.waitForTemplateReadyState(cls.cks_template.id) except Exception as e: cls.setup_failed = True cls.debug( "Failed to get CKS template in ready state, {}, {}".format( cks_template_data["url"], e)) cls.initial_configuration_cks_template_name = Configurations.list( cls.apiclient, name=cls.cks_template_name_key)[0].value Configurations.update(cls.apiclient, cls.cks_template_name_key, cls.cks_template.name) cks_offering_data = { "name": "CKS-Instance", "displaytext": "CKS Instance", "cpunumber": 2, "cpuspeed": 1000, "memory": 2048, } cks_offering_data[ "name"] = cks_offering_data["name"] + '-' + random_gen() if cls.setup_failed == False: cls.cks_service_offering = ServiceOffering.create( cls.apiclient, cks_offering_data) cls._cleanup = [] if cls.cks_template != None: cls._cleanup.append(cls.cks_template) if cls.cks_service_offering != None: cls._cleanup.append(cls.cks_service_offering) return
def test_04_copy_template(self): """ @Desc: Test to copy Template from one zone to another @steps: Step1: Listing Zones available for a user Step2: Verifying if the zones listed are greater than 1. If Yes continuing. If not halting the test. Step3: Listing all the templates for a user in zone1 Step4: Verifying that no templates are listed Step5: Listing all the templates for a user in zone2 Step6: Verifying that no templates are listed Step7: Creating a Template in zone 1 Step8: Listing all the Templates again for a user in zone1 Step9: Verifying that list size is 1 Step10: Listing all the templates for a user in zone2 Step11: Verifying that no templates are listed Step12: Copying the template created in step7 from zone1 to zone2 Step13: Listing all the templates for a user in zone2 Step14: Verifying that list size is 1 Step15: Listing all the Templates for a user in zone1 Step16: Verifying that list size is 1 """ # Listing Zones available for a user zones_list = Zone.list( self.userapiclient, available=True ) status = validateList(zones_list) self.assertEquals( PASS, status[0], "Failed to list Zones" ) if not len(zones_list) > 1: raise unittest.SkipTest("Not enough zones exist to copy template") else: # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone1, "Templates listed for newly created User in Zone1" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone2, "Templates listed for newly created User in Zone2" ) self.services["privatetemplate"][ "ostype"] = self.services["ostype"] # Listing Hypervisors in Zone 1 hypervisor_list = Hypervisor.list( self.apiClient, zoneid=zones_list[0].id ) status = validateList(zones_list) self.assertEquals( PASS, status[0], "Failed to list Hypervisors in Zone 1" ) # Creating aTemplate in Zone 1 template_created = Template.register( self.userapiclient, self.services["privatetemplate"], zones_list[0].id, hypervisor=hypervisor_list[0].name ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_templates_zone1) self.assertEquals( PASS, status[0], "Templates creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone1), "Failed to create a Template" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone2, "Templates listed for newly created User in Zone2" ) # Verifying the state of the template to be ready. If not waiting # for state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail( "Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Copying the Template from Zone1 to Zone2 copied_template = template_created.copy( self.userapiclient, sourcezoneid=template_created.zoneid, destzoneid=zones_list[1].id ) self.assertIsNotNone( copied_template, "Copying Template from Zone1 to Zone2 failed" ) # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_templates_zone1) self.assertEquals( PASS, status[0], "Templates creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone1), "Failed to create a Template" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) status = validateList(list_templates_zone2) self.assertEquals( PASS, status[0], "Template failed to copy into Zone2" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone2), "Template failed to copy into Zone2" ) self.assertNotEquals( "Connection refused", list_templates_zone2[0].status, "Failed to copy Template" ) self.assertEquals( True, list_templates_zone2[0].isready, "Failed to copy Template" ) del self.services["privatetemplate"]["ostype"] return
def setUpClass(cls): testClient = super(TestXDCCPInterop, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = 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.services['mode'] = cls.zone.networktype hosts = list_hosts( cls.apiclient, type="Routing" ) if hosts is None: raise unittest.SkipTest( "There are no hypervisor's available.Check list hosts response") for hypervisorhost in hosts : if hypervisorhost.hypervisor == "XenServer": cls.uploadtemplateformat="VHD" break elif hypervisorhost.hypervisor== "VMware": cls.uploadtemplateformat="OVA" break elif hypervisorhost.hypervisor== "KVM": cls.uploadtemplateformat="KVM" break if cls.uploadtemplateformat=="KVM": assert False, "Interop is not supported on KVM" cls.uploadurl=cls.services["interop"][cls.uploadtemplateformat]["url"] cls.xtemplate = get_template( cls.apiclient, cls.zone.id, cls.services["ostype"] ) if cls.xtemplate == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id, admin=False ) cls.debug(cls.account.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["large"] ) cls.template = get_windows_template( cls.apiclient, cls.zone.id, ostype_desc="Windows 8 (64-bit)") #cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows Server 2012 (64-bit)") if cls.template == FAILED: if "http://pleaseupdateURL/" in cls.uploadurl: raise unittest.SkipTest( "Check Test Data file if it has the valid template URL") cls.template = Template.register( cls.apiclient, cls.services["interop"][cls.uploadtemplateformat], zoneid=cls.zone.id, domainid=cls.account.domainid, account=cls.account.name ) timeout = cls.services["vgpu"]["timeout"] while True: time.sleep(cls.services["vgpu"]["sleep"]) list_template_response = Template.list( cls.apiclient, templatefilter=cls.services["templatefilter"], id=cls.template.id ) if (isinstance(list_template_response, list)) is not True: raise unittest.SkipTest( "Check list template api response returns a valid list") if len(list_template_response) is None: raise unittest.SkipTest( "Check template registered is in List Templates") template_response = list_template_response[0] if template_response.isready: break if timeout == 0: raise unittest.SkipTest( "Failed to download template(ID: %s). " % template_response.id) timeout = timeout - 1 cls.volume=[] # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = cls.template.id user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500)) cls.services["virtual_machine"]["userdata"] = user_data # cls.services["large"]["zoneid"] = cls.zone.id # cls.services["large"]["template"] = cls.template.id cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services['mode'], startvm="false" ) cls.user_api_client = cls.testClient.getUserApiClient( UserName=cls.account.name, DomainName=cls.account.domain ) cls.cleanup = [ cls.service_offering, cls.account ]
def test_01_create_template(self): """Test create public & private template """ # Validate the following: # 1. Upload a templates in raw img format. Create a Vm instances from # raw img template. # 2. Upload a templates in zip file format. Create a Vm instances from # zip template. # 3. Upload a templates in tar format.Create a Vm instances from tar # template. # 4. Upload a templates in tar gzip format.Create a Vm instances from # tar gzip template. # 5. Upload a templates in tar bzip format. Create a Vm instances from # tar bzip template. # 6. Verify VMs & Templates is up and in ready state builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["templates"][0]["url"] = builtin_info[0] self.services["templates"][0]["hypervisor"] = builtin_info[1] self.services["templates"][0]["format"] = builtin_info[2] # Register new template template = Template.register(self.apiclient, self.services["templates"][0], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) self.debug("Registered a template of format: %s with ID: %s" % (self.services["templates"][0]["format"], template.id)) # Wait for template to download template.download(self.apiclient) self.cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) timeout = self.services["timeout"] while True: list_template_response = Template.list( self.apiclient, templatefilter='all', id=template.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) if isinstance(list_template_response, list): break elif timeout == 0: raise Exception("List template failed!") time.sleep(5) timeout = timeout - 1 #Verify template response to check whether template added successfully self.assertEqual(isinstance(list_template_response, list), True, "Check for list template response return valid data") self.assertNotEqual(len(list_template_response), 0, "Check template available in List Templates") template_response = list_template_response[0] self.assertEqual( template_response.isready, True, "Template state is not ready, it is %s" % template_response.isready) # Deploy new virtual machine using template virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, mode=self.services["mode"]) self.debug("creating an instance with template ID: %s" % template.id) vm_response = VirtualMachine.list(self.apiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(vm_response, list), True, "Check for list VMs response after VM deployment") #Verify VM response to check whether VM deployment was successful self.assertNotEqual(len(vm_response), 0, "Check VMs available in List VMs response") vm = vm_response[0] self.assertEqual(vm.state, 'Running', "Check the state of VM created from Template") return
def setUpClass(cls): cls.logger = logging.getLogger('TestDeployVirtioSCSIVM') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) testClient = super(TestDeployVirtioSCSIVM, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = cls.testClient.getParsedTestDataConfig() cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][ 0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ cls.hypervisorNotSupported = False cls.hypervisor = testClient.getHypervisorInfo() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.pod = get_pod(cls.apiclient, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls._cleanup = [] if cls.hypervisor.lower() not in ['kvm']: cls.hypervisorNotSupported = True return kvmvirtioscsi = Templates().templates["kvmvirtioscsi"] cls.template = Template.register(cls.apiclient, kvmvirtioscsi[cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.apiclient) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["domainid"] = cls.domain.id cls.services["small"]["zoneid"] = cls.zone.id cls.services["zoneid"] = cls.zone.id cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"]) cls.sparse_disk_offering = DiskOffering.create( cls.apiclient, cls.services["sparse_disk_offering"]) cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], templateid=cls.template.id, accountid=cls.account.name, domainid=cls.account.domainid, zoneid=cls.zone.id, serviceofferingid=cls.service_offering.id, diskofferingid=cls.sparse_disk_offering.id, mode=cls.zone.networktype) hosts = Host.list(cls.apiclient, id=cls.virtual_machine.hostid) if len(hosts) != 1: assert False, "Could not find host with id " + cls.virtual_machine.hostid cls.vmhost = hosts[0] password = cls.virtual_machine.resetPassword(cls.apiclient) cls.virtual_machine.username = "******" cls.virtual_machine.password = password cls._cleanup = [ cls.template, cls.service_offering, cls.sparse_disk_offering, cls.account ]
def setUp(self): self.testdata = self.testClient.getParsedTestDataConfig()["vgpu"] self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() if self.noSuitableHost or self.unsupportedHypervisor: self.hypervisor = get_hypervisor_type(self.apiclient) if self.hypervisor.lower() not in ["vmware"]: self.skipTest( "Skipping test because suitable hypervisor/host not\ present") self.testdata = self.testClient.getParsedTestDataConfig() self.cleanup = [] # Get Zone, Domain and Default Built-in template self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) # Creating Account self.account = Account.create(self.apiclient, self.testdata["account"], domainid=self.domain.id) if self.hypervisor.lower() in ["xenserver"]: # Before running this test for Xen Server, register a windows template with ostype as # 'Windows 7 (32-bit)' self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) self.cleanup.append(self.template) self.testdata["mode"] = self.zone.networktype if self.template == FAILED: assert False, "get_template() failed to return template with description %s" % self.testdata[ "ostype"] self.testdata["small"]["zoneid"] = self.zone.id self.testdata["small"]["template"] = self.template.id self.testdata["service_offerings"]["vgpu260qwin"][ "serviceofferingdetails"] = [{ 'pciDevice': 'Group of NVIDIA Corporation GK107GL [GRID K1] GPUs' }, { 'vgpuType': 'GRID K120Q' }] # create a service offering self.service_offering = ServiceOffering.create( self.apiclient, self.testdata["service_offerings"]["vgpu260qwin"], ) self.cleanup.append(self.service_offering) elif self.hypervisor.lower() in ["vmware"]: self.testdata["isolated_network"]["zoneid"] = self.zone.id self.userapiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.service_offering = ServiceOffering.create( self.apiclient, self.testdata["service_offering"]) # Create Shared Network Offering self.isolated_network_offering = NetworkOffering.create( self.apiclient, self.testdata["isolated_network_offering"]) # Enable Isolated Network offering self.isolated_network_offering.update(self.apiclient, state='Enabled') # Register a private template in the account with nic adapter vmxnet3 # Also add required 3D GPU details for enabling it self.template = Template.register( self.userapiclient, self.testdata["configurableData"]["vmxnet3template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, details=[{ "mks.enable3d": "true", "mks.use3dRenderer": "automatic", "svga.autodetect": "false", "svga.vramSize": "131072" }])
def test_01_create_template(self): """TS_BUG_002-Test to create and deploy VM using password enabled template """ # Validate the following: #1. Create a password enabled template #2. Deploy VM using this template #3. Deploy VM should return password set in template. builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template"]["url"] = builtin_info[0] self.services["template"]["hypervisor"] = builtin_info[1] self.services["template"]["format"] = builtin_info[2] self.debug("Registering a new template") # Register new template template = Template.register( self.apiclient, self.services["template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( self.services["template"]["format"], template.id )) try: # Wait for template to download template.download(self.apiclient) except Exception as e: self.fail("Exception while downloading template %s: %s"\ % (template.id, e)) self.cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) list_template_response = Template.list( self.apiclient, templatefilter=\ self.services["template"]["templatefilter"], id=template.id, zoneid=self.zone.id ) self.assertEqual( isinstance(list_template_response, list), True, "Check list response returns a valid list" ) #Verify template response to check whether template added successfully self.assertNotEqual( len(list_template_response), 0, "Check template available in List Templates" ) template_response = list_template_response[0] self.assertEqual( template_response.isready, True, "Template state is not ready, it is %s" % template_response.isready ) # Deploy new virtual machine using template virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.debug("Deployed VM with ID: %s " % virtual_machine.id) self.assertEqual( hasattr(virtual_machine, "password"), True, "Check if the deployed VM returned a password" ) return
def test_07_templates_per_project(self): """Test Templates limit per project """ # 1. set max no of templates per project to 1. # 2. Create a template in this project. Both template should be in # ready state # 3. Try create 2nd template in the project. It should give the user # appropriate error and an alert should be generated. # Reset the volume limits update_resource_limit( self.apiclient, 2, # Volume max=5, projectid=self.project.id ) self.debug( "Updating template resource limits for domain: %s" % self.account.domainid) # Set usage_vm=1 for Account 1 update_resource_limit( self.apiclient, 4, # Template max=1, projectid=self.project.id ) # Register the First Template in the project self.debug("Register the First Template in the project") builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template"]["url"] = builtin_info[0] self.services["template"]["hypervisor"] = builtin_info[1] self.services["template"]["format"] = builtin_info[2] # Register new template template = Template.register( self.userapiclient, self.services["template"], zoneid=self.zone.id, projectid=self.project.id ) self.debug( "Registered a template of format: %s with ID: %s" % ( self.services["template"]["format"], template.id )) self.cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) timeout = self.services["timeout"] while True: list_template_response = Template.list( self.apiclient, templatefilter='all', id=template.id, zoneid=self.zone.id, projectid=self.project.id, ) if list_template_response[0].isready is True: break elif timeout == 0: raise Exception("Template state is not ready, it is %s" % list_template_response[0].isready) time.sleep(self.services["sleep"]) timeout = timeout - 1 #Verify template response to check whether template added successfully self.assertEqual( isinstance(list_template_response, list), True, "Check for list template response return valid data" ) self.assertNotEqual( len(list_template_response), 0, "Check template available in List Templates" ) template_response = list_template_response[0] self.assertEqual( template_response.isready, True, "Template state is not ready, it is %s" % template_response.isready ) # Exception should be raised for second template with self.assertRaises(Exception): Template.register( self.userapiclient, self.services["template"], zoneid=self.zone.id, projectid=self.project.id ) return
def test_02_download_template(self): """ @Desc: Test to Download Template @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating a Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is 1 Step6: Verifying if the template is in ready state. If yes the continuing If not waiting and checking for template to be ready till timeout Step7: Downloading the template (Extract) Step8: Verifying that Template is downloaded """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) # Verifying that no Templates are listed self.assertIsNone( list_templates_before, "Templates listed for newly created User" ) self.services["privatetemplate"]["ostype"] = self.services["ostype"] self.services["privatetemplate"]["isextractable"] = True # Creating aTemplate template_created = Template.register( self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) status = validateList(list_templates_after) self.assertEquals( PASS, status[0], "Templates creation failed" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_after), "Failed to create a Template" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail("Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Downloading the Template name download_template = Template.extract( self.userapiclient, template_created.id, mode="HTTP_DOWNLOAD", zoneid=self.zone.id ) self.assertIsNotNone( download_template, "Download Template failed" ) # Verifying the details of downloaded template self.assertEquals( "DOWNLOAD_URL_CREATED", download_template.state, "Download URL not created for Template" ) self.assertIsNotNone( download_template.url, "Download URL not created for Template" ) self.assertEquals( template_created.id, download_template.id, "Download Template details are not same as Template created" ) del self.services["privatetemplate"]["ostype"] del self.services["privatetemplate"]["isextractable"] return
def setUpClass(cls): testClient = super(TestVmSnapshot, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls._cleanup = [] cls.unsupportedHypervisor = False cls.hypervisor = testClient.getHypervisorInfo() if cls.hypervisor.lower() != "kvm": cls.unsupportedHypervisor = True return cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) hosts = Host.list(cls.apiclient, zoneid=cls.zone.id, type='Routing', hypervisor='KVM') pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id) for pool in pools: if pool.type == "NetworkFilesystem" or pool.type == "Filesystem": raise unittest.SkipTest( "Storage-based snapshots functionality is not supported for NFS/Local primary storage" ) for host in hosts: if host.details['Host.OS'] in ['CentOS']: raise unittest.SkipTest( "The standard `qemu-kvm` which is the default for CentOS does not support the new functionality. It has to be installed `qemu-kvm-ev`" ) Configurations.update(cls.apiclient, name="kvm.vmstoragesnapshot.enabled", value="true") #The version of CentOS has to be supported templ = { "name": "CentOS8", "displaytext": "CentOS 8", "format": "QCOW2", "url": "http://download.cloudstack.org/releases/4.14/default-tmpl-centos8.0.qcow2.bz2", "ispublic": "True", "isextractable": "True", "hypervisor": cls.hypervisor, "zoneid": cls.zone.id, "ostype": "CentOS 8", "directdownload": True, } template = Template.register(cls.apiclient, templ, zoneid=cls.zone.id, hypervisor=cls.hypervisor) 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.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls._cleanup.append(cls.account) service_offerings_nfs = { "name": "nfs", "displaytext": "nfs", "cpunumber": 1, "cpuspeed": 500, "memory": 512, "storagetype": "shared", "customizediops": False, } cls.service_offering = ServiceOffering.create( cls.apiclient, service_offerings_nfs, ) cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services, zoneid=cls.zone.id, templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.zone.networktype, hypervisor=cls.hypervisor, rootdisksize=20, ) cls.random_data_0 = random_gen(size=100) cls.test_dir = "/tmp" cls.random_data = "random.data" return
def test_03_restore_vm_with_new_template(self): """ Test restoring a vm with different template than the one it was created with """ hosts = Host.list(self.apiclient, type="Routing", listall=True) host_list_validation_result = validateList(hosts) self.assertEqual( host_list_validation_result[0], PASS, "host list validation failed due to %s" % host_list_validation_result[2]) hypervisor = host_list_validation_result[1].hypervisor for k, v in self.services["templates"].items(): if k.lower() == hypervisor.lower(): # Register new template template = Template.register(self.apiclient, v, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) self.debug("Registered a template of format: %s with ID: %s" % (v["format"], template.id)) self.debug("Downloading template with ID: %s" % (template.id)) template.download(self.apiclient) self._cleanup.append(template) # Wait for template status to be changed across time.sleep(self.services["sleep"]) self.verify_template_listing(template) # Restore a vm with the new template. self.vm_with_reset.restore(self.apiclient, templateid=template.id) self.vm_without_reset.restore(self.apiclient, templateid=template.id) # Make sure the VMs now have the new template ID # Make sure the Ip address of the VMs haven't changed self.debug("Checking template id of VM with isVolatile=True") vms = VirtualMachine.list(self.apiclient, id=self.vm_with_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "VM list validation failed due to %s" % vm_list_validation_result[2]) vm_with_reset = vm_list_validation_result[1] self.assertNotEqual( self.vm_with_reset.templateid, vm_with_reset.templateid, "VM created with IsVolatile=True has same templateid : %s after restore" % vm_with_reset.templateid) self.assertNotEqual( self.vm_with_reset.templateid, template.id, "VM created with IsVolatile=True has wrong templateid after restore Got:%s Expected: %s" % (self.vm_with_reset.templateid, template.id)) # Make sure it has the same IP after reboot self.assertEqual( self.vm_with_reset.nic[0].ipaddress, vm_with_reset.nic[0].ipaddress, "VM created with IsVolatile=True doesn't have same ip after restore. Got : %s Expected : %s" % (vm_with_reset.nic[0].ipaddress, self.vm_with_reset.nic[0].ipaddress)) # Check if the the root disk was not destroyed for isVolatile=False self.debug("Checking template id of VM with isVolatile=False") vms = VirtualMachine.list(self.apiclient, id=self.vm_without_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "VM list validation failed due to %s" % vm_list_validation_result[2]) vm_without_reset = vm_list_validation_result[1] self.assertNotEqual( self.vm_without_reset.templateid, vm_without_reset.templateid, "VM created with IsVolatile=False has same templateid : %s after restore" % vm_with_reset.templateid) self.assertNotEqual( self.vm_without_reset.templateid, template.id, "VM created with IsVolatile=False has wrong templateid after restore Got:%s Expected: %s" % (self.vm_without_reset.templateid, template.id)) # Make sure it has the same IP after reboot self.assertEqual( self.vm_without_reset.nic[0].ipaddress, vm_without_reset.nic[0].ipaddress, "VM created with IsVolatile=False doesn't have same ip after restore. Got : %s Expected : %s" % (vm_without_reset.nic[0].ipaddress, self.vm_without_reset.nic[0].ipaddress)) return
def test_3d_gpu_support(self): """ # 1. Register a template for VMware with nicAdapter vmxnet3 and 3D GPU details # 2. Deploy a VM using this template # 3. Create an isolated network # 4. Add network to VM # 5. Verify vm details for 3D GPU details """ if self.hypervisor.lower() not in ["vmware"]: self.skipTest("This test case is written specifically\ for Vmware hypervisor") # Register a private template in the account with nic adapter vmxnet3 # Also add required 3D GPU details for enabling it template = Template.register( self.userapiclient, self.testdata["configurableData"]["vmxnet3template"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, details=[{ "mks.enable3d": "true", "mks.use3dRenderer": "automatic", "svga.autodetect": "false", "svga.vramSize": "131072" }]) self.cleanup.append(template) template.download(self.apiclient) templates = Template.list(self.userapiclient, listall=True, id=template.id, templatefilter="self") self.assertEqual( validateList(templates)[0], PASS, "Templates list validation failed") self.testdata["virtual_machine"]["zoneid"] = self.zone.id self.testdata["virtual_machine"]["template"] = template.id virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, templateid=template.id, serviceofferingid=self.service_offering.id) isolated_network = Network.create( self.apiclient, self.testdata["isolated_network"], self.account.name, self.account.domainid, networkofferingid=self.isolated_network_offering.id) virtual_machine.add_nic(self.apiclient, isolated_network.id) qresultset = self.dbclient.execute( "select id from vm_instance where uuid = '%s';" % virtual_machine.id) vm_id = qresultset[0] qresultset = self.dbclient.execute( "select name, value from user_vm_details where vm_id = '%d';" % vm_id) detailKeys = [x[0] for x in qresultset] self.assertTrue( 'mks.enable3d' in detailKeys and 'mks.use3dRenderer' in detailKeys and 'svga.autodetect' in detailKeys and 'svga.vramSize' in detailKeys, "VM details do not contain 3D GPU details") self.assertEquals('true', qresultset[detailKeys.index('mks.enable3d')][1], "Expected detail 'mks.enable3d'='true'") self.assertEquals('automatic', qresultset[detailKeys.index('mks.use3dRenderer')][1], "Expected detail 'mks.use3dRenderer'='automatic'") self.assertEquals('false', qresultset[detailKeys.index('svga.autodetect')][1], "Expected detail 'svga.autodetect'='false'") self.assertEquals('131072', qresultset[detailKeys.index('svga.vramSize')][1], "Expected detail 'svga.vramSize'='131072'")
def test_01_list_templates_pagination(self): """ @Desc: Test to List Templates pagination @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating (page size + 1) number of Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is (page size + 1) Step6: Listing all the Templates in page1 Step7: Verifying that list size is (page size) Step8: Listing all the Templates in page2 Step9: Verifying that list size is 1 Step10: Listing the template by Id Step11: Verifying if the template is downloaded and ready. If yes the continuing If not waiting and checking for template to be ready till timeout Step12: Deleting the Template present in page 2 Step13: Listing all the Templates in page2 Step14: Verifying that no Templates are listed """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) # Verifying that no Templates are listed self.assertIsNone( list_templates_before, "Templates listed for newly created User" ) self.services["privatetemplate"]["ostype"] = self.services["ostype"] # Creating pagesize + 1 number of Templates for i in range(0, (self.services["pagesize"] + 1)): template_created = Template.register( self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) status = validateList(list_templates_after) self.assertEquals( PASS, status[0], "Templates creation failed" ) # Verifying that list size is pagesize + 1 self.assertEquals( self.services["pagesize"] + 1, len(list_templates_after), "Failed to create pagesize + 1 number of Templates" ) # Listing all the Templates in page 1 list_templates_page1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=1, pagesize=self.services["pagesize"] ) status = validateList(list_templates_page1) self.assertEquals( PASS, status[0], "Failed to list Templates in page 1" ) # Verifying the list size to be equal to pagesize self.assertEquals( self.services["pagesize"], len(list_templates_page1), "Size of Templates in page 1 is not matching" ) # Listing all the Templates in page 2 list_templates_page2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=2, pagesize=self.services["pagesize"] ) status = validateList(list_templates_page2) self.assertEquals( PASS, status[0], "Failed to list Templates in page 2" ) # Verifying the list size to be equal to 1 self.assertEquals( 1, len(list_templates_page2), "Size of Templates in page 2 is not matching" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail("Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Deleting the Template present in page 2 Template.delete( template_created, self.userapiclient ) # Listing all the Templates in page 2 again list_templates_page2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=2, pagesize=self.services["pagesize"] ) # Verifying that there are no Templates listed self.assertIsNone( list_templates_page2, "Templates not deleted from page 2" ) del self.services["privatetemplate"]["ostype"] return
def test_04_copy_template(self, value): """Test copy template between zones Steps and validations: This test requires at least two zones present in the setup 1. Create a root domain/child domain admin account 2. Register and download a template in the account 3. Verify the secondary storage resource count of the account equals the size of the template 4. Copy this template to other zone 5. Verify that the secondary storage resource count is now doubled as there are two templates now in two zones under the admin account """ zones = list_zones(self.apiclient) self.assertEqual(validateList(zones)[0], PASS, "zones list validation faield") if len(zones) < 2: self.skipTest("At least 2 zones should be present for this test case") response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register( self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor, ) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list( self.apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id ) self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed") templateSize = templates[0].size / (1024 ** 3) expectedCount = templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) templateDestinationZoneId = None for zone in zones: if template.zoneid != zone.id: templateDestinationZoneId = zone.id break template.copy(self.apiclient, destzoneid=templateDestinationZoneId, sourcezoneid=template.zoneid) expectedCount = templateSize * 2 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) return
def test_03_edit_template_details(self): """ @Desc: Test to Edit Template name, displaytext, OSType @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating a Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is 1 Step6: Verifying if the template is in ready state. If yes the continuing If not waiting and checking for template to be ready till timeout Step7: Editing the template name Step8: Verifying that Template name is edited Step9: Editing the template displaytext Step10: Verifying that Template displaytext is edited Step11: Editing the template ostypeid Step12: Verifying that Template ostypeid is edited Step13: Editing the template name, displaytext Step14: Verifying that Template name, displaytext are edited Step15: Editing the template name, displaytext, ostypeid Step16: Verifying that Template name, displaytext and ostypeid are edited """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) # Verifying that no Templates are listed self.assertIsNone( list_templates_before, "Templates listed for newly created User" ) self.services["privatetemplate"]["ostype"] = self.services["ostype"] # Creating aTemplate template_created = Template.register( self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) status = validateList(list_templates_after) self.assertEquals( PASS, status[0], "Templates creation failed" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_after), "Failed to create a Template" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail("Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Editing the Template name edited_template = Template.update( template_created, self.userapiclient, name="NewTemplateName" ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": template_created.displaytext, "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template displaytext edited_template = Template.update( template_created, self.userapiclient, displaytext="TemplateDisplaytext" ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template ostypeid ostype_list = list_os_types(self.userapiclient) status = validateList(ostype_list) self.assertEquals( PASS, status[0], "Failed to list OS Types" ) for i in range(0, len(ostype_list)): if ostype_list[i].id != template_created.ostypeid: newostypeid = ostype_list[i].id break edited_template = Template.update( template_created, self.userapiclient, ostypeid=newostypeid ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": newostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template name, displaytext edited_template = Template.update( template_created, self.userapiclient, name=template_created.name, displaytext=template_created.displaytext ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": template_created.name, "displaytest": template_created.displaytext, "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": newostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template name, displaytext, ostypeid edited_template = Template.update( template_created, self.userapiclient, name="NewTemplateName", displaytext="TemplateDisplaytext", ostypeid=template_created.ostypeid ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) del self.services["privatetemplate"]["ostype"] return
def setUpClass(cls): testClient = super(TestXDCCPInterop, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = 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.services['mode'] = cls.zone.networktype hosts = list_hosts(cls.apiclient, type="Routing") if hosts is None: raise unittest.SkipTest( "There are no hypervisor's available.Check list hosts response" ) for hypervisorhost in hosts: if hypervisorhost.hypervisor == "XenServer": cls.uploadtemplateformat = "VHD" break elif hypervisorhost.hypervisor == "VMware": cls.uploadtemplateformat = "OVA" break elif hypervisorhost.hypervisor == "KVM": cls.uploadtemplateformat = "KVM" break if cls.uploadtemplateformat == "KVM": raise unittest.SkipTest("Interop is not supported on KVM") cls.uploadurl = cls.services["interop"][ cls.uploadtemplateformat]["url"] cls.xtemplate = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"]) if cls.xtemplate == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services[ "ostype"] cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id, admin=False) cls.debug(cls.account.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["large"]) cls.template = get_windows_template(cls.apiclient, cls.zone.id, ostype_desc="Windows 8 (64-bit)") #cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows Server 2012 (64-bit)") if cls.template == FAILED: if "http://pleaseupdateURL/" in cls.uploadurl: raise unittest.SkipTest( "Check Test Data file if it has the valid template URL") cls.template = Template.register( cls.apiclient, cls.services["interop"][cls.uploadtemplateformat], zoneid=cls.zone.id, domainid=cls.account.domainid, account=cls.account.name) timeout = cls.services["vgpu"]["timeout"] while True: time.sleep(cls.services["vgpu"]["sleep"]) list_template_response = Template.list( cls.apiclient, templatefilter=cls.services["templatefilter"], id=cls.template.id) if (isinstance(list_template_response, list)) is not True: raise unittest.SkipTest( "Check list template api response returns a valid list" ) if len(list_template_response) is None: raise unittest.SkipTest( "Check template registered is in List Templates") template_response = list_template_response[0] if template_response.isready: break if timeout == 0: raise unittest.SkipTest( "Failed to download template(ID: %s). " % template_response.id) timeout = timeout - 1 cls.volume = [] # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = cls.template.id user_data = ''.join( random.choice(string.ascii_uppercase + string.digits) for x in range(2500)) cls.services["virtual_machine"]["userdata"] = user_data # cls.services["large"]["zoneid"] = cls.zone.id # cls.services["large"]["template"] = cls.template.id cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services['mode'], startvm="false") cls.user_api_client = cls.testClient.getUserApiClient( UserName=cls.account.name, DomainName=cls.account.domain) cls.cleanup = [cls.service_offering, cls.account]
def setUpClass(cls): testClient = super(TestPathVMLC, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.testdata = testClient.getParsedTestDataConfig() cls.hypervisor = testClient.getHypervisorInfo() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient) cls._cleanup = [] try: # Create an account cls.account = Account.create( cls.apiclient, cls.testdata["account"], domainid=cls.domain.id ) cls._cleanup.append(cls.account) # If local storage is enabled, alter the offerings to use # localstorage if cls.zone.localstorageenable: cls.testdata["service_offering"]["storagetype"] = 'local' # Create 3 service offerings with different values for # for cpunumber, cpuspeed, and memory cls.testdata["service_offering"]["cpuspeed"] = 128 cls.testdata["service_offering"]["memory"] = 256 cls.testdata["service_offering"]["cpunumber"] = 1 cls.service_offering_1 = ServiceOffering.create( cls.apiclient, cls.testdata["service_offering"] ) cls._cleanup.append(cls.service_offering_1) cls.testdata["service_offering"]["cpunumber"] = 2 cls.service_offering_2 = ServiceOffering.create( cls.apiclient, cls.testdata["service_offering"] ) cls._cleanup.append(cls.service_offering_2) # Create isolated network offering cls.isolated_network_offering = CreateEnabledNetworkOffering( cls.apiclient, cls.testdata["isolated_network_offering"] ) cls._cleanup.append(cls.isolated_network_offering) # Create shared network offering cls.testdata["shared_network_offering_all_services"][ "specifyVlan"] = "True" cls.testdata["shared_network_offering_all_services"][ "specifyIpRanges"] = "True" cls.shared_network_offering = CreateEnabledNetworkOffering( cls.apiclient, cls.testdata["shared_network_offering_all_services"] ) cls._cleanup.append(cls.shared_network_offering) cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering( cls.apiclient, cls.testdata["nw_offering_isolated_vpc"] ) cls._cleanup.append(cls.isolated_network_offering_vpc) cls.vpc_off = VpcOffering.create(cls.apiclient, cls.testdata["vpc_offering"] ) cls.vpc_off.update(cls.apiclient, state='Enabled') cls._cleanup.append(cls.vpc_off) # This variable will store the id of vpc network whenever # test case creates it # If not created, it will be None and will not be used cls.vpcid = None # Create user api client of the account cls.userapiclient = testClient.getUserApiClient( UserName=cls.account.name, DomainName=cls.account.domain ) # Register a private template in the account builtin_info = get_builtin_template_info(cls.apiclient, cls.zone.id) cls.testdata["privatetemplate"]["url"] = builtin_info[0] cls.testdata["privatetemplate"]["hypervisor"] = builtin_info[1] cls.testdata["privatetemplate"]["format"] = builtin_info[2] # Register new template cls.template = Template.register( cls.userapiclient, cls.testdata["privatetemplate"], zoneid=cls.zone.id, account=cls.account.name, domainid=cls.account.domainid ) # Wait for template to download cls.template.download(cls.apiclient) # Check that we are able to login to the created account respose = User.login( cls.apiclient, username=cls.account.name, password=cls.testdata["account"]["password"] ) assert respose.sessionkey is not None,\ "Login to the CloudStack should be successful\ response shall have non Null key" except Exception as e: cls.tearDownClass() raise e return
def setUpClass(cls): cls.logger = logging.getLogger('TestRedundantIsolateNetworks') cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) cls.testClient = super(TestRedundantIsolateNetworks, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype macchinina = Templates().templates["macchinina"] cls.hypervisor = cls.testClient.getHypervisorInfo() cls.logger.debug("Downloading Template: %s from: %s" % (macchinina[cls.hypervisor.lower()], macchinina[cls.hypervisor.lower()]["url"])) cls.template = Template.register(cls.api_client, macchinina[cls.hypervisor.lower()], cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) cls.template.download(cls.api_client) if cls.template == FAILED: assert False, "get_template() failed to return template" cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id # Create an account, network, VM and IP addresses cls.account = Account.create( cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) cls.services["nw_off_persistent_RVR_egress_true"] = cls.services["nw_off_persistent_RVR"].copy() cls.services["nw_off_persistent_RVR_egress_true"]["egress_policy"] = "true" cls.services["nw_off_persistent_RVR_egress_false"] = cls.services["nw_off_persistent_RVR"].copy() cls.services["nw_off_persistent_RVR_egress_false"]["egress_policy"] = "false" cls.services["egress_80"] = { "startport": 80, "endport": 80, "protocol": "TCP", "cidrlist": ["0.0.0.0/0"] } cls.services["egress_53"] = { "startport": 53, "endport": 53, "protocol": "UDP", "cidrlist": ["0.0.0.0/0"] } cls._cleanup = [ cls.service_offering, cls.account, cls.template ] return