Move network_entry function to top level
This change adds some minor testing around the build process for a network's dictionary. This function may be further refactored in the future, but this serves as a start for that work. Change-Id: I63506e863386bd91a59d10530f3e81a444692cf7
This commit is contained in:
parent
bb3ddb31c7
commit
3b6895be67
@ -526,28 +526,8 @@ def _load_optional_q(config, cidr_name):
|
||||
return ip_q
|
||||
|
||||
|
||||
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
bridge, net_type, net_mtu, user_config,
|
||||
is_ssh_address, is_container_address,
|
||||
static_routes):
|
||||
"""Process additional ip adds and append then to hosts as needed.
|
||||
|
||||
If the host is found to be "is_metal" it will be marked as "on_metal"
|
||||
and will not have an additionally assigned IP address.
|
||||
|
||||
:param key: ``str`` Component key name. This could be a group or a host
|
||||
name
|
||||
:param inventory: ``dict`` Living dictionary of inventory.
|
||||
:param ip_q: ``object`` build queue of IP addresses.
|
||||
:param q_name: ``str`` key to use in host vars for storage. May be blank.
|
||||
:param netmask: ``str`` netmask to use.
|
||||
:param interface: ``str`` interface name to set for the network.
|
||||
:param user_config: ``dict`` user defined configuration details.
|
||||
:param is_ssh_address: ``bol`` set this address as ansible_ssh_host.
|
||||
:param is_container_address: ``bol`` set this address to container_address.
|
||||
:param static_routes: ``list`` List containing static route dicts.
|
||||
"""
|
||||
def network_entry():
|
||||
def network_entry(is_metal, interface,
|
||||
bridge=None, net_type=None, net_mtu=None):
|
||||
"""Return a network entry for a container."""
|
||||
|
||||
# TODO(cloudnull) After a few releases this conditional should be
|
||||
@ -570,6 +550,29 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
|
||||
return _network
|
||||
|
||||
|
||||
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
bridge, net_type, net_mtu, user_config,
|
||||
is_ssh_address, is_container_address,
|
||||
static_routes):
|
||||
"""Process additional ip adds and append then to hosts as needed.
|
||||
|
||||
If the host is found to be "is_metal" it will be marked as "on_metal"
|
||||
and will not have an additionally assigned IP address.
|
||||
|
||||
:param key: ``str`` Component key name. This could be a group or a host
|
||||
name
|
||||
:param inventory: ``dict`` Living dictionary of inventory.
|
||||
:param ip_q: ``object`` build queue of IP addresses.
|
||||
:param q_name: ``str`` key to use in host vars for storage. May be blank.
|
||||
:param netmask: ``str`` netmask to use.
|
||||
:param interface: ``str`` interface name to set for the network.
|
||||
:param user_config: ``dict`` user defined configuration details.
|
||||
:param is_ssh_address: ``bol`` set this address as ansible_ssh_host.
|
||||
:param is_container_address: ``bol`` set this address to container_address.
|
||||
:param static_routes: ``list`` List containing static route dicts.
|
||||
"""
|
||||
|
||||
base_hosts = inventory['_meta']['hostvars']
|
||||
lookup = inventory.get(key, list())
|
||||
|
||||
@ -625,7 +628,13 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
# This should convert found addresses based on q_name + "_address"
|
||||
# and then build the network if its not found.
|
||||
if not is_metal and old_address not in networks:
|
||||
network = networks[old_address] = network_entry()
|
||||
network = networks[old_address] = network_entry(
|
||||
is_metal,
|
||||
interface,
|
||||
bridge,
|
||||
net_type,
|
||||
net_mtu
|
||||
)
|
||||
if old_address in container and container[old_address]:
|
||||
network['address'] = container.pop(old_address)
|
||||
elif not is_metal:
|
||||
@ -635,7 +644,13 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
|
||||
network['netmask'] = netmask
|
||||
elif is_metal:
|
||||
network = networks[old_address] = network_entry()
|
||||
network = networks[old_address] = network_entry(
|
||||
is_metal,
|
||||
interface,
|
||||
bridge,
|
||||
net_type,
|
||||
net_mtu
|
||||
)
|
||||
network['netmask'] = netmask
|
||||
if is_ssh_address or is_container_address:
|
||||
# Container physical host group
|
||||
|
@ -1029,5 +1029,20 @@ class TestConfigCheckFunctional(TestConfigCheckBase):
|
||||
self.assertEqual(context.exception.ip, '172.29.236.100')
|
||||
|
||||
|
||||
class TestNetworkEntry(unittest.TestCase):
|
||||
def test_all_args_filled(self):
|
||||
entry = di.network_entry(True, 'eth1', 'br-mgmt', 'my_type', '1700')
|
||||
|
||||
self.assertNotIn('interface', entry.keys())
|
||||
self.assertEqual(entry['bridge'], 'br-mgmt')
|
||||
self.assertEqual(entry['type'], 'my_type')
|
||||
self.assertEqual(entry['mtu'], '1700')
|
||||
|
||||
def test_container_dict(self):
|
||||
entry = di.network_entry(False, 'eth1', 'br-mgmt', 'my_type', '1700')
|
||||
|
||||
self.assertEqual(entry['interface'], 'eth1')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user