diff options
author | Chereau Natacha <natacha.chereau@orange.com> | 2021-01-13 10:54:46 +0100 |
---|---|---|
committer | Chereau Natacha <natacha.chereau@orange.com> | 2021-01-15 11:01:19 +0100 |
commit | ff24de49ef658ffe0aa13d494e8201bd181bce2c (patch) | |
tree | b4425e2240fd1cd1e760053f49fc161f71208595 /src/onaptests | |
parent | d089e89005df1b4b3b6238a2937e23791c07d9ae (diff) |
[PythonSDK-tests] Add basic_onboard testcase
Issue-ID: TEST-288
Signed-off-by: Chereau Natacha <natacha.chereau@orange.com>
Change-Id: Ide7267428b5ca694dc3ca44a4c81730233610b78
Diffstat (limited to 'src/onaptests')
-rw-r--r-- | src/onaptests/configuration/basic_onboard_settings.py | 68 | ||||
-rw-r--r-- | src/onaptests/configuration/settings.py | 2 | ||||
-rw-r--r-- | src/onaptests/scenario/basic_onboard.py | 43 | ||||
-rw-r--r-- | src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 | 39 |
4 files changed, 151 insertions, 1 deletions
diff --git a/src/onaptests/configuration/basic_onboard_settings.py b/src/onaptests/configuration/basic_onboard_settings.py new file mode 100644 index 0000000..db7680d --- /dev/null +++ b/src/onaptests/configuration/basic_onboard_settings.py @@ -0,0 +1,68 @@ + +import sys +import random +import string +from yaml import load +from jinja2 import Environment, PackageLoader +import onaptests.utils.exceptions as onap_test_exceptions +from .settings import * # pylint: disable=W0614 + +""" Creation of service to onboard""" + +# We need to create a service file with a random service name, +# to be sure that we force onboarding +def generate_service_config_yaml_file(): + """ generate the service file with a random service name + from a jinja template""" + + env = Environment( + loader=PackageLoader('onaptests', 'templates/vnf-services'), + ) + template = env.get_template('basic_onboard-service.yaml.j2') + + # get a random string to randomize the vnf name + # Random string with the combination of lower and upper case + letters = string.ascii_letters + result_str = ''.join(random.choice(letters) for i in range(6)) + service_name = 'basic_onboard_' + result_str + + rendered_template = template.render(service_name=service_name) + + file_name = (sys.path[-1] + "/onaptests/templates/vnf-services/" + + "basic-onboard-service.yaml") + + with open(file_name, 'w+') as file_to_write: + file_to_write.write(rendered_template) + +"""Basic onboard service to only onboard a service in SDC""" + +# pylint: disable=bad-whitespace +# The ONAP part +SERVICE_DETAILS="Onboarding of an Ubuntu VM" +SERVICE_COMPONENTS="SDC" + +#USE_MULTICLOUD = False +# Set ONLY_INSTANTIATE to true to run an instantiation without repeating +# onboarding and related AAI configuration (Cloud config) +#ONLY_INSTANTIATE= False + +# if a yaml file is define, retrieve info from this yaml files +# if not declare the parameters in the settings +generate_service_config_yaml_file() +SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + + "basic-onboard-service.yaml") + +try: + # Try to retrieve the SERVICE NAME from the yaml file + with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: + yaml_config_file = load(yaml_template) + SERVICE_NAME = next(iter(yaml_config_file.keys())) +except (FileNotFoundError, ValueError): + raise onap_test_exceptions.TestConfigurationException + +#CLEANUP_FLAG = True +#CLEANUP_ACTIVITY_TIMER = 10 # nb of seconds before cleanup in case cleanup option is set +VENDOR_NAME = "basic_onboard_vendor" + +VF_NAME = "basic_onboard_vf" +VSP_NAME = "basic_onboard_vsp" diff --git a/src/onaptests/configuration/settings.py b/src/onaptests/configuration/settings.py index a2a4b4a..ba4e163 100644 --- a/src/onaptests/configuration/settings.py +++ b/src/onaptests/configuration/settings.py @@ -43,4 +43,4 @@ REPORTING_FILE_PATH = "/tmp/reporting.html" K8S_REGION_TYPE = "k8s" K8S_CONFIG = None # None means it will use default config (~/.kube/config) K8S_NAMESPACE = "onap" # Kubernetes namespace -# SOCK_HTTP = "socks5h://127.0.0.1:8083" +#SOCK_HTTP = "socks5h://127.0.0.1:8091" diff --git a/src/onaptests/scenario/basic_onboard.py b/src/onaptests/scenario/basic_onboard.py new file mode 100644 index 0000000..3695975 --- /dev/null +++ b/src/onaptests/scenario/basic_onboard.py @@ -0,0 +1,43 @@ + +#!/usr/bin/env python +"""Basic Onboard test case.""" +import logging +import time +from xtesting.core import testcase +#from onapsdk.configuration import settings +import onaptests.utils.exceptions as onap_test_exceptions +#from onaptests.steps.onboard.service import YamlTemplateServiceOnboardStep + +class BasicOnboard(testcase.TestCase): + """Onboard a simple VM with ONAP.""" + + __logger = logging.getLogger(__name__) + + def __init__(self, **kwargs): + """Init BasicOnboard.""" + # import basic_onboard_settings needed + if "case_name" not in kwargs: + kwargs["case_name"] = 'basic_onboard' + super(BasicOnboard, self).__init__(**kwargs) + self.__logger.debug("BasicOnboard init started") + self.start_time = None + self.stop_time = None + self.result = 0 + + def run(self): + """Run basic_onboard and onboard a simple service""" + self.start_time = time.time() + self.__logger.debug("start time") + try: + self.test.execute() + self.__logger.info("VNF basic_vm successfully onboarded") + except onap_test_exceptions.OnapTestException as exc: + self.result = 0 + self.__logger.error(exc.error_message) + finally: + self.stop_time = time.time() + + def clean(self): + """Clean Additional resources if needed.""" + self.__logger.info("Generate Test report") + self.test.reports_collection.generate_report() diff --git a/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 b/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 new file mode 100644 index 0000000..c45745e --- /dev/null +++ b/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 @@ -0,0 +1,39 @@ +--- +{{ service_name }}: + vnfs: + - vnf_name: {{ service_name }} + heat_files_to_upload: onaptests/templates/heat-files/ubuntu18/ubuntu18agent.zip + vnf_parameters: [ + {"name": "ubuntu18_image_name", + "value": "ubuntu-agent" + }, + {"name": "ubuntu18_key_name", + "value": "cleouverte" + }, + {"name": "ubuntu18_pub_key", + "value": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAA\ +BAQDY15cdBmIs2XOpe4EiFCsaY6bmUmK/GysMoLl4UG51JCfJwvwoWCoA+6mDIbymZxhxq9IGx\ +ilp/yTA6WQ9s/5pBag1cUMJmFuda9PjOkXl04jgqh5tR6I+GZ97AvCg93KAECis5ubSqw1xOCj4\ +utfEUtPoF1OuzqM/lE5mY4N6VKXn+fT7pCD6cifBEs6JHhVNvs5OLLp/tO8Pa3kKYQOdyS0xc3r\ +h+t2lrzvKUSWGZbX+dLiFiEpjsUL3tDqzkEMNUn4pdv69OJuzWHCxRWPfdrY9Wg0j3mJesP29EBh\ +t+w+EC9/kBKq+1VKdmsXUXAcjEvjovVL8l1BrX3BY0R8D imported-openssh-key" + }, + {"name": "ubuntu18_flavor_name", + "value": "onap.small" + }, + {"name": "VM_name", + "value": "ubuntu18agent-VM-01" + }, + {"name": "vnf_id", + "value": "ubuntu18agent-VNF-instance" + }, + {"name": "vf_module_id", + "value": "ubuntu18agent-vfmodule-instance" + }, + {"name": "vnf_name", + "value": "ubuntu18agent-VNF" + }, + {"name": "admin_plane_net_name", + "value": "admin" + } + ] |