From d95eaf59966f48bc084332798977286b403b19b1 Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Mon, 1 Aug 2016 14:59:54 -0400 Subject: [PATCH] Add test for setting existing used IPs. The _set_used_ips function will traverse the IPs for each host already existing in inventory, but there was no targetted test for this functionality. This patch adds a fairly simple one to ensure code coverage. Change-Id: I8a4a62c387c6722d20b2450c78f7dd3f9718de99 --- tests/test_inventory.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 15eddd53cb..ff432672dc 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -965,5 +965,34 @@ class TestOverridingEnvIntegration(OverridingEnvBase): self.user_defined_config = None self.inv = None + +class TestSetUsedIPS(unittest.TestCase): + def setUp(self): + # Clean up the used ips in case other tests didn't. + di.USED_IPS = set() + + # Create a fake inventory just for this test. + self.inventory = {'_meta': {'hostvars': { + 'host1': {'container_networks': { + 'net': {'address': '172.12.1.1'} + }}, + 'host2': {'container_networks': { + 'net': {'address': '172.12.1.2'} + }}, + }}} + + def test_adding_inventory_used_ips(self): + config = {'used_ips': None} + + di._set_used_ips(config, self.inventory) + + self.assertEqual(len(di.USED_IPS), 2) + self.assertIn('172.12.1.1', di.USED_IPS) + self.assertIn('172.12.1.2', di.USED_IPS) + + def tearDown(self): + di.USED_IPS = set() + + if __name__ == '__main__': unittest.main()