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,6 +526,31 @@ def _load_optional_q(config, cidr_name):
|
|||||||
return ip_q
|
return ip_q
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
# simplified. The container address checking that is ssh address
|
||||||
|
# is only being done to support old inventory.
|
||||||
|
|
||||||
|
if is_metal:
|
||||||
|
_network = dict()
|
||||||
|
else:
|
||||||
|
_network = {'interface': interface}
|
||||||
|
|
||||||
|
if bridge:
|
||||||
|
_network['bridge'] = bridge
|
||||||
|
|
||||||
|
if net_type:
|
||||||
|
_network['type'] = net_type
|
||||||
|
|
||||||
|
if net_mtu:
|
||||||
|
_network['mtu'] = net_mtu
|
||||||
|
|
||||||
|
return _network
|
||||||
|
|
||||||
|
|
||||||
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||||
bridge, net_type, net_mtu, user_config,
|
bridge, net_type, net_mtu, user_config,
|
||||||
is_ssh_address, is_container_address,
|
is_ssh_address, is_container_address,
|
||||||
@ -547,28 +572,6 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
|||||||
:param is_container_address: ``bol`` set this address to container_address.
|
:param is_container_address: ``bol`` set this address to container_address.
|
||||||
:param static_routes: ``list`` List containing static route dicts.
|
:param static_routes: ``list`` List containing static route dicts.
|
||||||
"""
|
"""
|
||||||
def network_entry():
|
|
||||||
"""Return a network entry for a container."""
|
|
||||||
|
|
||||||
# TODO(cloudnull) After a few releases this conditional should be
|
|
||||||
# simplified. The container address checking that is ssh address
|
|
||||||
# is only being done to support old inventory.
|
|
||||||
|
|
||||||
if is_metal:
|
|
||||||
_network = dict()
|
|
||||||
else:
|
|
||||||
_network = {'interface': interface}
|
|
||||||
|
|
||||||
if bridge:
|
|
||||||
_network['bridge'] = bridge
|
|
||||||
|
|
||||||
if net_type:
|
|
||||||
_network['type'] = net_type
|
|
||||||
|
|
||||||
if net_mtu:
|
|
||||||
_network['mtu'] = net_mtu
|
|
||||||
|
|
||||||
return _network
|
|
||||||
|
|
||||||
base_hosts = inventory['_meta']['hostvars']
|
base_hosts = inventory['_meta']['hostvars']
|
||||||
lookup = inventory.get(key, list())
|
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"
|
# This should convert found addresses based on q_name + "_address"
|
||||||
# and then build the network if its not found.
|
# and then build the network if its not found.
|
||||||
if not is_metal and old_address not in networks:
|
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]:
|
if old_address in container and container[old_address]:
|
||||||
network['address'] = container.pop(old_address)
|
network['address'] = container.pop(old_address)
|
||||||
elif not is_metal:
|
elif not is_metal:
|
||||||
@ -635,7 +644,13 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
|||||||
|
|
||||||
network['netmask'] = netmask
|
network['netmask'] = netmask
|
||||||
elif is_metal:
|
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
|
network['netmask'] = netmask
|
||||||
if is_ssh_address or is_container_address:
|
if is_ssh_address or is_container_address:
|
||||||
# Container physical host group
|
# Container physical host group
|
||||||
|
@ -1029,5 +1029,20 @@ class TestConfigCheckFunctional(TestConfigCheckBase):
|
|||||||
self.assertEqual(context.exception.ip, '172.29.236.100')
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user