Merge "Add tests for the _net_address_search function"

This commit is contained in:
Jenkins
2016-05-31 19:39:51 +00:00
committed by Gerrit Code Review
2 changed files with 29 additions and 5 deletions

View File

@@ -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

View File

@@ -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