diff options
author | Dan Radez <dradez@redhat.com> | 2016-08-23 20:22:26 -0400 |
---|---|---|
committer | Dan Radez <dradez@redhat.com> | 2016-08-24 14:02:23 -0400 |
commit | 3403334a7c1758bd81dafb3fad77470d91691580 (patch) | |
tree | abcbe2b8f80248ef97e1059bfc35c72d8b81ce18 /lib/python/apex | |
parent | 1895eba89b351b0f74a2280c023bbf799aa94e09 (diff) |
adding more network_environment.py tests
- increasing required test coverage to 90%
- also consolidating some repeated code into functions
Change-Id: I6b582478c509c24fce43224a516414e1ead6c8e4
Signed-off-by: Dan Radez <dradez@redhat.com>
Diffstat (limited to 'lib/python/apex')
-rw-r--r-- | lib/python/apex/network_environment.py | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/lib/python/apex/network_environment.py b/lib/python/apex/network_environment.py index d96fa44e..175f408f 100644 --- a/lib/python/apex/network_environment.py +++ b/lib/python/apex/network_environment.py @@ -42,6 +42,9 @@ API_RESOURCES = {'OS::TripleO::Network::InternalApi': None, IPV6_FLAGS = ["NovaIPv6", "MongoDbIPv6", "CorosyncIPv6", "CephIPv6", "RabbitIPv6", "MemcachedIPv6"] +reg = 'resource_registry' +param_def = 'parameter_defaults' + class NetworkEnvironment(dict): """ @@ -63,24 +66,10 @@ class NetworkEnvironment(dict): enabled_networks = net_settings.enabled_network_list except: raise NetworkEnvException('Invalid Network Setting object') - param_def = self['parameter_defaults'] - reg = self['resource_registry'] - if not net_settings: - raise NetworkEnvException("Network Settings does not exist") + self._set_tht_dir() enabled_networks = net_settings.get_enabled_networks() - param_def = 'parameter_defaults' - reg = 'resource_registry' - for key, prefix in TENANT_RESOURCES.items(): - if prefix is None: - prefix = '' - m = re.split('%s/\w+\.yaml' % prefix, self[reg][key]) - if m is not None: - tht_dir = m[0] - break - if not tht_dir: - raise NetworkEnvException('Unable to parse THT Directory') admin_cidr = net_settings[ADMIN_NETWORK]['cidr'] admin_prefix = str(admin_cidr.prefixlen) @@ -111,10 +100,8 @@ class NetworkEnvironment(dict): else: postfix = '/external.yaml' - for key, prefix in EXTERNAL_RESOURCES.items(): - if prefix is None: - prefix = '' - self[reg][key] = tht_dir + prefix + postfix + # apply resource registry update for EXTERNAL_RESOURCES + self._config_resource_reg(EXTERNAL_RESOURCES, postfix) if PRIVATE_NETWORK in enabled_networks: priv_range = net_settings[PRIVATE_NETWORK][ @@ -136,10 +123,8 @@ class NetworkEnvironment(dict): else: postfix = '/noop.yaml' - for key, prefix in TENANT_RESOURCES.items(): - if prefix is None: - prefix = '' - self[reg][key] = tht_dir + prefix + postfix + # apply resource registry update for TENANT_RESOURCES + self._config_resource_reg(TENANT_RESOURCES, postfix) if STORAGE_NETWORK in enabled_networks: storage_range = net_settings[STORAGE_NETWORK][ @@ -162,10 +147,8 @@ class NetworkEnvironment(dict): else: postfix = '/noop.yaml' - for key, prefix in STORAGE_RESOURCES.items(): - if prefix is None: - prefix = '' - self[reg][key] = tht_dir + prefix + postfix + # apply resource registry update for STORAGE_RESOURCES + self._config_resource_reg(STORAGE_RESOURCES, postfix) if API_NETWORK in enabled_networks: api_range = net_settings[API_NETWORK][ @@ -186,10 +169,8 @@ class NetworkEnvironment(dict): else: postfix = '/noop.yaml' - for key, prefix in API_RESOURCES.items(): - if prefix is None: - prefix = '' - self[reg][key] = tht_dir + prefix + postfix + # apply resource registry update for API_RESOURCES + self._config_resource_reg(API_RESOURCES, postfix) if compute_pre_config: self[reg][COMPUTE_PRE] = PRE_CONFIG_DIR + "compute/numa.yaml" @@ -203,6 +184,24 @@ class NetworkEnvironment(dict): for flag in IPV6_FLAGS: self[param_def][flag] = True + def _set_tht_dir(self): + self.tht_dir = None + for key, prefix in TENANT_RESOURCES.items(): + if prefix is None: + prefix = '' + m = re.split('%s/\w+\.yaml' % prefix, self[reg][key]) + if m is not None: + self.tht_dir = m[0] + break + if not self.tht_dir: + raise NetworkEnvException('Unable to parse THT Directory') + + def _config_resource_reg(self, resources, postfix): + for key, prefix in resources.items(): + if prefix is None: + prefix = '' + self[reg][key] = self.tht_dir + prefix + postfix + class NetworkEnvException(Exception): def __init__(self, value): |