From 3f047b81fba3c4359031cea0256d11b3c5787d6a Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Tue, 10 Dec 2019 09:50:09 +0100 Subject: 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 Issue-ID: INT-1399 --- test/vcpe/vcpecommon.py | 30 ++++++++++++++++++++++++++++++ test/vcpe/vcpeconfig.yaml | 0 2 files changed, 30 insertions(+) create mode 100644 test/vcpe/vcpeconfig.yaml 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 -- cgit 1.2.3-korg