|
|
@ -24,7 +24,7 @@ from ansible.inventory.data import InventoryData
|
|
|
|
from ansible.template import Templar
|
|
|
|
from ansible.template import Templar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
@pytest.fixture()
|
|
|
|
def inventory_module():
|
|
|
|
def inventory_module():
|
|
|
|
r = InventoryModule()
|
|
|
|
r = InventoryModule()
|
|
|
|
r.inventory = InventoryData()
|
|
|
|
r.inventory = InventoryData()
|
|
|
@ -60,13 +60,11 @@ def test_keyed_group_separator(inventory_module):
|
|
|
|
{
|
|
|
|
{
|
|
|
|
'prefix': 'farmer',
|
|
|
|
'prefix': 'farmer',
|
|
|
|
'separator': '_old_',
|
|
|
|
'separator': '_old_',
|
|
|
|
'key': 'farmer',
|
|
|
|
'key': 'farmer'
|
|
|
|
'unsafe': True
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
'separator': 'mmmmmmmmmm',
|
|
|
|
'separator': 'mmmmmmmmmm',
|
|
|
|
'key': 'barn',
|
|
|
|
'key': 'barn'
|
|
|
|
'unsafe': True
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
inventory_module._add_host_to_keyed_groups(
|
|
|
|
inventory_module._add_host_to_keyed_groups(
|
|
|
@ -78,6 +76,22 @@ def test_keyed_group_separator(inventory_module):
|
|
|
|
assert group.hosts == [host]
|
|
|
|
assert group.hosts == [host]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_keyed_group_empty_construction(inventory_module):
|
|
|
|
|
|
|
|
inventory_module.inventory.add_host('farm')
|
|
|
|
|
|
|
|
inventory_module.inventory.set_variable('farm', 'barn', {})
|
|
|
|
|
|
|
|
host = inventory_module.inventory.get_host('farm')
|
|
|
|
|
|
|
|
keyed_groups = [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
'separator': 'mmmmmmmmmm',
|
|
|
|
|
|
|
|
'key': 'barn'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
inventory_module._add_host_to_keyed_groups(
|
|
|
|
|
|
|
|
keyed_groups, host.vars, host.name, strict=True
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
assert host.groups == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_keyed_parent_groups(inventory_module):
|
|
|
|
def test_keyed_parent_groups(inventory_module):
|
|
|
|
inventory_module.inventory.add_host('web1')
|
|
|
|
inventory_module.inventory.add_host('web1')
|
|
|
|
inventory_module.inventory.add_host('web2')
|
|
|
|
inventory_module.inventory.add_host('web2')
|
|
|
|