def getZoneDetails(cls, zone=None): # Get Zone, Domain and templates cls.zone = zone if zone else get_zone( cls.api_client, zone_name=cls.test_client.getZoneForTests() ) cls.domain = get_domain(cls.api_client) cls.template = get_template(cls.api_client, cls.zone.id, cls.test_data["ostype"] ) cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id cls.test_data["virtual_machine"]["template"] = cls.template.id # Check if the host hypervisor type is simulator hypervisors = Hypervisor.list(cls.api_client, zoneid=cls.zone.id) assert hypervisors is not None and len(hypervisors) > 0, \ "Expected at least one hypervisor" cls.isSimulator = any(map(lambda h: h.name == "Simulator", hypervisors)) # Get configured Nuage VSP device details try: physical_networks = PhysicalNetwork.list( cls.api_client, zoneid=cls.zone.id ) cls.vsp_physical_network = next(pn for pn in physical_networks if pn.isolationmethods == "VSP") cls.nuage_vsp_device = Nuage.list( cls.api_client, physicalnetworkid=cls.vsp_physical_network.id)[0] # Take username and password from the datacenter config file, # as they are not returned by the API. config_nuage_device = next(device for zone in cls.config.zones if zone.name == cls.zone.name for physnet in zone.physical_networks if "VSP" in physnet.isolationmethods for provider in physnet.providers if provider.name == "NuageVsp" for device in provider.devices) cls.nuage_vsp_device.username = config_nuage_device.username cls.nuage_vsp_device.password = config_nuage_device.password cls.cms_id = cls.nuage_vsp_device.cmsid except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Warning: Could not get configured " "Nuage VSP device details - %s" % e) 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, zone=None): cls.debug("setUpClass nuageTestCase") # We want to fail quicker, if it's a failure socket.setdefaulttimeout(60) test_client = super(nuageTestCase, cls).getClsTestClient() cls.api_client = test_client.getApiClient() cls.db_client = test_client.getDbConnection() cls.test_data = test_client.getParsedTestDataConfig() # Get Zone, Domain and templates cls.zone = get_zone(cls.api_client, zone_name=zone.name if zone else None, zone_id=zone.id if zone else None) cls.domain = get_domain(cls.api_client) cls.template = get_template(cls.api_client, cls.zone.id, cls.test_data["ostype"]) cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id cls.test_data["virtual_machine"]["template"] = cls.template.id # Create service offering cls.service_offering = ServiceOffering.create( cls.api_client, cls.test_data["service_offering"]) cls._cleanup = [cls.service_offering] # Check if the host hypervisor type is simulator cls.isSimulator = Hypervisor.list( cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator" # Get configured Nuage VSP device details try: physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id) for pn in physical_networks: if pn.isolationmethods == "VSP": cls.vsp_physical_network = pn break cls.nuage_vsp_device = Nuage.list( cls.api_client, physicalnetworkid=cls.vsp_physical_network.id)[0] pns = cls.config.zones[0].physical_networks providers = filter( lambda physical_network: "VSP" in physical_network. isolationmethods, pns)[0].providers devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices cls.nuage_vsp_device.username = devices[0].username cls.nuage_vsp_device.password = devices[0].password cls.cms_id = cls.nuage_vsp_device.cmsid except Exception as e: cls.tearDownClass() raise unittest.SkipTest( "Warning: Could not get configured Nuage VSP device details - %s" % e) # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform # vspk is a Python SDK for Nuage VSP's VSD # libVSD is a library that wraps vspk package try: vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion cls.vsdk = importlib.import_module(vspk_module) from libVSD import ApiClient, VSDHelpers except Exception as e: cls.tearDownClass() raise unittest.SkipTest( "Warning: vspk (and/or) libVSD package import failure - %s" % e) # Configure VSD session cls._session = cls.vsdk.NUVSDSession( username=cls.nuage_vsp_device.username, password=cls.nuage_vsp_device.password, enterprise="csp", api_url="https://%s:%d" % (cls.nuage_vsp_device.hostname, cls.nuage_vsp_device.port)) cls._session.start() # Configure libVSD session root = logging.getLogger() log_handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') log_handler.setFormatter(formatter) root.addHandler(log_handler) vsd_info = cls.nuage_vsp_device.__dict__ cls.debug("Nuage VSP device (VSD) details - %s" % vsd_info) vsd_api_client = ApiClient(address=vsd_info["hostname"], user=vsd_info["username"], password=vsd_info["password"], version=vsd_info["apiversion"][1] + "." + vsd_info["apiversion"][3]) vsd_api_client.new_session() cls.vsd = VSDHelpers(vsd_api_client) cls.debug("setUpClass nuageTestCase [DONE]")
def setUpClass(cls, zone=None): cls.debug("setUpClass nuageTestCase") # We want to fail quicker, if it's a failure socket.setdefaulttimeout(60) test_client = super(nuageTestCase, cls).getClsTestClient() cls.api_client = test_client.getApiClient() cls.db_client = test_client.getDbConnection() cls.test_data = test_client.getParsedTestDataConfig() # Get Zone, Domain and templates cls.zone = get_zone(cls.api_client, zone_name=zone.name if zone else None, zone_id=zone.id if zone else None ) cls.domain = get_domain(cls.api_client) cls.template = get_template(cls.api_client, cls.zone.id, cls.test_data["ostype"] ) cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id cls.test_data["virtual_machine"]["template"] = cls.template.id # Create service offering cls.service_offering = ServiceOffering.create(cls.api_client, cls.test_data["service_offering"] ) cls._cleanup = [cls.service_offering] # Get configured Nuage VSP device details try: physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id) for pn in physical_networks: if pn.isolationmethods == "VSP": cls.vsp_physical_network = pn break cls.nuage_vsp_device = Nuage.list(cls.api_client, physicalnetworkid=cls.vsp_physical_network.id )[0] pns = cls.config.zones[0].physical_networks providers = filter(lambda physical_network: "VSP" in physical_network.isolationmethods, pns)[0].providers devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices cls.nuage_vsp_device.username = devices[0].username cls.nuage_vsp_device.password = devices[0].password cls.cms_id = cls.nuage_vsp_device.cmsid except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Warning: Couldn't get configured Nuage VSP device details: %s" % e) # Check if the host hypervisor type is simulator cls.isSimulator = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator" # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform # vspk is a Python SDK for Nuage VSP's VSD # cms_vspk_wrapper is a library that wraps vspk package try: vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion cls.vsdk = importlib.import_module(vspk_module) vspk_utils_module = "vspk.utils" if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion + ".utils" vsdk_utils = importlib.import_module(vspk_utils_module) set_log_level = getattr(vsdk_utils, "set_log_level") from cms_vspk_wrapper.cms_vspk_wrapper import Cms_vspk_wrapper except: raise unittest.SkipTest("vspk (and/or) cms_vspk_wrapper import failure") # Configure VSD session cls._session = cls.vsdk.NUVSDSession(username=cls.nuage_vsp_device.username, password=cls.nuage_vsp_device.password, enterprise="csp", api_url="https://%s:%d" % (cls.nuage_vsp_device.hostname, cls.nuage_vsp_device.port) ) cls._session.start() # Configure cms_vspk_wrapper session cls.log_handler = logging.getLogger("CSLog").handlers[0] vsd_info = cls.nuage_vsp_device.__dict__ vsd_info["port"] = str(vsd_info["port"]) cls.vsd = Cms_vspk_wrapper(vsd_info, cls.log_handler) set_log_level(logging.INFO) cls.debug("setUpClass nuageTestCase [DONE]")
def setUpClass(cls, zone=None): cls.debug("setUpClass nuageTestCase") # We want to fail quicker, if it's a failure socket.setdefaulttimeout(60) test_client = super(nuageTestCase, cls).getClsTestClient() cls.api_client = test_client.getApiClient() cls.db_client = test_client.getDbConnection() cls.test_data = test_client.getParsedTestDataConfig() # Get Zone, Domain and templates cls.zone = get_zone(cls.api_client, zone_name=zone.name if zone else None, zone_id=zone.id if zone else None ) cls.domain = get_domain(cls.api_client) cls.template = get_template(cls.api_client, cls.zone.id, cls.test_data["ostype"] ) cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id cls.test_data["virtual_machine"]["template"] = cls.template.id # Create service offering cls.service_offering = ServiceOffering.create(cls.api_client, cls.test_data["service_offering"] ) cls._cleanup = [cls.service_offering] # Check if the host hypervisor type is simulator cls.isSimulator = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator" # Get configured Nuage VSP device details try: physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id) for pn in physical_networks: if pn.isolationmethods == "VSP": cls.vsp_physical_network = pn break cls.nuage_vsp_device = Nuage.list(cls.api_client, physicalnetworkid=cls.vsp_physical_network.id )[0] pns = cls.config.zones[0].physical_networks providers = filter(lambda physical_network: "VSP" in physical_network.isolationmethods, pns)[0].providers devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices cls.nuage_vsp_device.username = devices[0].username cls.nuage_vsp_device.password = devices[0].password cls.cms_id = cls.nuage_vsp_device.cmsid except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Warning: Could not get configured Nuage VSP device details - %s" % e) # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform # vspk is a Python SDK for Nuage VSP's VSD # libVSD is a library that wraps vspk package try: vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion cls.vsdk = importlib.import_module(vspk_module) from libVSD import ApiClient, VSDHelpers except Exception as e: cls.tearDownClass() raise unittest.SkipTest("Warning: vspk (and/or) libVSD package import failure - %s" % e) # Configure VSD session cls._session = cls.vsdk.NUVSDSession(username=cls.nuage_vsp_device.username, password=cls.nuage_vsp_device.password, enterprise="csp", api_url="https://%s:%d" % (cls.nuage_vsp_device.hostname, cls.nuage_vsp_device.port) ) cls._session.start() # Configure libVSD session root = logging.getLogger() log_handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') log_handler.setFormatter(formatter) root.addHandler(log_handler) vsd_info = cls.nuage_vsp_device.__dict__ cls.debug("Nuage VSP device (VSD) details - %s" % vsd_info) vsd_api_client = ApiClient(address=vsd_info["hostname"], user=vsd_info["username"], password=vsd_info["password"], version=vsd_info["apiversion"][1] + "." + vsd_info["apiversion"][3] ) vsd_api_client.new_session() cls.vsd = VSDHelpers(vsd_api_client) cls.debug("setUpClass nuageTestCase [DONE]")