From ffa11b3d1bff7a4448637a04be09cde58d71b362 Mon Sep 17 00:00:00 2001 From: Matt Love Date: Wed, 10 Jul 2019 16:20:23 -0700 Subject: [PATCH] :bug: Properly handle lack of user config --- hyperglass/configuration/__init__.py | 12 ++++++++++-- tests/{configuration.yaml => hyperglass.yaml} | 0 2 files changed, 10 insertions(+), 2 deletions(-) rename tests/{configuration.yaml => hyperglass.yaml} (100%) diff --git a/hyperglass/configuration/__init__.py b/hyperglass/configuration/__init__.py index 18cc087..8e411bd 100644 --- a/hyperglass/configuration/__init__.py +++ b/hyperglass/configuration/__init__.py @@ -24,12 +24,14 @@ try: with open(working_dir.joinpath("hyperglass.yaml")) as config_yaml: user_config = yaml.safe_load(config_yaml) except FileNotFoundError as no_config_error: + user_config = None logger.error(f"{no_config_error} - Default configuration will be used") # Import device commands file try: with open(working_dir.joinpath("commands.yaml")) as commands_yaml: user_commands = yaml.safe_load(commands_yaml) except FileNotFoundError: + user_commands = None logger.info( ( f'No commands found in {working_dir.joinpath("commands.yaml")}. ' @@ -52,8 +54,14 @@ except FileNotFoundError as no_devices_error: # Map imported user config files to expected schema: try: - params = models.Params(**user_config) - commands = models.Commands.import_params(user_commands) + if user_config: + params = models.Params(**user_config) + elif not user_config: + params = models.Params() + if user_commands: + commands = models.Commands.import_params(user_commands) + elif not user_commands: + commands = models.Commands() devices = models.Routers.import_params(user_devices["router"]) credentials = models.Credentials.import_params(user_devices["credential"]) proxies = models.Proxies.import_params(user_devices["proxy"]) diff --git a/tests/configuration.yaml b/tests/hyperglass.yaml similarity index 100% rename from tests/configuration.yaml rename to tests/hyperglass.yaml