Merge "Move inventory environment loading to function"

This commit is contained in:
Jenkins 2016-04-21 02:12:33 +00:00 committed by Gerrit Code Review
commit a7881a1348
2 changed files with 39 additions and 7 deletions

View File

@ -898,11 +898,29 @@ def _check_config_settings(cidr_networks, config, container_skel):
)
def load_environment(config_path):
"""Create an environment dictionary from config files
:param config_path: ``str``path where the environment files are kept
"""
environment = dict()
# Load all YAML files found in the env.d directory
env_plugins = os.path.join(config_path, 'env.d')
if os.path.isdir(env_plugins):
_extra_config(user_defined_config=environment, base_dir=env_plugins)
return environment
def load_user_configuration(config_path):
"""Create a user configuration dictionary from config files
:param config_path: ``str`` path where the configuration files are kept
"""
user_defined_config = dict()
# Load the user defined configuration file
@ -935,13 +953,7 @@ def main(all_args):
user_defined_config = load_user_configuration(config_path)
environment = dict()
# Load all YAML files found in the env.d directory
env_plugins = os.path.join(config_path, 'env.d')
if os.path.isdir(env_plugins):
_extra_config(user_defined_config=environment, base_dir=env_plugins)
environment = load_environment(config_path)
# Load existing inventory file if found
dynamic_inventory_file = os.path.join(

View File

@ -268,6 +268,26 @@ class TestUserConfiguration(unittest.TestCase):
self.assertIsInstance(self.loaded_user_configuration, dict)
class TestEnvironments(unittest.TestCase):
def setUp(self):
self.longMessage = True
self.loaded_environment = di.load_environment(TARGET_DIR)
def test_loading_environment(self):
"""Test that the environment can be loaded"""
self.assertIsInstance(self.loaded_environment, dict)
def test_envd_read(self):
"""Test that the env.d contents are inserted into the environment"""
expected_keys = [
'component_skel',
'container_skel',
'physical_skel',
]
for key in expected_keys:
self.assertIn(key, self.loaded_environment)
class TestDuplicateIps(unittest.TestCase):
def setUp(self):
# Allow custom assertion errors.