From c905f57046424e32eb4f46cc57d1556d42c53e13 Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Thu, 6 May 2021 12:01:29 +0200 Subject: [PATCH] Constants path formatting unification Paths in the constants.py are now formatted using a single function, the os.path.join. This both normalizes the code and reduces chance of errors and confusion arising from nonstandard paths. Signed-off-by: Jiri Podivin Change-Id: I761c4449579590b9081a78627eeac754d6b04e2a --- validations_libs/constants.py | 9 ++++++--- validations_libs/tests/test_validation_actions.py | 1 + validations_libs/utils.py | 8 +++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/validations_libs/constants.py b/validations_libs/constants.py index da5f9f4e..d5e45470 100644 --- a/validations_libs/constants.py +++ b/validations_libs/constants.py @@ -18,9 +18,12 @@ DEFAULT_VALIDATIONS_BASEDIR = '/usr/share/ansible/' ANSIBLE_VALIDATION_DIR = '/usr/share/ansible/validation-playbooks' -VALIDATION_GROUPS_INFO = '%s/groups.yaml' % DEFAULT_VALIDATIONS_BASEDIR +VALIDATION_GROUPS_INFO = os.path.join( + DEFAULT_VALIDATIONS_BASEDIR, + 'groups.yaml') VALIDATIONS_LOG_BASEDIR = os.path.join(os.environ.get('HOME'), 'validations') -VALIDATION_ANSIBLE_ARTIFACT_PATH = '{}/artifacts/'.format( - VALIDATIONS_LOG_BASEDIR) +VALIDATION_ANSIBLE_ARTIFACT_PATH = os.path.join( + VALIDATIONS_LOG_BASEDIR, + 'artifacts') diff --git a/validations_libs/tests/test_validation_actions.py b/validations_libs/tests/test_validation_actions.py index 79f2fc25..9f5279b4 100644 --- a/validations_libs/tests/test_validation_actions.py +++ b/validations_libs/tests/test_validation_actions.py @@ -222,6 +222,7 @@ class TestValidationActions(TestCase): validations_dir='/tmp/foo' ) + @mock.patch('validations_libs.validation_logs.ValidationLogs.get_results') @mock.patch('validations_libs.utils.parse_all_validations_on_disk') @mock.patch('validations_libs.ansible.Ansible.run') diff --git a/validations_libs/utils.py b/validations_libs/utils.py index 0f7c2de2..26804915 100644 --- a/validations_libs/utils.py +++ b/validations_libs/utils.py @@ -66,7 +66,7 @@ def create_artifacts_dir(log_path=constants.VALIDATIONS_LOG_BASEDIR, :type log_path: `string` :param prefix: Playbook name :type prefix: `string` - :return: The UUID of the validation and the absolute Path of the log file + :return: The UUID of the validation and the absolute path of the log file :rtype: `string`, `string` """ artifact_dir = os.path.join(log_path, 'artifacts') @@ -79,11 +79,13 @@ def create_artifacts_dir(log_path=constants.VALIDATIONS_LOG_BASEDIR, except (OSError, PermissionError): LOG.exception( ( - "Error while creating Ansible artifacts log file." - "Please check the access rights for {}" + "Error while creating Ansible artifacts directory. " + "Please check the access rights for: '{}'" ).format(log_dir) ) + raise RuntimeError() + def parse_all_validations_on_disk(path, groups=None): """Return a list of validations metadata which can be sorted by Groups