mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Reformat everything.
This commit is contained in:
@@ -20,7 +20,7 @@ def inventory():
|
||||
|
||||
|
||||
def test_verify_file_bad_config(inventory):
|
||||
assert inventory.verify_file('foobar.icinga2.yml') is False
|
||||
assert inventory.verify_file("foobar.icinga2.yml") is False
|
||||
|
||||
|
||||
def check_api():
|
||||
@@ -33,58 +33,58 @@ def query_hosts(hosts=None, attrs=None, joins=None, host_filter=None):
|
||||
# _get_hosts - list of dicts
|
||||
json_host_data = [
|
||||
{
|
||||
'attrs': {
|
||||
'address': 'test-host1.home.local',
|
||||
'groups': ['home_servers', 'servers_dell'],
|
||||
'display_name': 'Test Host 1',
|
||||
'state': 0.0,
|
||||
'state_type': 1.0
|
||||
"attrs": {
|
||||
"address": "test-host1.home.local",
|
||||
"groups": ["home_servers", "servers_dell"],
|
||||
"display_name": "Test Host 1",
|
||||
"state": 0.0,
|
||||
"state_type": 1.0,
|
||||
},
|
||||
'joins': {},
|
||||
'meta': {},
|
||||
'name': 'test-host1',
|
||||
'type': 'Host'
|
||||
"joins": {},
|
||||
"meta": {},
|
||||
"name": "test-host1",
|
||||
"type": "Host",
|
||||
},
|
||||
{
|
||||
'attrs': {
|
||||
'address': 'test-host2.home.local',
|
||||
'display_name': 'Test Host 2',
|
||||
'groups': ['home_servers', 'servers_hp'],
|
||||
'state': 1.0,
|
||||
'state_type': 1.0
|
||||
"attrs": {
|
||||
"address": "test-host2.home.local",
|
||||
"display_name": "Test Host 2",
|
||||
"groups": ["home_servers", "servers_hp"],
|
||||
"state": 1.0,
|
||||
"state_type": 1.0,
|
||||
},
|
||||
'joins': {},
|
||||
'meta': {},
|
||||
'name': 'test-host2',
|
||||
'type': 'Host'
|
||||
"joins": {},
|
||||
"meta": {},
|
||||
"name": "test-host2",
|
||||
"type": "Host",
|
||||
},
|
||||
{
|
||||
'attrs': {
|
||||
'address': '',
|
||||
'display_name': 'Test Host 3',
|
||||
'groups': ['not_home_servers', 'servers_hp'],
|
||||
'state': 1.0,
|
||||
'state_type': 1.0
|
||||
"attrs": {
|
||||
"address": "",
|
||||
"display_name": "Test Host 3",
|
||||
"groups": ["not_home_servers", "servers_hp"],
|
||||
"state": 1.0,
|
||||
"state_type": 1.0,
|
||||
},
|
||||
'joins': {},
|
||||
'meta': {},
|
||||
'name': 'test-host3.example.com',
|
||||
'type': 'Host'
|
||||
}
|
||||
"joins": {},
|
||||
"meta": {},
|
||||
"name": "test-host3.example.com",
|
||||
"type": "Host",
|
||||
},
|
||||
]
|
||||
return json_host_data
|
||||
|
||||
|
||||
def get_option(option):
|
||||
if option == 'groups':
|
||||
if option == "groups":
|
||||
return {}
|
||||
elif option == 'keyed_groups':
|
||||
elif option == "keyed_groups":
|
||||
return []
|
||||
elif option == 'compose':
|
||||
elif option == "compose":
|
||||
return {}
|
||||
elif option == 'strict':
|
||||
elif option == "strict":
|
||||
return False
|
||||
elif option == 'group_by_hostgroups':
|
||||
elif option == "group_by_hostgroups":
|
||||
return True
|
||||
else:
|
||||
return None
|
||||
@@ -92,8 +92,8 @@ def get_option(option):
|
||||
|
||||
def test_populate(inventory, mocker):
|
||||
# module settings
|
||||
inventory.icinga2_user = 'ansible'
|
||||
inventory.icinga2_password = 'password'
|
||||
inventory.icinga2_user = "ansible"
|
||||
inventory.icinga2_password = "password"
|
||||
inventory.icinga2_url = "https://localhost:5665/v1"
|
||||
inventory.inventory_attr = "address"
|
||||
inventory.group_by_hostgroups = True
|
||||
@@ -105,46 +105,46 @@ def test_populate(inventory, mocker):
|
||||
inventory._populate()
|
||||
|
||||
# get different hosts
|
||||
host1_info = inventory.inventory.get_host('test-host1.home.local')
|
||||
host1_info = inventory.inventory.get_host("test-host1.home.local")
|
||||
print(host1_info)
|
||||
host2_info = inventory.inventory.get_host('test-host2.home.local')
|
||||
host2_info = inventory.inventory.get_host("test-host2.home.local")
|
||||
print(host2_info)
|
||||
host3_info = inventory.inventory.get_host('test-host3.example.com')
|
||||
assert inventory.inventory.get_host('test-host3.example.com') is not None
|
||||
host3_info = inventory.inventory.get_host("test-host3.example.com")
|
||||
assert inventory.inventory.get_host("test-host3.example.com") is not None
|
||||
print(host3_info)
|
||||
|
||||
# check if host in the home_servers group
|
||||
assert 'home_servers' in inventory.inventory.groups
|
||||
group1_data = inventory.inventory.groups['home_servers']
|
||||
assert "home_servers" in inventory.inventory.groups
|
||||
group1_data = inventory.inventory.groups["home_servers"]
|
||||
group1_test_data = [host1_info, host2_info]
|
||||
print(group1_data.hosts)
|
||||
print(group1_test_data)
|
||||
assert group1_data.hosts == group1_test_data
|
||||
# Test servers_hp group
|
||||
group2_data = inventory.inventory.groups['servers_hp']
|
||||
group2_data = inventory.inventory.groups["servers_hp"]
|
||||
group2_test_data = [host2_info, host3_info]
|
||||
print(group2_data.hosts)
|
||||
print(group2_test_data)
|
||||
assert group2_data.hosts == group2_test_data
|
||||
|
||||
# check if host state rules apply properly
|
||||
assert host1_info.get_vars()['state'] == 'on'
|
||||
assert host1_info.get_vars()['display_name'] == "Test Host 1"
|
||||
assert host2_info.get_vars()['state'] == 'off'
|
||||
assert host3_info.get_vars().get('ansible_host') is None
|
||||
assert host1_info.get_vars()["state"] == "on"
|
||||
assert host1_info.get_vars()["display_name"] == "Test Host 1"
|
||||
assert host2_info.get_vars()["state"] == "off"
|
||||
assert host3_info.get_vars().get("ansible_host") is None
|
||||
|
||||
# Confirm attribute options switcher
|
||||
inventory.inventory_attr = "name"
|
||||
inventory._populate()
|
||||
assert inventory.inventory.get_host('test-host3.example.com') is not None
|
||||
host2_info = inventory.inventory.get_host('test-host2')
|
||||
assert inventory.inventory.get_host("test-host3.example.com") is not None
|
||||
host2_info = inventory.inventory.get_host("test-host2")
|
||||
assert host2_info is not None
|
||||
assert host2_info.get_vars().get('ansible_host') == 'test-host2.home.local'
|
||||
assert host2_info.get_vars().get("ansible_host") == "test-host2.home.local"
|
||||
|
||||
# Confirm attribute options switcher
|
||||
inventory.inventory_attr = "display_name"
|
||||
inventory._populate()
|
||||
assert inventory.inventory.get_host('Test Host 3') is not None
|
||||
host2_info = inventory.inventory.get_host('Test Host 2')
|
||||
assert inventory.inventory.get_host("Test Host 3") is not None
|
||||
host2_info = inventory.inventory.get_host("Test Host 2")
|
||||
assert host2_info is not None
|
||||
assert host2_info.get_vars().get('ansible_host') == 'test-host2.home.local'
|
||||
assert host2_info.get_vars().get("ansible_host") == "test-host2.home.local"
|
||||
|
||||
Reference in New Issue
Block a user