openstack-ansible/tests/test_manage.py
Nolan Brubaker 18c9e1faee Add export host option for inventory-manage script
The export host option allows users to export their existing host
information for import into a third party system. The output is
'pivoted', so that the key is the host/container name, and the values
are the group memberships and hostvar information. Some top level
networking information, such as load balancer IP addresses, as well as
provider networks, are also provided.

Test scaffolding was added to ensure the export does what is intended.

The tox inventory environment was modified to do coverage testing of
both the dynamic_inventory.py and manage_inventory.py files. The
coverage data is erased between runs, since combined output lead to
incorrect results for dynamic_inventory.py.

Change-Id: I2caa5a0c070b12a74ac26334c63ac8d0de704042
2016-09-22 02:50:01 +00:00

54 lines
1.5 KiB
Python

#!/usr/bin/env python
import os
from os import path
import sys
import test_inventory
import unittest
MANAGE_DIR = path.join(os.getcwd(), 'scripts')
sys.path.append(MANAGE_DIR)
import manage_inventory as mi
class TestExportFunction(unittest.TestCase):
def setUp(self):
self.inv = test_inventory.get_inventory()
def tearDown(self):
test_inventory.cleanup()
def test_host_is_present(self):
host_inv = mi.export_host_info(self.inv)['hosts']
self.assertIn('aio1', host_inv.keys())
def test_groups_added(self):
host_inv = mi.export_host_info(self.inv)['hosts']
self.assertIn('groups', host_inv['aio1'].keys())
def test_variables_added(self):
host_inv = mi.export_host_info(self.inv)['hosts']
self.assertIn('hostvars', host_inv['aio1'].keys())
def test_number_of_hosts(self):
host_inv = mi.export_host_info(self.inv)['hosts']
self.assertEqual(len(self.inv['_meta']['hostvars']),
len(host_inv))
def test_all_information_added(self):
all_info = mi.export_host_info(self.inv)['all']
self.assertIn('provider_networks', all_info)
def test_all_lb_information(self):
all_info = mi.export_host_info(self.inv)['all']
inv_all = self.inv['all']['vars']
self.assertEqual(inv_all['internal_lb_vip_address'],
all_info['internal_lb_vip_address'])
if __name__ == '__main__':
unittest.main()