def test_nuage_vsp_device(self): """ Test Nuage VSP device in the Nuage VSP Physical Network """ # 1. Verify that the Nuage VSP network service provider is successfully created and enabled in the Nuage VSP # Physical Network. # 2. Verify that the Nuage VSP device is successfully created in the Nuage VSP Physical Network. # 3. Delete the Nuage VSP device in the Nuage VSP Physical Network, verify that the Nuage VSP device is # successfully deleted in the Nuage VSP Physical Network. # 4. Add the Nuage VSP device in the Nuage VSP Physical Network with invalid VSD credentials, verify that the # Nuage VSP device failed to add in the Nuage VSP Physical Network. # 5. Add the Nuage VSP device in the Nuage VSP Physical Network with valid VSD credentials, verify that the # Nuage VSP device is successfully added in the Nuage VSP Physical Network. # Nuage VSP network service provider validation self.debug("Validating the Nuage VSP network service provider in the Nuage VSP Physical Network...") self.validate_NetworkServiceProvider("NuageVsp", state="Enabled") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP Physical Network...") self.validate_NuageVspDevice() # Nuage VSP device deletion self.debug("Deleting the Nuage VSP device in the Nuage VSP Physical Network...") self.delete_NuageVspDevice() # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("Successfully deleted the Nuage VSP device in the Nuage VSP Physical Network") # Adding the Nuage VSP device with invalid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical Network with invalid VSD credentials...") vsd_info = self.nuage_vsp_device.__dict__ invalid_vsd_info = copy.deepcopy(vsd_info) invalid_vsd_info["password"] = "" with self.assertRaises(Exception): Nuage.add(self.api_client, invalid_vsd_info, self.vsp_physical_network.id) self.debug("Failed to add the Nuage VSP device in the Nuage VSP Physical Network due to invalid VSD " "credentials") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("The Nuage VSP device is not added in the Nuage VSP Physical Network") # Adding the Nuage VSP device with valid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical Network with valid VSD credentials...") Nuage.add(self.api_client, vsd_info, self.vsp_physical_network.id) # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP Physical Network...") self.validate_NuageVspDevice()
def delete_NuageVspDevice(self): """Deletes the Nuage VSP device in the Nuage VSP Physical Network""" self.debug("Deleting the Nuage VSP device in the Nuage VSP Physical " "Network - %s" % self.vsp_physical_network.id) nuage_vsp_device = Nuage.list( self.api_client, physicalnetworkid=self.vsp_physical_network.id)[0] cmd = deleteNuageVspDevice.deleteNuageVspDeviceCmd() cmd.vspdeviceid = nuage_vsp_device.vspdeviceid self.api_client.deleteNuageVspDevice(cmd) self.debug("Successfully deleted the Nuage VSP device in the Nuage " "VSP Physical Network - %s" % self.vsp_physical_network.id)
def validate_NuageVspDevice(self): """Validates the addition of Nuage VSP device in the Nuage VSP Physical Network""" self.debug( "Validating the addition of Nuage VSP device in the Nuage VSP Physical Network - %s" % self.vsp_physical_network.id) nuage_vsp_device = Nuage.list( self.api_client, physicalnetworkid=self.vsp_physical_network.id) self.assertEqual(isinstance(nuage_vsp_device, list), True, "List Nuage VSP device should return a valid list") self.debug( "Successfully validated the addition of Nuage VSP device in the Nuage VSP Physical Network - %s" % self.vsp_physical_network.id)
def validate_NuageVspDevice(self): """Validates the addition of Nuage VSP device in the Nuage VSP Physical Network""" self.debug("Validating the addition of Nuage VSP device in the Nuage VSP Physical Network - %s" % self.vsp_physical_network.id) nuage_vsp_device = Nuage.list(self.api_client, physicalnetworkid=self.vsp_physical_network.id ) self.assertEqual(isinstance(nuage_vsp_device, list), True, "List Nuage VSP device should return a valid list" ) self.debug("Successfully validated the addition of Nuage VSP device in the Nuage VSP Physical Network - %s" % self.vsp_physical_network.id)
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_nuage_vsp_device(self): """ Test Nuage VSP device in the Nuage VSP Physical Network """ # 1. Verify that the Nuage VSP network service provider is successfully created and enabled in the Nuage VSP # Physical Network. # 2. Verify that the Nuage VSP device is successfully created in the Nuage VSP Physical Network. # 3. Delete the Nuage VSP device in the Nuage VSP Physical Network, verify that the Nuage VSP device is # successfully deleted in the Nuage VSP Physical Network. # 4. Add the Nuage VSP device in the Nuage VSP Physical Network with invalid VSD credentials, verify that the # Nuage VSP device failed to add in the Nuage VSP Physical Network. # 5. Add the Nuage VSP device in the Nuage VSP Physical Network with valid VSD credentials, verify that the # Nuage VSP device is successfully added in the Nuage VSP Physical Network. # Nuage VSP network service provider validation self.debug( "Validating the Nuage VSP network service provider in the Nuage VSP Physical Network..." ) self.validate_NetworkServiceProvider("NuageVsp", state="Enabled") # Nuage VSP device validation self.debug( "Validating the Nuage VSP device in the Nuage VSP Physical Network..." ) self.validate_NuageVspDevice() # Nuage VSP device deletion self.debug( "Deleting the Nuage VSP device in the Nuage VSP Physical Network..." ) self.delete_NuageVspDevice() # Nuage VSP device validation self.debug( "Validating the Nuage VSP device in the Nuage VSP Physical Network..." ) with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug( "Successfully deleted the Nuage VSP device in the Nuage VSP Physical Network" ) # Adding the Nuage VSP device with invalid VSD credentials self.debug( "Adding the Nuage VSP device in the Nuage VSP Physical Network with invalid VSD credentials..." ) vsd_info = self.nuage_vsp_device.__dict__ invalid_vsd_info = copy.deepcopy(vsd_info) invalid_vsd_info["password"] = "" with self.assertRaises(Exception): Nuage.add(self.api_client, invalid_vsd_info, self.vsp_physical_network.id) self.debug( "Failed to add the Nuage VSP device in the Nuage VSP Physical Network due to invalid VSD " "credentials") # Nuage VSP device validation self.debug( "Validating the Nuage VSP device in the Nuage VSP Physical Network..." ) with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug( "The Nuage VSP device is not added in the Nuage VSP Physical Network" ) # Adding the Nuage VSP device with valid VSD credentials self.debug( "Adding the Nuage VSP device in the Nuage VSP Physical Network with valid VSD credentials..." ) Nuage.add(self.api_client, vsd_info, self.vsp_physical_network.id) # Nuage VSP device validation self.debug( "Validating the Nuage VSP device in the Nuage VSP Physical Network..." ) self.validate_NuageVspDevice()
def test_nuage_vsp_device(self): """ Test Nuage VSP device in the Nuage VSP Physical Network """ # 1. Verify that the Nuage VSP network service provider is successfully # created and enabled in the Nuage VSP Physical Network. # 2. Verify that the Nuage VSP device is successfully created in the # Nuage VSP Physical Network. # 3. Delete the Nuage VSP device in the Nuage VSP Physical Network, # verify that the Nuage VSP device is successfully deleted in the # Nuage VSP Physical Network. # 4. Add the Nuage VSP device in the Nuage VSP Physical Network with # invalid VSD credentials, verify that the Nuage VSP device failed # to add in the Nuage VSP Physical Network. # 5. Add the Nuage VSP device in the Nuage VSP Physical Network with # valid VSD credentials, verify that the Nuage VSP device is # successfully added in the Nuage VSP Physical Network. for zone in self.zones: self.debug("Zone - %s" % zone.name) # Get Zone details self.getZoneDetails(zone=zone) # Configure VSD sessions self.configureVSDSessions() # Nuage VSP network service provider validation self.debug("Validating the Nuage VSP network service provider in " "the Nuage VSP Physical Network...") self.validate_NetworkServiceProvider("NuageVsp", state="Enabled") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") self.validate_NuageVspDevice() # Nuage VSP device deletion self.debug("Deleting the Nuage VSP device in the Nuage VSP " "Physical Network...") self.delete_NuageVspDevice() # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("Successfully deleted the Nuage VSP device in the " "Nuage VSP Physical Network") # Adding the Nuage VSP device with invalid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical " "Network with invalid VSD credentials...") vsd_info = self.nuage_vsp_device.__dict__ invalid_vsd_info = copy.deepcopy(vsd_info) invalid_vsd_info["password"] = "" with self.assertRaises(Exception): Nuage.add(self.api_client, invalid_vsd_info, self.vsp_physical_network.id) self.debug("Failed to add the Nuage VSP device in the Nuage VSP " "Physical Network due to invalid VSD credentials") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("The Nuage VSP device is not added in the Nuage VSP " "Physical Network") # Adding the Nuage VSP device with valid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical " "Network with valid VSD credentials...") Nuage.add(self.api_client, vsd_info, self.vsp_physical_network.id) # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") self.validate_NuageVspDevice()
def setUpClass(cls): 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) 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: resp = listPhysicalNetworks.listPhysicalNetworksCmd() resp.zoneid = cls.zone.id physical_networks = cls.api_client.listPhysicalNetworks(resp) 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 listConfigurationsCmd = listConfigurations.listConfigurationsCmd() listConfigurationsCmd.name = "nuagevsp.cms.id" listConfigurationsCmd.scopename = "global" cs_config_dict = cls.api_client.listConfigurations( listConfigurationsCmd) cls.cms_id = str(cs_config_dict[0].value).split(":")[1] 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 resp = listHypervisors.listHypervisorsCmd() resp.zoneid = cls.zone.id cls.isSimulator = cls.api_client.listHypervisors( resp)[0].name == 'Simulator' # VSD is a Python SDK for Nuage Vsp 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 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 = 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]")
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]")
def test_nuage_vsp_device(self): """ Test Nuage VSP device in the Nuage VSP Physical Network """ # 1. Verify that the Nuage VSP network service provider is successfully # created and enabled in the Nuage VSP Physical Network. # 2. Verify that the Nuage VSP device is successfully created in the # Nuage VSP Physical Network. # 3. Delete the Nuage VSP device in the Nuage VSP Physical Network, # verify that the Nuage VSP device is successfully deleted in the # Nuage VSP Physical Network. # 4. Add the Nuage VSP device in the Nuage VSP Physical Network with # invalid VSD credentials, verify that the Nuage VSP device failed # to add in the Nuage VSP Physical Network. # 5. Add the Nuage VSP device in the Nuage VSP Physical Network with # valid VSD credentials, verify that the Nuage VSP device is # successfully added in the Nuage VSP Physical Network. for zone in self.zones: self.debug("Zone - %s" % zone.name) # Get Zone details self.getZoneDetails(zone=zone) # Configure VSD sessions self.configureVSDSessions() # Nuage VSP network service provider validation self.debug("Validating the Nuage VSP network service provider in " "the Nuage VSP Physical Network...") self.validate_NetworkServiceProvider("NuageVsp", state="Enabled") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") self.validate_NuageVspDevice() # Nuage VSP device deletion self.debug("Deleting the Nuage VSP device in the Nuage VSP " "Physical Network...") self.delete_NuageVspDevice() # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("Successfully deleted the Nuage VSP device in the " "Nuage VSP Physical Network") # Adding the Nuage VSP device with invalid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical " "Network with invalid VSD credentials...") vsd_info = self.nuage_vsp_device.__dict__ invalid_vsd_info = copy.deepcopy(vsd_info) invalid_vsd_info["password"] = "" with self.assertRaises(Exception): Nuage.add( self.api_client, invalid_vsd_info, self.vsp_physical_network.id) self.debug("Failed to add the Nuage VSP device in the Nuage VSP " "Physical Network due to invalid VSD credentials") # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") with self.assertRaises(Exception): self.validate_NuageVspDevice() self.debug("The Nuage VSP device is not added in the Nuage VSP " "Physical Network") # Adding the Nuage VSP device with valid VSD credentials self.debug("Adding the Nuage VSP device in the Nuage VSP Physical " "Network with valid VSD credentials...") Nuage.add(self.api_client, vsd_info, self.vsp_physical_network.id) # Nuage VSP device validation self.debug("Validating the Nuage VSP device in the Nuage VSP " "Physical Network...") self.validate_NuageVspDevice()
def setUpClass(cls): 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) 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: resp = listPhysicalNetworks.listPhysicalNetworksCmd() resp.zoneid = cls.zone.id physical_networks = cls.api_client.listPhysicalNetworks(resp) 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 listConfigurationsCmd = listConfigurations.listConfigurationsCmd() listConfigurationsCmd.name = "nuagevsp.cms.id" listConfigurationsCmd.scopename = "global" cs_config_dict = cls.api_client.listConfigurations(listConfigurationsCmd) cls.cms_id = str(cs_config_dict[0].value).split(":")[1] 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 resp = listHypervisors.listHypervisorsCmd() resp.zoneid = cls.zone.id cls.isSimulator = cls.api_client.listHypervisors(resp)[0].name == 'Simulator' # VSD is a Python SDK for Nuage Vsp 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 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 = 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]")