Add tests for the _net_address_search function
The _net_address_search function looks through the provider networks and sets a key to True if it's the main network. This commit adds tests around the conditionals found in the function. In practice, the keys that are used (is_ssh_address and is_container_address) are specified in the gate user_config files, but this function seems to be there to catch and correct errors. The 'else' clause from the 'for' loop was moved up, since logically it was the action that happened when the target key was not present. The 'else' clause made it re-loop, which was unnecessary. Change-Id: Ic5920f19c8e21e324aee9c5e11831fd2c2e2b21d
This commit is contained in:
@@ -667,7 +667,7 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
|
||||
|
||||
def _net_address_search(provider_networks, main_network, key):
|
||||
"""Set the key netwokr type to the main network if not specified.
|
||||
"""Set the key network type to the main network if not specified.
|
||||
|
||||
:param provider_networks: ``list`` Network list of ``dict``s
|
||||
:param main_network: ``str`` The name of the main network bridge.
|
||||
@@ -680,10 +680,7 @@ def _net_address_search(provider_networks, main_network, key):
|
||||
# Check for the key
|
||||
if p_net.get(key):
|
||||
break
|
||||
else:
|
||||
for pn in provider_networks:
|
||||
p_net = pn.get('network')
|
||||
if p_net:
|
||||
else:
|
||||
if p_net.get('container_bridge') == main_network:
|
||||
p_net[key] = True
|
||||
|
||||
|
||||
@@ -610,6 +610,33 @@ class TestStaticRouteConfig(TestConfigChecks):
|
||||
self.assertEqual(exception.message, self.expectedMsg)
|
||||
|
||||
|
||||
class TestNetAddressSearch(unittest.TestCase):
|
||||
def test_net_address_search_key_not_found(self):
|
||||
pns = [
|
||||
{'network': {'container_bridge': 'br-mgmt'}}
|
||||
]
|
||||
new_pns = di._net_address_search(pns, 'br-mgmt', 'is_ssh_address')
|
||||
|
||||
self.assertTrue(new_pns[0]['network']['is_ssh_address'])
|
||||
|
||||
def test_net_address_search_key_not_found_bridge_doesnt_match(self):
|
||||
pns = [
|
||||
{'network': {'container_bridge': 'lxcbr0'}}
|
||||
]
|
||||
new_pns = di._net_address_search(pns, 'br-mgmt', 'is_ssh_address')
|
||||
|
||||
self.assertNotIn('is_ssh_address', new_pns[0]['network'])
|
||||
|
||||
def test_net_address_search_key_found(self):
|
||||
pns = [
|
||||
{'network': {'container_bridge': 'br-mgmt',
|
||||
'is_ssh_address': True}}
|
||||
]
|
||||
new_pns = di._net_address_search(pns, 'br-mgmt', 'is_ssh_address')
|
||||
|
||||
self.assertEqual(pns, new_pns)
|
||||
|
||||
|
||||
class TestMultipleRuns(unittest.TestCase):
|
||||
def test_creating_backup_file(self):
|
||||
# Generate the initial inventory files
|
||||
|
||||
Reference in New Issue
Block a user