def test_base(self):
class MockGroup(MagicMock):
def __init__(self, name):
super(MockGroup, self).__init__()
self.name = name
hosts = []
vars = {}
def __repr__(self):
return str(self.name)
group_all = MockGroup("all")
compute = MockGroup("compute")
controller = MockGroup("controller")
ungrouped = MockGroup("ungrouped")
group_all.hosts = ['localhost']
compute.hosts = ['localhost']
compute.vars = {'localhost': {
"ansible_connection": "local",
"neutron_physical_interface_mappings": "vlan:enp0s8,"
"external:enp0s3",
"cinder_disk": "/dev/sdc"}}
controller.hosts = ['localhost']
controller.vars = {'localhost': {
"ansible_connection": "local"
}}
mocked_inv = MagicMock()
mocked_inv.groups = {'all': group_all,
'compute': compute,
'controller': controller,
'ungrouped': ungrouped}
mocked_dl = MagicMock()
inventory_path = "NonePath"
with patch.multiple('inventory.dynlxc', InventoryParser=mocked_inv,
DataLoader=mocked_dl):
res = dynlxc.read_inventory_file(inventory_path)
mocked_dl.assert_called_once_with()
assert "all" in res
assert "_meta" in res
assert "hostvars" in res["_meta"]
assert "groupvars" in res["_meta"]
assert "localhost" in res["all"]
assert "compute" in res
assert "localhost" in res["compute"]["hosts"]
评论列表
文章目录