ec4bd84f879014a2ff02294e022e21c07a6fd1c3
[testsuite/pythonsdk-tests.git] / src / onaptests / configuration / settings.py
1 """Specific settings module."""
2
3 ######################
4 #                    #
5 # ONAP INPUTS DATAS  #
6 #                    #
7 ######################
8
9 import random
10 import string
11 from jinja2 import Environment, PackageLoader
12
13 # Variables to set logger information
14 # Possible values for logging levels in onapsdk: INFO, DEBUG , WARNING, ERROR
15 LOG_CONFIG = {
16     "version": 1,
17     "disable_existing_loggers": False,
18     "formatters": {
19         "default": {
20             "class": "logging.Formatter",
21             "format": "%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s"
22         }
23     },
24     "handlers": {
25         "console": {
26             "level": "DEBUG",
27             "class": "logging.StreamHandler",
28             "formatter": "default"
29         },
30         "file": {
31             "level": "DEBUG",
32             "class": "logging.FileHandler",
33             "formatter": "default",
34             "filename": "/tmp/pythonsdk.debug.log",
35             "mode": "w"
36         }
37     },
38     "root": {
39         "level": "DEBUG",
40         "handlers": ["console", "file"]
41     }
42 }
43 CLEANUP_FLAG = False
44 CLEANUP_ACTIVITY_TIMER = 5
45 SDC_CLEANUP = False
46
47 REPORTING_FILE_DIRECTORY = "/tmp/"
48 HTML_REPORTING_FILE_NAME = "reporting.html"
49 JSON_REPORTING_FILE_NAME = "reporting.json"
50 K8S_REGION_TYPE = "k8s"
51 TILLER_HOST = "localhost"
52 K8S_CONFIG = None  # None means it will use default config (~/.kube/config)
53 K8S_ONAP_NAMESPACE = "onap"  # ONAP Kubernetes namespace
54 K8S_ADDITIONAL_RESOURCES_NAMESPACE = K8S_ONAP_NAMESPACE  # Resources created on tests namespace
55 MSB_K8S_OVERRIDE_VALUES = None
56 # SOCK_HTTP = "socks5h://127.0.0.1:8091"
57
58 ORCHESTRATION_REQUEST_TIMEOUT = 60.0 * 15  # 15 minutes in seconds
59 SERVICE_DISTRIBUTION_NUMBER_OF_TRIES = 30
60 SERVICE_DISTRIBUTION_SLEEP_TIME = 60
61 EXPOSE_SERVICES_NODE_PORTS = True
62 CDS_NODE_PORT = 30449
63 IN_CLUSTER = False
64 VES_BASIC_AUTH = {'username': 'sample1', 'password': 'sample1'}
65 IF_VALIDATION = False
66 SDNC_SECRET_NAME = "onap-sdnc-db-secret"
67 SDNC_DB_PRIMARY_HOST = "sdnc-db.onap.svc.cluster.local"
68 SDNC_DB_PORT = 3306
69
70
71 # We need to create a service file with a random service name,
72 # to be sure that we force onboarding
73 def generate_service_config_yaml_file(service_name: str,
74                                       service_template: str,
75                                       service_config: str,
76                                       generate_random_names: bool = False):
77     """Generate service config YAML file.
78
79     Service configurations (both models and instances) are stored in YAML files
80         mostly generated by filling Jinja templates with service names. For most
81         cases we are generate the same configuration for all runs
82         (so generate_random_names is set to False, as default) but it is possible to
83         create all resources on each test execution.
84
85     Args:
86         service_name (str): Name of the service
87         service_template (str): Template which would be used to generate configuration
88         service_config (str): Configuration output file path
89         generate_random_names (bool, optional): Flag indicating whether service name
90             should have a random suffix or not. Defaults to False.
91
92     """
93
94     env = Environment(
95         loader=PackageLoader('onaptests', 'templates/vnf-services'),
96     )
97     template = env.get_template(service_template)
98
99     if generate_random_names:
100         # get a random string to randomize the vnf name
101         # Random string with the combination of lower and upper case
102         letters = string.ascii_letters
103         result_str = ''.join(random.choice(letters) for i in range(6))
104         service_name = f"{service_name}_{result_str}"
105
106     rendered_template = template.render(service_name=service_name)
107
108     with open(service_config, 'w+', encoding="utf-8") as file_to_write:
109         file_to_write.write(rendered_template)