diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2019-12-10 09:50:09 +0100 |
---|---|---|
committer | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-01-08 10:18:04 +0000 |
commit | 3f047b81fba3c4359031cea0256d11b3c5787d6a (patch) | |
tree | 172416847e7dde3bbcc9c003385e8bd41c85014c | |
parent | 8c7373d8c5c432bc0aca3c508edc2948659f3136 (diff) |
Support reading configuration from vcpeconfig.yaml
Settings from config file will be assigned directly
to VcpeCommon class' object attributes.
Change-Id: I3cd31077c04de6bacf6dc2365837405a1aa5f6cc
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Issue-ID: INT-1399
-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 |