diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/vcpe/vcpecommon.py | 30 | ||||
-rw-r--r-- | test/vcpe/vcpeconfig.yaml | 0 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/vcpe/vcpecommon.py b/test/vcpe/vcpecommon.py index 0041a567b..9c5e626c5 100755 --- a/test/vcpe/vcpecommon.py +++ b/test/vcpe/vcpecommon.py @@ -12,6 +12,7 @@ import mysql.connector import requests import commands import time +import yaml from novaclient import client as openstackclient from kubernetes import client, config from netaddr import IPAddress, IPNetwork @@ -95,6 +96,9 @@ class VcpeCommon: self.logger.setLevel(logging.DEBUG) self.logger.info('Initializing configuration') + # Read configuration from config file + self._load_config() + # OOM: this is the address that the brg and bng will nat for sdnc access - 10.0.0.x address of k8 host for sdnc-0 container self.sdnc_oam_ip = self.get_pod_node_oam_ip(self.sdnc_controller_pod) # OOM: this is a k8s host external IP, e.g. oom-k8s-01 IP @@ -227,6 +231,32 @@ class VcpeCommon: 'Content-Type': 'application/json', 'X-FromAppId': 'postman', 'X-TransactionId': '9999'} + def _load_config(self, cfg_file='vcpeconfig.yaml'): + """ + Reads vcpe config file and injects settings as object's attributes + :param cfg_file: Configuration file path + """ + + try: + with open(cfg_file, 'r') as cfg: + cfg_yml = yaml.full_load(cfg) + except Exception as e: + self.logger.error('Error loading configuration: ' + str(e)) + sys.exit(1) + + self.logger.debug('\n' + yaml.dump(cfg_yml)) + + # Use setattr to load config file keys as VcpeCommon class' object + # attributes + try: + # Check config isn't empty + if cfg_yml is not None: + for cfg_key in cfg_yml: + setattr(self, cfg_key, cfg_yml[cfg_key]) + except TypeError as e: + self.logger.error('Unable to parse config file: ' + str(e)) + sys.exit(1) + def heatbridge(self, openstack_stack_name, svc_instance_uuid): """ Add vserver information to AAI diff --git a/test/vcpe/vcpeconfig.yaml b/test/vcpe/vcpeconfig.yaml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/vcpe/vcpeconfig.yaml |