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
This commit is contained in:
parent
be08d990ad
commit
d95eaf5996
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user