def __init__(self, proxy, LOGGER): # Logger # pylint: disable=no-member requests.packages.urllib3.disable_warnings() self.aai_url = onap_test_utils.get_config("onap.aai.url") self.aai_headers = onap_test_utils.get_config("onap.aai.headers") self.proxy = proxy self.logger = LOGGER
def __init__(self, proxy, LOGGER, disableRollback=False): # Logger # pylint: disable=no-member requests.packages.urllib3.disable_warnings() self.so_url = onap_test_utils.get_config("onap.so.url") self.so_headers = onap_test_utils.get_config("onap.so.headers") self.proxy = proxy self.logger = LOGGER self.disableRollback = disableRollback
def __init__(self, proxy, LOGGER): # Logger # pylint: disable=no-member requests.packages.urllib3.disable_warnings() self.nbi_url = onap_test_utils.get_config("onap.nbi.url") self.nbi_headers = onap_test_utils.get_config("onap.nbi.headers") self.proxy = proxy self.logger = LOGGER self.name = "" self.customer = "generic" self.external_id = "" self.service_id = ""
class AaiTestingBase(unittest.TestCase): _LOGGER = onap_test_utils.get_logger("unit_tests") _PROXY = onap_test_utils.get_config("general.proxy") _AAI_URL = onap_test_utils.get_config("onap.aai.url") _AAI_HEADERS = onap_test_utils.get_config("onap.aai.headers") def setUp(self): self.my_aai = aai.Aai(proxy=self._PROXY, LOGGER=self._LOGGER) @requests_mock.mock() def test_check_services(self, m): url = self._AAI_URL + "/aai/v11/service-design-and-creation/services" m.get(url, text='a response') self.assertEqual(self.my_aai.check_sercices(), 'a response')
def check_service_instance(self, service_description, service_instance_id): """ Check that a given service instance is created send request, wait, check max nb_try_max times """ url = (self.aai_url + "/aai/v11/business/customers/customer/" + onap_test_utils.get_config("onap.customer") + "/service-subscriptions/service-subscription/" + service_description + "/service-instances/") try: service_instance_found = False nb_try = 0 nb_try_max = 5 while service_instance_found is False and nb_try < nb_try_max: response = requests.get(url, headers=self.aai_headers, proxies=self.proxy, verify=False) self.logger.info("AAI: looking for %s service instance....", service_instance_id) if service_instance_id in response.text: self.logger.info("Service instance %s found in AAI", service_instance_id) service_instance_found = True time.sleep(10) nb_try += 1 except Exception as err: # pylint: disable=broad-except self.logger.error("impossible to perform the request on AAI: %s", str(err)) if service_instance_found is False: self.logger.info("Service instance not found") return service_instance_found
def set_module_var(self): """ set module variables from the config file """ self.vnf_config["sdnc_vnf_type"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + self.vnf_config["vnf_type"] + ".metadata.vfModuleModelName") vnf_param = self.vnf_config["vnf"] + ".vnf_parameters" self.vnf_config["vnf_parameters"] = onap_utils.get_config(vnf_param) self.vnf_config["module_invariant_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + self.vnf_config["vnf_type"] + ".metadata.vfModuleModelInvariantUUID") self.vnf_config["module_name_version_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + self.vnf_config["vnf_type"] + ".metadata.vfModuleModelUUID")) self.vnf_config["module_customization_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + self.vnf_config["vnf_type"] + ".metadata.vfModuleModelCustomizationUUID")) self.vnf_config["module_version_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + self.vnf_config["vnf_type"] + ".metadata.vfModuleModelUUID")
def __init__(self, **kwargs): """Initialize Vnf object.""" super(Vnf, self).__init__() self.vnf_config = {} if "case" not in kwargs: # by convention is VNF is not precised we set mrf kwargs["case"] = "mrf" self.vnf_config["vnf"] = kwargs["case"] # can be useful to destroy resources, sdnc module name shall be given if "sdnc_vnf_name" in kwargs: self.vnf_config["sdnc_vnf_name"] = kwargs["sdnc_vnf_name"] # Random part = 6 last char of the the vnf name self.vnf_config["random_string"] = kwargs["sdnc_vnf_name"][-6:] else: self.vnf_config["random_string"] = ( onap_utils.random_string_generator()) self.vnf_config["sdnc_vnf_name"] = ( onap_utils.get_config("onap.service.name") + "_" + kwargs["case"] + "_" + self.vnf_config["random_string"]) self.set_service_instance_var() self.set_vnf_var() self.set_module_var() self.set_onap_components()
def get_subscriber_info(cls): """ Get Subscriber Info """ subscriber_id = onap_test_utils.get_config("onap.customer") return { "globalSubscriberId": subscriber_id }
def get_cloud_config(cls): """ Get Cloud configuration """ tenant_id = onap_test_utils.get_config("openstack.tenant_id") return { "lcpCloudRegionId": "RegionOne", "tenantId": tenant_id }
def get_request_param(cls, vnf, alacarte=False, subscription=False): """ Get Request parameters """ subscription_type = onap_test_utils.get_config(vnf + ".subscription_type") request_params = { "userParams": [], "cascadeDelete": True, } if subscription: request_params.update( {"subscriptionServiceType": subscription_type}) if alacarte: request_params.update({"aLaCarte": True}) return request_params
def get_service_instance(self, service_subscription, service_name): """ Get the context of the existing service (from which we will extract ids and instantiated VNFs) returns None if not found, {} on error """ res = None url = (self.aai_url + "/aai/v11/business/customers/customer/" + onap_test_utils.get_config("onap.customer") + "/service-subscriptions/service-subscription/" + service_subscription + "/service-instances/") try: service_instance_found = False response = requests.get(url, headers=self.aai_headers, proxies=self.proxy, verify=False) self.logger.debug("AAI: looking for %s service instance....", service_name) rsp_json = response.json() self.logger.debug("Json=%s", rsp_json) if "service-instance" in rsp_json: # Parse all services instances of the customer for svc in rsp_json["service-instance"]: # targeted service found if service_name in svc["service-instance-name"]: self.logger.info("Service instance %s found in AAI", service_name) res = svc service_instance_found = True break else: self.logger.debug("Svc %s ignored", svc["service-instance-name"]) except Exception as err: # pylint: disable=broad-except self.logger.error("impossible to perform the request on AAI: %s", str(err)) # to distinguish, not found service from exception, we send an empty dict on error res = {} if service_instance_found is False: self.logger.info("Service instance not found") return res
def __init__(self, **kwargs): """Initialize Solution object.""" super(Solution, self).__init__() self.vnf_config = {} self.components = {} if "case" not in kwargs: # by convention is VNF is not precised we set mrf kwargs["case"] = "mrf" self.vnf_config["vnf"] = kwargs["case"] if "nbi" in kwargs: self.vnf_config["nbi"] = kwargs["nbi"] # can be useful to destroy resources, sdnc module name shall be given if "sdnc_vnf_name" in kwargs: self.vnf_config["sdnc_vnf_name"] = kwargs["sdnc_vnf_name"] # Random part = 6 last char of the the vnf name self.vnf_config["random_string"] = kwargs["sdnc_vnf_name"][-6:] else: self.vnf_config["random_string"] = ( onap_utils.random_string_generator()) self.vnf_config["sdnc_vnf_name"] = ( onap_utils.get_config("onap.service.name") + "_" + kwargs["case"] + "_" + self.vnf_config["random_string"]) vnf_list = list( onap_utils.get_template_param(self.vnf_config["vnf"], "topology_template.node_templates")) vf_module_list = list( onap_utils.get_template_param(self.vnf_config["vnf"], "topology_template.groups")) # Class attributes for instance, vnf and module VF self.service_infos = {} self.vnf_infos = {'list': vnf_list} self.module_infos = {'list': vf_module_list} # retrieve infos from the configuration files self.set_service_instance_var() self.set_vnf_var() self.set_module_var() self.set_onap_components()
def set_service_instance_var(self): """ set service instance variables from the config file Fix: Service version is not in the Tosca but in the Instantiation input file """ self.vnf_config["vnf_name"] = onap_utils.get_template_param( self.vnf_config["vnf"], "metadata.name") self.vnf_config["invariant_uuid"] = onap_utils.get_template_param( self.vnf_config["vnf"], "metadata.invariantUUID") self.vnf_config["uuid"] = onap_utils.get_template_param( self.vnf_config["vnf"], "metadata.UUID") # Catch exception For backward compatibility with previous file format that does not contain any service_version try: self.vnf_config["version"] = onap_utils.get_config( self.vnf_config["vnf"] + ".service_version") except ValueError: # the default hardcoded version self.vnf_config["version"] = "1.0" self.__logger.info( "No service_version in config file, using default %s", self.vnf_config["version"])
def set_module_var(self): """ set module variables from the config file """ for elt in self.vnf_infos['list']: vf_config = {} # we cannot be sure that the modules are in teh same order # than the vnf vf_index = onap_utils.get_vf_module_index( self.module_infos['list'], elt) vnf_type = list( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups"))[vf_index] self.__logger.info("Complete Module info for VNF %s", elt) vf_config["sdnc_vnf_type"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelName") vnf_param = (self.vnf_config["vnf"] + "." + str(elt) + ".vnf_parameters") vf_config["vnf_parameters"] = onap_utils.get_config(vnf_param) vf_config["module_invariant_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelInvariantUUID") vf_config["module_name_version_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelUUID")) vf_config["module_customization_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelCustomizationUUID")) vf_config["module_version_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelUUID") self.vnf_config[elt].update(vf_config)
def check_service_instance_cleaned(self, service_description, service_instance_id): """ Check if the Service instance has been cleaned in the AAI return True if it has been clean_preload return False elsewhere """ # url2 = self.aai_url + "/aai/v11/service-design-and-creation/services" # url1 = self.aai_url + "/aai/v11/business/customers" url = (self.aai_url + "/aai/v11/business/customers/customer/" + onap_test_utils.get_config("onap.customer") + "/service-subscriptions/service-subscription/" + service_description + "/service-instances/") try: service_instance_found = True nb_try = 0 nb_try_max = 5 while service_instance_found is True and nb_try < nb_try_max: response = requests.get(url, headers=self.aai_headers, proxies=self.proxy, verify=False) self.logger.info("AAI: Has %s service instance been cleaned..", service_instance_id) if service_instance_id not in response.text: self.logger.info("Service instance %s cleaned in AAI", service_instance_id) service_instance_found = False time.sleep(10) nb_try += 1 except Exception as err: # pylint: disable=broad-except self.logger.error("impossible to perform the request on AAI: %s", str(err)) if service_instance_found is True: self.logger.info("Service instance not cleaned") return not service_instance_found
class SoComponentTesting(unittest.TestCase): _LOGGER = onap_test_utils.getLogger("onap_tests") _PROXY = onap_test_utils.get_config("general.proxy") def setUp(self): self.my_so = so.So(proxy=self._PROXY, LOGGER=self._LOGGER) def test_get_request_info(self): pass def _test_get_cloud_config(self): pass def test_get_cloud_config(self): pass def test_get_subscriber_info(self): pass def test_get_request_param(self): pass def test_get_service_model_info(self): pass def test_get_vnf_model_info(self): pass def test_get_vnf_related_instance(self): pass def test_get_module_model_info(self): pass def test_get_module_related_instance(self): pass def test_get_service_payload(self): pass def test_get_vnf_payload(self): pass def test_get_module_payload(self): pass def test_create_instance(self): pass def test_create_vnf(self): pass def test_create_module(self): pass def test_delete_instance(self): pass def test_delete_vnf(self): pass def test_delete_module(self): pass
# are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # # http://www.apache.org/licenses/LICENSE-2.0 # # pylint: disable=missing-docstring import logging import time import onap_tests.components.aai as aai import onap_tests.components.so as so import onap_tests.components.sdnc as sdnc import onap_tests.utils.stack_checker as sc import onap_tests.utils.utils as onap_utils PROXY = onap_utils.get_config("general.proxy") LOG_LEVEL = onap_utils.get_config("general.log.log_level") logging.basicConfig() LOGGER = logging.getLogger(__name__) logging.getLogger().setLevel(LOG_LEVEL) class Vnf(object): """ VNF: Class to automate the instantiation of a VNF It is assumed that the Design phase has been already done The yaml template is available and stored in the template directory TODO: automate the design phase """ def __init__(self, **kwargs): """Initialize Vnf object."""
# # http://www.apache.org/licenses/LICENSE-2.0 # # pylint: disable=missing-docstring # pylint: disable=duplicate-code import logging import time import onap_tests.components.aai as aai import onap_tests.components.so as so import onap_tests.components.sdnc as sdnc import onap_tests.components.nbi as nbi import onap_tests.utils.stack_checker as sc import onap_tests.utils.utils as onap_utils PROXY = onap_utils.get_config("general.proxy") class Solution(object): """ VNF: Class to automate the instantiation of a VNF It is assumed that the Design phase has been already done The yaml template is available and stored in the template directory TODO: automate the design phase """ __logger = logging.getLogger(__name__) def __init__(self, **kwargs): """Initialize Solution object.""" super(Solution, self).__init__() self.vnf_config = {}
def setUp(self): PROXY = onap_utils.get_config("general.proxy") self.my_aai = aai.Aai(PROXY, self.__logger)
def set_module_var(self): """ set module variables from the config file Fix: a VNF can have multiple VF so we need to iterate also on VF modules to find matching VNFs they belong to Get modules versions from tosca groups """ for elt in self.vnf_infos['list']: vf_config = {} # we cannot be sure that the modules are in the same order # than the vnf # iterate as long as some modules are found for the current VNF mod_index = 0 vf_index = 0 while vf_index >= 0: # If no more module are found for current VNF, index returned is -1 vf_index = onap_utils.get_vf_module_index( self.module_infos['list'], elt, mod_index=mod_index) if vf_index == -1: break module_name = "module-%s" % mod_index vnf_type = list( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups"))[vf_index] # Move this item to the module layer of the context (to avoid beeing overwritten when multiple VF in the VNF!) #vf_config["sdnc_vnf_type"] = onap_utils.get_template_param( # self.vnf_config["vnf"], "topology_template.groups." + # vnf_type + # ".metadata.vfModuleModelName") module_name = "module-%s" % mod_index vf_config[module_name] = {} vf_config[module_name][ "sdnc_vnf_type"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelName") self.__logger.info("get Module %s:%s info for VNF %s", module_name, vf_config[module_name]["sdnc_vnf_type"], elt) vnf_param = (self.vnf_config["vnf"] + "." + str(elt) + ".vnf_parameters") # For backward compatibility: If there is only one VF module in the VNF, the yaml file is VNF.vnf_parameters # if multiple VF: VNF.<VF_module>.vnf_parameters # vf_config["vnf_parameters"] = onap_utils.get_config(vnf_param) try: vnf_vf_params = onap_utils.get_config( vnf_param ) # exception if not found (new format with module-x except ValueError: # We look with the VF level in the yaml file vnf_param = (self.vnf_config["vnf"] + "." + str(elt) + "." + module_name + ".vnf_parameters") vnf_vf_params = onap_utils.get_config(vnf_param) # Add entry with the VNF.<module-x>.vnf_parameters vf_config[module_name]["vnf_parameters"] = vnf_vf_params # Every field below the groups is related to a specific vf and shold be in the vf context (not the VNF context!) vf_config[module_name][ "module_invariant_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelInvariantUUID") vf_config[module_name]["module_name_version_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelUUID")) vf_config[module_name]["module_customization_id"] = ( onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelCustomizationUUID")) vf_config[module_name][ "module_version_id"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelUUID") # Keep the initial_count to identify how many instances of a module have to be instantiated at startup vf_config[module_name][ "initial_count"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".properties.initial_count") # Module version (& trailing '.0') vf_config[module_name][ "module_version"] = onap_utils.get_template_param( self.vnf_config["vnf"], "topology_template.groups." + vnf_type + ".metadata.vfModuleModelVersion") + ".0" # Update the VNF Context with integrated VFs self.vnf_config[elt].update(vf_config) # prepare index for next loop mod_index += 1 # Keep Nb of VF_Module for this VNF self.vnf_config[elt]['vf_modules_count'] = mod_index
def __init__(self, **kwargs): """Initialize Solution object.""" super(Solution, self).__init__() #Check if Os_* vars are set if not self.check_env_vars(): self.__logger.error( "No OS_* environment variables detected : Exiting...") sys.exit(1) self.vnf_config = {} self.components = {} if "case" not in kwargs: # by convention is VNF is not precised we set mrf kwargs["case"] = "mrf" self.vnf_config["vnf"] = kwargs["case"] if "nbi" in kwargs: self.vnf_config["nbi"] = kwargs["nbi"] # can be useful to destroy resources, sdnc module name shall be given if "sdnc_vnf_name" in kwargs: self.vnf_config["sdnc_vnf_name"] = kwargs["sdnc_vnf_name"] # Random part = 6 last char of the the vnf name self.vnf_config["random_string"] = kwargs["sdnc_vnf_name"][-6:] else: self.vnf_config["random_string"] = ( onap_utils.random_string_generator()) self.vnf_config["sdnc_vnf_name"] = ( onap_utils.get_config("onap.service.name") + "_" + kwargs["case"] + "_" + self.vnf_config["random_string"]) LOG_LEVEL = onap_utils.get_config("general.log.log_level") if LOG_LEVEL == "DEBUG": self.__logger.info("DEBUG: Activated!") self.DebugActivated = True else: self.__logger.info("DEBUG: Not activated") self.DebugActivated = True vnf_list = list( onap_utils.get_template_param(self.vnf_config["vnf"], "topology_template.node_templates")) vf_module_list = list( onap_utils.get_template_param(self.vnf_config["vnf"], "topology_template.groups")) # Class attributes for instance, vnf and module VF self.service_infos = {} self.service_subscription_type = onap_utils.get_config( self.vnf_config["vnf"] + ".subscription_type") self.vnf_infos = {'list': vnf_list} self.module_infos = {'list': vf_module_list} # List of parameters of the preload to add a random key to self.parameters_random_addlist = onap_utils.get_config( self.vnf_config["vnf"] + ".add_random_to_parameters") # retrieve infos from the configuration files self.set_service_instance_var() self.set_vnf_var() self.set_module_var() self.set_onap_components()
class StackChecker(object): """ Class used to check is the Stack does exist in openstack And if the status is complete """ LOG_LEVEL = onap_test_utils.get_config("general.log.log_level") logging.basicConfig() __logger = logging.getLogger(__name__) logging.getLogger().setLevel(LOG_LEVEL) def __init__(self, **kwargs): """Initialize MRF object.""" super(StackChecker, self).__init__() # get param from env variables auth_url = self.get("OS_AUTH_URL") username = self.get("OS_USERNAME") password = self.get("OS_PASSWORD") project_id = self.get("OS_PROJECT_ID") project_name = self.get("OS_PROJECT_NAME") user_domain_name = self.get("OS_USER_DOMAIN_NAME") loader = loading.get_plugin_loader('password') try: auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_id=project_id, project_name=project_name, user_domain_name=user_domain_name) sess = session.Session(auth=auth) self.heat = client.Client('1', session=sess) except Exception: # pylint: disable=broad-except self.__logger.error("Env variables not found, impossible to get" " keystone client") try: self.stack_name = kwargs["stack_name"] except KeyError: self.__logger.info("No stack name provided at inititialization") @staticmethod def get(env_var): """ Get env variable """ return os.environ.get(env_var) def check_stack_exists(self, stack_name): """ Check if the stack exists in openstack """ stack_found = False nb_try = 0 nb_try_max = 5 while stack_found is False and nb_try < nb_try_max: stack_list = list(self.heat.stacks.list()) if stack_name in str(stack_list): self.__logger.info("Stack found") return True nb_try += 1 time.sleep(10) return stack_found def check_stack_is_complete(self, stack_name): """ Check the status of a stack """ # we assume that the stack does exist stack_status_complete = False nb_try = 0 nb_try_max = 5 while stack_status_complete is False and nb_try < nb_try_max: stack_list = list(self.heat.stacks.list()) for stack in enumerate(stack_list): if stack_name in str(stack_list): found_stack = stack[1] if "COMPLETE" in found_stack.status: return True nb_try += 1 time.sleep(10) return stack_status_complete