def setUpClass(cls): testClient = super(TestISO, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() cls._cleanup = [] cls.unsupportedHypervisor = False cls.hypervisor = get_hypervisor_type(cls.apiclient) if cls.hypervisor.lower() in ["simulator", "lxc"]: cls.unsupportedHypervisor = True return # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services["domainid"] = cls.domain.id cls.services["iso1"]["zoneid"] = cls.zone.id cls.services["iso2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id # populate second zone id for iso copy cmd = listZones.listZonesCmd() cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") # Create an account, ISOs etc. cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls._cleanup.append(cls.account) # Finding the OsTypeId from Ostype ostypes = list_os_types(cls.apiclient, description=cls.services["ostype"]) if not isinstance(ostypes, list): raise unittest.SkipTest("OSTypeId for given description not found") cls.services["iso1"]["ostypeid"] = ostypes[0].id cls.services["iso2"]["ostypeid"] = ostypes[0].id cls.services["ostypeid"] = ostypes[0].id cls.iso_1 = Iso.create(cls.apiclient, cls.services["iso1"], account=cls.account.name, domainid=cls.account.domainid) try: cls.iso_1.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s" % (cls.iso_1.id, e)) cls.iso_2 = Iso.create(cls.apiclient, cls.services["iso2"], account=cls.account.name, domainid=cls.account.domainid) try: cls.iso_2.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s" % (cls.iso_2.id, e)) return
def list(self, **kwargs): """:rtype: collections.Sequence[Zone]""" cmd = listZonesCmd() copy_to_object(cmd, kwargs) results = self.api_client().listZones(cmd) if results is None: return [] return list([new_object(Zone, a, set_all=True) for a in results])
def setUpClass(cls): testClient = super(TestSetupSuccess, cls).getClsTestClient() cls.apiClient = testClient.getApiClient() cls.hypervisor = testClient.getHypervisorInfo() zones = listZones.listZonesCmd() cls.zones_list = cls.apiClient.listZones(zones) cls.retry = 50
def list_zones(apiclient, **kwargs): """List all Zones matching criteria""" cmd = listZones.listZonesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] if "account" in kwargs.keys() and "domainid" in kwargs.keys(): cmd.listall = True return apiclient.listZones(cmd)
def list_zones(api_client, **kwargs): """List all Zones matching criteria""" cmd = listZones.listZonesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] if 'account' in kwargs.keys() and 'domainid' in kwargs.keys(): cmd.listall = True return api_client.listZones(cmd)
def delete_all(self, *args): """:type *args: list[Zone]""" cmd = listZonesCmd() cmd.listall = True results = self.api_client().listZones(cmd) for zone in args: for result in results: if zone.name == result.name: self.delete(result)
def get_zone(apiclient, services=None): "Returns a default zone" cmd = listZones.listZonesCmd() if services: if "zoneid" in services: cmd.id = services["zoneid"] zones = apiclient.listZones(cmd) if isinstance(zones, list): assert len(zones) > 0, "There are no available zones in the deployment" return zones[0] else: raise Exception("Failed to find specified zone.")
def get_zone(apiclient, zone_name=None, zone_id=None): """ @name : get_zone @Desc :Returns the Zone Information for a given zone id or Zone Name @Input : zone_name: Name of the Zone zone_id : Id of the zone @Output : 1. Zone Information for the passed inputs else first zone 2. FAILED In case the cmd failed """ cmd = listZones.listZonesCmd() if zone_name is not None: cmd.name = zone_name if zone_id is not None: cmd.id = zone_id cmd_out = apiclient.listZones(cmd) if validateList(cmd_out)[0] != PASS: return FAILED """ Check if input zone name and zone id is None, then return first element of List Zones command """ return cmd_out[0]
def get_zone(api_client, zone_name=None, zone_id=None): """ @name : get_zone @Desc :Returns the Zone Information for a given zone id or Zone Name @Input : zone_name: Name of the Zone zone_id : Id of the zone @Output : 1. Zone Information for the passed inputs else first zone 2. FAILED In case the cmd failed """ cmd = listZones.listZonesCmd() if zone_name is not None: cmd.name = zone_name if zone_id is not None: cmd.id = zone_id cmd_out = api_client.listZones(cmd) if validate_list(cmd_out)[0] != PASS: return FAILED ''' Check if input zone name and zone id is None, then return first element of List Zones command ''' return cmd_out[0]
def setUpClass(cls): testClient = super(TestTemplates, 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, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cmd = listZones.listZonesCmd() cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") cls.disk_offering = DiskOffering.create(cls.apiclient, cls.services["disk_offering"]) template = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"]) if template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services[ "ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["zoneid"] = cls.zone.id cls.services["template_2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid print "Before:", cls.services cls.account = Account.create(cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id) print "After:", cls.services cls.user = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"]) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) list_volume = Volume.list(cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True) try: cls.volume = list_volume[0] except Exception as e: raise Exception( "Exception: Unable to find root volume foe VM: %s - %s" % (cls.virtual_machine.id, e)) #Create templates for Edit, Delete & update permissions testcases cls.template_1 = Template.create(cls.apiclient, cls.services["template"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid) cls.template_2 = Template.create(cls.apiclient, cls.services["template_2"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid) cls._cleanup = [ cls.service_offering, cls.disk_offering, cls.account, cls.user ]
def setUpClass(cls): cls.testClient = super(TestTemplates, 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.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cmd = listZones.listZonesCmd() zones = cls.api_client.listZones(cmd) if not isinstance(zones, list): raise Exception("Failed to find zones.") if len(zones) >= 2: cls.services["destzoneid"] = zones[1].id template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls._cleanup = [] try: cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"]) cls._cleanup.append(cls.service_offering) # create virtual machine cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, ) #Stop virtual machine cls.virtual_machine.stop(cls.api_client) timeout = cls.services["timeout"] while True: list_volume = Volume.list( cls.api_client, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True) if isinstance(list_volume, list): break elif timeout == 0: raise Exception("List volumes failed.") time.sleep(5) timeout = timeout - 1 cls.volume = list_volume[0] #Create template from volume cls.template = Template.create(cls.api_client, cls.services["template"], cls.volume.id) except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Failure in setUpClass: %s" % e)
def setUpClass(cls): testClient = super(TestTemplates, 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, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cmd = listZones.listZonesCmd() cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") cls.disk_offering = DiskOffering.create( cls.apiclient, cls.services["disk_offering"] ) template = get_template( cls.apiclient, cls.zone.id, cls.services["ostype"] ) if template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["zoneid"] = cls.zone.id cls.services["template_2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid print "Before:",cls.services cls.account = Account.create( cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) print "After:",cls.services cls.user = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"] ) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) list_volume = Volume.list( cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True ) try: cls.volume = list_volume[0] except Exception as e: raise Exception( "Exception: Unable to find root volume foe VM: %s - %s" % (cls.virtual_machine.id, e)) #Create templates for Edit, Delete & update permissions testcases cls.template_1 = Template.create( cls.apiclient, cls.services["template"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid ) cls.template_2 = Template.create( cls.apiclient, cls.services["template_2"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid ) cls._cleanup = [ cls.service_offering, cls.disk_offering, cls.account, cls.user ]
def setUpClass(cls): cls.testClient = super(TestTemplates, 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.services['mode'] = cls.zone.networktype cls._cleanup = [] cls.unsupportedHypervisor = False cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in ['lxc']: cls.unsupportedHypervisor = True return # populate second zone id for iso copy cmd = listZones.listZonesCmd() zones = cls.api_client.listZones(cmd) if not isinstance(zones, list): raise Exception("Failed to find zones.") if len(zones) >= 2: cls.services["destzoneid"] = zones[1].id template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) cls.services["virtual_machine"]["zoneid"] = cls.zone.id try: cls.account = Account.create( cls.api_client, cls.services["account"], domainid=cls.domain.id ) cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) cls._cleanup.append(cls.service_offering) # create virtual machine cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, ) # Stop virtual machine cls.virtual_machine.stop(cls.api_client) timeout = cls.services["timeout"] while True: list_volume = Volume.list( cls.api_client, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True) if isinstance(list_volume, list): break elif timeout == 0: raise Exception("List volumes failed.") time.sleep(5) timeout = timeout - 1 cls.volume = list_volume[0] # Create template from volume cls.template = Template.create( cls.api_client, cls.services["template"], cls.volume.id ) except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Failure in setUpClass: %s" % e)
def test_09_copy_delete_template(self): cmd = listZones.listZonesCmd() zones = self.apiclient.listZones(cmd) if not isinstance(zones, list): raise Exception("Failed to find zones.") if len(zones) < 2: self.skipTest( "Skipping test due to there are less than two zones.") return self.sourceZone = zones[0] self.destZone = zones[1] template = Template.create(self.apiclient, self.services["template"], self.volume.id, account=self.account.name, domainid=self.account.domainid) self.cleanup.append(template) self.debug("Created template with ID: %s" % template.id) list_template_response = Template.list( self.apiclient, templatefilter=\ self.services["templatefilter"], id=template.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") #Copy template from zone1 to zone2 copytemplate = Template.copy(cls.apiclient, zoneid=cls.sourceZone.id, destzoneid=cls.destZone.id) cls._cleanup.append(cls.copytemplate) list_template_response = Template.list( self.apiclient, templatefilter=self.services["template"]["templatefilter"], id=self.template.id, zoneid=self.destZone.id) self.assertEqual(list_template_response, None, "Check template available in List Templates") self.deltemplate = list_template_response[0] self.debug("Deleting template: %s" % self.deltemplate) # Delete the template self.deltemplate.delete(self.apiclient) self.debug("Delete template: %s successful" % self.deltemplate) copytemplate = Template.copy(self.apiclient, zoneid=self.sourceZone.id, destzoneid=self.destZone.id) removed = cls.dbclient.execute( "select removed from template_zone_ref where zone_id='%s' and template_id='%s';" % self.destZone.id, self.template.id) self.assertEqual(removed, NULL, "Removed state is not correct.") return
def setUpClass(cls): testClient = super(TestISO, 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, cls.testClient.getZoneForTests()) cls.services["domainid"] = cls.domain.id cls.services["iso1"]["zoneid"] = cls.zone.id cls.services["iso2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id # populate second zone id for iso copy cmd = listZones.listZonesCmd() cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") # Create an account, ISOs etc. cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) # Finding the OsTypeId from Ostype ostypes = list_os_types( cls.apiclient, description=cls.services["ostype"] ) if not isinstance(ostypes, list): raise unittest.SkipTest("OSTypeId for given description not found") cls.services["iso1"]["ostypeid"] = ostypes[0].id cls.services["iso2"]["ostypeid"] = ostypes[0].id cls.services["ostypeid"] = ostypes[0].id cls.iso_1 = Iso.create( cls.apiclient, cls.services["iso1"], account=cls.account.name, domainid=cls.account.domainid ) try: cls.iso_1.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s" % (cls.iso_1.id, e)) cls.iso_2 = Iso.create( cls.apiclient, cls.services["iso2"], account=cls.account.name, domainid=cls.account.domainid ) try: cls.iso_2.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s" % (cls.iso_2.id, e)) cls._cleanup = [cls.account] return
def list_zones(apiclient, **kwargs): """List all Zones matching criteria""" cmd = listZones.listZonesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listZones(cmd))
def list_zones(apiclient, **kwargs): """List all Zones matching criteria""" cmd = listZones.listZonesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return (apiclient.listZones(cmd))
def test_09_copy_delete_template(self): cmd = listZones.listZonesCmd() zones = self.apiclient.listZones(cmd) if not isinstance(zones, list): raise Exception("Failed to find zones.") if len(zones) < 2: self.skipTest( "Skipping test due to there are less than two zones.") return self.sourceZone = zones[0] self.destZone = zones[1] template = Template.create( self.apiclient, self.services["template"], self.volume.id, account=self.account.name, domainid=self.account.domainid ) self.cleanup.append(template) self.debug("Created template with ID: %s" % template.id) list_template_response = Template.list( self.apiclient, templatefilter=\ self.services["templatefilter"], id=template.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" ) #Copy template from zone1 to zone2 copytemplate = Template.copy( cls.apiclient, zoneid=cls.sourceZone.id, destzoneid = cls.destZone.id ) cls._cleanup.append(cls.copytemplate) list_template_response = Template.list( self.apiclient, templatefilter=self.services["template"]["templatefilter"], id=self.template.id, zoneid=self.destZone.id ) self.assertEqual( list_template_response, None, "Check template available in List Templates" ) self.deltemplate = list_template_response[0] self.debug("Deleting template: %s" % self.deltemplate) # Delete the template self.deltemplate.delete(self.apiclient) self.debug("Delete template: %s successful" % self.deltemplate) copytemplate = Template.copy( self.apiclient, zoneid=self.sourceZone.id, destzoneid = self.destZone.id ) removed = cls.dbclient.execute("select removed from template_zone_ref where zone_id='%s' and template_id='%s';" % self.destZone.id, self.template.id) self.assertEqual( removed, NULL, "Removed state is not correct." ) return