diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-01-31 08:30:41 +0100 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-02-02 08:30:15 +0100 |
commit | 440df5e3af8446ddaf1e7ab9ed5abbbe439f9a06 (patch) | |
tree | 13ee8f0a3839b18eff32a1bcab25a6c5baf00364 /src/onaptests/configuration/settings.py | |
parent | 6a3e189d7fac6ec562f8785c71ed87663ef0c311 (diff) |
Refactor tests to use SDC v2 onapsdk module
Refactored SDC allows to archive and delete SDC resources
Remove unmaintained test basic_clamp
Issue-ID: TEST-404
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I11e4be6f4567098b20733879e393c689766a9c6e
Diffstat (limited to 'src/onaptests/configuration/settings.py')
-rw-r--r-- | src/onaptests/configuration/settings.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/onaptests/configuration/settings.py b/src/onaptests/configuration/settings.py index 399f3f7..5feffac 100644 --- a/src/onaptests/configuration/settings.py +++ b/src/onaptests/configuration/settings.py @@ -6,6 +6,9 @@ # # ###################### +import random +import string +from jinja2 import Environment, PackageLoader # Variables to set logger information # Possible values for logging levels in onapsdk: INFO, DEBUG , WARNING, ERROR @@ -60,3 +63,44 @@ CDS_NODE_PORT = 30449 IN_CLUSTER = False VES_BASIC_AUTH = {'username': 'sample1', 'password': 'sample1'} IF_VALIDATION = False + + +# 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(service_name: str, + service_template: str, + service_config: str, + generate_random_names: bool = False): + """Generate service config YAML file. + + Service configurations (both models and instances) are stored in YAML files + mostly generated by filling Jinja templates with service names. For most + cases we are generate the same configuration for all runs + (so generate_random_names is set to False, as default) but it is possible to + create all resources on each test execution. + + Args: + service_name (str): Name of the service + service_template (str): Template which would be used to generate configuration + service_config (str): Configuration output file path + generate_random_names (bool, optional): Flag indicating whether service name + should have a random suffix or not. Defaults to False. + + """ + + env = Environment( + loader=PackageLoader('onaptests', 'templates/vnf-services'), + ) + template = env.get_template(service_template) + + if generate_random_names: + # 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 = f"{service_name}_{result_str}" + + rendered_template = template.render(service_name=service_name) + + with open(service_config, 'w+', encoding="utf-8") as file_to_write: + file_to_write.write(rendered_template) |