From 0b55614e6dad4e597f5f2fc778a71dacf73dbe60 Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 16 2017 14:04:12 +0000 Subject: [PATCH 1/4] update docstring for get_correct_config --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py old mode 100644 new mode 100755 index 71c0914..094497d --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -1368,10 +1368,10 @@ def get_correct_url(): def get_correct_config(): """ - Return proper config what should be used - default location is ./config.yaml, could be refedined via - env variable CONFIG + Read the module's configuration file + :default: ``./config.yaml`` in the ``tests`` directory of the module's root directory + :envvar: **CONFIG=path/to/file** overrides default value. :return: str """ cfgfile = os.environ.get('CONFIG') From 3e4aabb746c68e118a58beba9b2a1e6f50c67c6e Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 17 2017 20:01:35 +0000 Subject: [PATCH 2/4] fix var assignment for get_correct_config --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 094497d..bec8434 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -1374,9 +1374,7 @@ def get_correct_config(): :envvar: **CONFIG=path/to/file** overrides default value. :return: str """ - cfgfile = os.environ.get('CONFIG') - if not cfgfile: - cfgfile = "config.yaml" + cfgfile = os.environ.get('CONFIG') or './config.yaml' if not os.path.exists(cfgfile): raise ConfigExc( "Config file (%s) does not exist or is inaccesible (you can also redefine own by CONFIG=path/to/configfile.yaml env variable)" % From 6dec5ec1d2430cd7e65d0f06c8b39b9d4b682e6f Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 17 2017 20:13:15 +0000 Subject: [PATCH 3/4] update error handler for get_correct_config --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index bec8434..547dd02 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -1375,18 +1375,15 @@ def get_correct_config(): :return: str """ cfgfile = os.environ.get('CONFIG') or './config.yaml' - if not os.path.exists(cfgfile): - raise ConfigExc( - "Config file (%s) does not exist or is inaccesible (you can also redefine own by CONFIG=path/to/configfile.yaml env variable)" % - cfgfile) - with open(cfgfile, 'r') as ymlfile: - xcfg = yaml.load(ymlfile.read()) - if xcfg['document'] != 'modularity-testing': - raise ConfigExc( - "Bad Config file, not yaml or does not contain proper document type" % - cfgfile) - return xcfg - + try: + with open(cfgfile, 'r') as ymlfile: + xcfg = yaml.load(ymlfile.read()) + return xcfg + except IOError: + raise ConfigExc( + "Error: File '%s' doesn't appear to exist or it's not a YAML file." % + cfgfile + " " + + "Tip: If the CONFIG envvar is not set, mtf-generator looks for './config'.") def get_compose_url(): """ From f382e292ef136b1704ba2e4616fab23c2637a706 Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 17 2017 20:13:45 +0000 Subject: [PATCH 4/4] rename get_correct_config --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 547dd02..f54406f 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -141,7 +141,7 @@ class CommonFunctions(object): :return: None """ try: - self.config = get_correct_config() + self.config = get_config() self.moduleName = self.config['name'] self.source = self.config.get('source') if self.config.get( 'source') else self.config['module']['rpm'].get('source') @@ -1366,7 +1366,7 @@ def get_correct_url(): return amodule -def get_correct_config(): +def get_config(): """ Read the module's configuration file