From 87cafc60f4ab154e6ea241953ad2ceddbfaa0b6a Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Wed, 16 Feb 2022 10:15:32 +0100 Subject: [PATCH] Checking inventory file presence and format Unless the inventory consists of only localhost, we are going to check it's presence and formatting, before actually starting validations. Docstring of the 'read_cli_data_file' was expanded to provide more info. Signed-off-by: Jiri Podivin Change-Id: I44a3081f64b169d874d1b790b9739ad13e556714 --- validations_libs/cli/common.py | 7 +++++++ validations_libs/cli/run.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/validations_libs/cli/common.py b/validations_libs/cli/common.py index b7322336..a9314b9c 100644 --- a/validations_libs/cli/common.py +++ b/validations_libs/cli/common.py @@ -104,6 +104,13 @@ def write_junitxml(output_junitxml, results): def read_cli_data_file(data_file): """Read CLI data (YAML/JSON) file. + :param data_file: Path to the requested file. + :type data_file: ``path like`` + + :returns: Parsed YAML/JSON file + :rtype: ``dict`` + + :raises: RuntimeError if the file doesn't exist or is malformed. """ try: with open(data_file, 'r') as _file: diff --git a/validations_libs/cli/run.py b/validations_libs/cli/run.py index 5072bca7..e5c7760a 100644 --- a/validations_libs/cli/run.py +++ b/validations_libs/cli/run.py @@ -171,6 +171,14 @@ class Run(BaseCommand): # Get config: config = self.base.config + # Verify properties of inventory file, if it isn't just 'localhost' + if parsed_args.inventory.startswith('localhost'): + self.app.LOG.debug( + "You are using inline inventory. '{}'".format( + parsed_args.inventory)) + else: + common.read_cli_data_file(parsed_args.inventory) + v_actions = ValidationActions( parsed_args.validation_dir, log_path=parsed_args.validation_log_dir) # Ansible execution should be quiet while using the validations_json