diff --git a/playbooks/inventory/dynamic_inventory.py b/playbooks/inventory/dynamic_inventory.py index 96aa32472c..b0b7f48912 100755 --- a/playbooks/inventory/dynamic_inventory.py +++ b/playbooks/inventory/dynamic_inventory.py @@ -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 diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 4e15c3941b..f6ed904698 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -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