aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/configuration/settings.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/onaptests/configuration/settings.py')
-rw-r--r--src/onaptests/configuration/settings.py44
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)