From a89a5a7e3b0421a5ae1859235dfef6b6adf24279 Mon Sep 17 00:00:00 2001 From: Gabriel Cuba Date: Sat, 26 Nov 2022 18:55:15 -0500 Subject: [PATCH] Fix loading of boolean values in configuration and set missing default values Change-Id: I11e5e778e916fc84781bd73cce8a6d050b76ee5b Signed-off-by: Gabriel Cuba --- osm_lcm/data_utils/lcm_config.py | 4 +- osm_lcm/lcm.cfg | 20 ++++----- osm_lcm/lcm.py | 32 ++------------ osm_lcm/netslice.py | 7 +--- osm_lcm/tests/test_lcm.py | 2 +- osm_lcm/tests/test_lcm_config_file_ini.cfg | 49 ---------------------- 6 files changed, 17 insertions(+), 97 deletions(-) delete mode 100644 osm_lcm/tests/test_lcm_config_file_ini.cfg diff --git a/osm_lcm/data_utils/lcm_config.py b/osm_lcm/data_utils/lcm_config.py index 13d3e68..08a8728 100644 --- a/osm_lcm/data_utils/lcm_config.py +++ b/osm_lcm/data_utils/lcm_config.py @@ -61,7 +61,7 @@ class GlobalConfig(OsmConfigman): class Timeout(OsmConfigman): - nsi_deploy: int = None + nsi_deploy: int = 2 * 3600 # default global timeout for deployment a nsi vca_on_error: int = ( 5 * 60 ) # Time for charm from first time at blocked,error status to mark as failed @@ -90,7 +90,7 @@ class RoConfig(OsmConfigman): port: int = None uri: str = None tenant: str = "osm" - loglevel: str = "DEBUG" + loglevel: str = "ERROR" logfile: str = None logger_name: str = None diff --git a/osm_lcm/lcm.cfg b/osm_lcm/lcm.cfg index 9f580da..625f24e 100644 --- a/osm_lcm/lcm.cfg +++ b/osm_lcm/lcm.cfg @@ -14,25 +14,25 @@ # under the License. ## -# TODO currently is a pure yaml format. Consider to change it to [ini] style with yaml inside to be coherent with other modules +# TODO currently is a pure yaml format. Consider to change it to [ini: style with yaml inside to be coherent with other modules -[global] +global: loglevel: DEBUG # logfile: /app/log # or /var/log/osm/lcm.log # nologging: True # do no log to stdout/stderr -[timeout] +timeout: # ns_deploy: 7200 # total deploy timeout for a ns 2 hours # nsi_deploy: 7200 # total deploy timeout for a nsi 2 hours -[RO] +RO: host: ro # hostname or IP port: 9090 tenant: osm # loglevel: DEBUG # logfile: /var/log/osm/lcm-ro.log -[VCA] +VCA: host: vca port: 17070 user: admin @@ -43,7 +43,7 @@ helm3path: /usr/local/bin/helm3 kubectlpath: /usr/bin/kubectl jujupath: /usr/local/bin/juju - eegrpc_tls_enforce: False + eegrpc_tls_enforce: false # public_key: pubkey # ca_cert: cacert # api_proxy: apiproxy @@ -53,7 +53,7 @@ # loglevel: DEBUG # logfile: /var/log/osm/lcm-vca.log -[database] +database: driver: mongo # mongo or memory host: mongo # hostname or IP port: 27017 @@ -65,14 +65,14 @@ # loglevel: DEBUG # logfile: /var/log/osm/lcm-database.log -[storage] +storage: driver: local # local filesystem # for local provide file path path: /app/storage # loglevel: DEBUG # logfile: /var/log/osm/lcm-storage.log -[message] +message: driver: kafka # local or kafka # for local provide file path path: /app/storage/kafka @@ -83,7 +83,7 @@ # logfile: /var/log/osm/lcm-message.log group_id: lcm-server -[tsdb] # time series database +tsdb: # time series database driver: prometheus # local file to store the configuration path: /etc/prometheus diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index 9f0e310..5638943 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -28,7 +28,6 @@ import logging import logging.handlers import getopt import sys -import configparser from osm_lcm import ns, vim_sdn, netslice from osm_lcm.ng_ro import NgRoException, NgRoClient @@ -750,37 +749,12 @@ class Lcm: self.fs.fs_disconnect() def read_config_file(self, config_file): - # TODO make a [ini] + yaml inside parser - # the configparser library is not suitable, because it does not admit comments at the end of line, - # and not parse integer or boolean - conf = {} try: - # read file as yaml format - config = configparser.ConfigParser(inline_comment_prefixes="#") - config.read(config_file) - conf = {s: dict(config.items(s)) for s in config.sections()} + with open(config_file) as f: + return yaml.safe_load(f) except Exception as e: self.logger.critical("At config file '{}': {}".format(config_file, e)) - self.logger.critical("Trying to load config as legacy mode") - try: - with open(config_file) as f: - conf = yaml.safe_load(f) - # Ensure all sections are not empty - for k in ( - "global", - "timeout", - "RO", - "VCA", - "database", - "storage", - "message", - ): - if not conf.get(k): - conf[k] = {} - except Exception as e: - self.logger.critical("At config file '{}': {}".format(config_file, e)) - exit(1) - return conf + exit(1) @staticmethod def get_process_id(): diff --git a/osm_lcm/netslice.py b/osm_lcm/netslice.py index 42b634e..2256540 100644 --- a/osm_lcm/netslice.py +++ b/osm_lcm/netslice.py @@ -34,9 +34,6 @@ __author__ = "Felipe Vicens, Pol Alemany, Alfonso Tierno" class NetsliceLcm(LcmBase): - - timeout_nsi_deploy = 2 * 3600 # default global timeout for deployment a nsi - def __init__(self, msg, lcm_tasks, config, loop, ns): """ Init, Connect to database, filesystem storage, and messaging @@ -392,9 +389,7 @@ class NetsliceLcm(LcmBase): if nsi_params and nsi_params.get("timeout_nsi_deploy"): timeout_nsi_deploy = nsi_params["timeout_nsi_deploy"] else: - timeout_nsi_deploy = self.timeout.get( - "nsi_deploy", self.timeout_nsi_deploy - ) + timeout_nsi_deploy = self.timeout.get("nsi_deploy") # Empty list to keep track of network service records status in the netslice nsir_admin = db_nsir_admin = db_nsir.get("_admin") diff --git a/osm_lcm/tests/test_lcm.py b/osm_lcm/tests/test_lcm.py index e05836a..cc18c37 100644 --- a/osm_lcm/tests/test_lcm.py +++ b/osm_lcm/tests/test_lcm.py @@ -64,7 +64,7 @@ def check_file_content(health_check_file: str) -> str: class TestLcm(TestCase): def setUp(self): - self.config_file = os.getcwd() + "/osm_lcm/tests/test_lcm_config_file_ini.cfg" + self.config_file = os.getcwd() + "/osm_lcm/tests/test_lcm_config_file.yaml" self.config_file_without_storage_path = tempfile.mkstemp()[1] Database.instance = None self.db = Mock(Database({"database": {"driver": "memory"}}).instance.db) diff --git a/osm_lcm/tests/test_lcm_config_file_ini.cfg b/osm_lcm/tests/test_lcm_config_file_ini.cfg deleted file mode 100644 index a6afb65..0000000 --- a/osm_lcm/tests/test_lcm_config_file_ini.cfg +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 Canonical Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -[global] - loglevel: DEBUG -[RO] - host: ro - port: 9090 - tenant: osm -[VCA] - host: vca - port: 17070 - user: admin - secret: secret - cloud: localhost - k8s_cloud: k8scloud - helmpath: /usr/local/bin/helm - helm3path: /usr/local/bin/helm3 - kubectlpath: /usr/bin/kubectl - jujupath: /usr/local/bin/juju -[database] - driver: memory # mongo or memory - # host: mongo # hostname or IP - port: 27017 - name: osm -[storage] - driver: local # local filesystem - path: /tmp/storage -[message] - driver: local # local or kafka - path: /tmp/kafka - host: kafka - port: 9092 - group_id: lcm-server -[tsdb] # time series database - driver: prometheus - path: /tmp/prometheus - uri: http://prometheus:9090/ -- 2.25.1