Merge "Refactor user config loading into function"
This commit is contained in:
commit
6ff23113bd
@ -899,15 +899,12 @@ def _check_config_settings(cidr_networks, config, container_skel):
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the main application."""
|
||||
all_args = args()
|
||||
user_defined_config = dict()
|
||||
def load_user_configuration(config_path):
|
||||
"""Create a user configuration dictionary from config files
|
||||
|
||||
# Get the path to the user configuration files
|
||||
config_path = find_config_path(
|
||||
user_config_path=all_args.get('config')
|
||||
)
|
||||
:param config_path: ``str`` path where the configuration files are kept
|
||||
"""
|
||||
user_defined_config = dict()
|
||||
|
||||
# Load the user defined configuration file
|
||||
user_config_file = os.path.join(config_path, 'openstack_user_config.yml')
|
||||
@ -927,6 +924,18 @@ def main():
|
||||
'No openstack_user_config files are available in either \n%s'
|
||||
'\nor \n%s/conf.d directory' % (config_path, config_path)
|
||||
)
|
||||
return user_defined_config
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the main application."""
|
||||
all_args = args()
|
||||
# Get the path to the user configuration files
|
||||
config_path = find_config_path(
|
||||
user_config_path=all_args.get('config')
|
||||
)
|
||||
|
||||
user_defined_config = load_user_configuration(config_path)
|
||||
|
||||
environment = dict()
|
||||
|
||||
|
@ -5,6 +5,7 @@ import json
|
||||
import os
|
||||
from os import path
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
import yaml
|
||||
|
||||
@ -12,6 +13,10 @@ INV_DIR = 'playbooks/inventory'
|
||||
SCRIPT_FILENAME = 'dynamic_inventory.py'
|
||||
INV_SCRIPT = path.join(os.getcwd(), INV_DIR, SCRIPT_FILENAME)
|
||||
|
||||
sys.path.append(path.join(os.getcwd(), INV_DIR))
|
||||
|
||||
import dynamic_inventory as di
|
||||
|
||||
TARGET_DIR = path.join(os.getcwd(), 'tests', 'inventory')
|
||||
USER_CONFIG_FILE = path.join(TARGET_DIR, "openstack_user_config.yml")
|
||||
|
||||
@ -246,6 +251,16 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
|
||||
self.assertEqual(set(all_keys), set(self.inventory.keys()))
|
||||
|
||||
|
||||
class TestUserConfiguration(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.longMessage = True
|
||||
self.loaded_user_configuration = di.load_user_configuration(TARGET_DIR)
|
||||
|
||||
def test_loading_user_configuration(self):
|
||||
"""Test that the user configuration can be loaded"""
|
||||
self.assertIsInstance(self.loaded_user_configuration, dict)
|
||||
|
||||
|
||||
class TestDuplicateIps(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Allow custom assertion errors.
|
||||
|
Loading…
Reference in New Issue
Block a user