mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-07-25 00:44:35 +00:00
tests(inventory): cover existing ansible_connection and service selection
- Assert default_win_ansible_connection is not applied when the host already has ansible_connection. - Matching Service is used when SSH and WinRM LoadBalancer services co-exist. Signed-off-by: Geetika Kapoor <gkapoor@redhat.com>
This commit is contained in:
@@ -96,6 +96,34 @@ SVC_LB_SSH = merge_dicts(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
SVC_LB_SSH_2222 = merge_dicts(
|
||||||
|
SVC_LB_SSH,
|
||||||
|
{
|
||||||
|
"spec": {
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"protocol": "TCP",
|
||||||
|
"port": 2222,
|
||||||
|
"targetPort": 22,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
SVC_LB_WINRM_HTTPS_59861 = merge_dicts(
|
||||||
|
SVC_LB_WINRM_HTTPS,
|
||||||
|
{
|
||||||
|
"spec": {
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"protocol": "TCP",
|
||||||
|
"port": 59861,
|
||||||
|
"targetPort": 5986,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -155,3 +183,45 @@ def test_default_win_ansible_connection(
|
|||||||
else:
|
else:
|
||||||
assert hosts[host]["ansible_host"] == "10.10.10.10"
|
assert hosts[host]["ansible_host"] == "10.10.10.10"
|
||||||
assert hosts[host]["ansible_port"] is None
|
assert hosts[host]["ansible_port"] is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"default_win_ansible_connection,expected_port",
|
||||||
|
[
|
||||||
|
("winrm", 59861),
|
||||||
|
("ssh", 2222),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_default_win_ansible_connection_picks_service_by_protocol(
|
||||||
|
inventory,
|
||||||
|
hosts,
|
||||||
|
default_win_ansible_connection,
|
||||||
|
expected_port,
|
||||||
|
):
|
||||||
|
inventory._populate_inventory(
|
||||||
|
{
|
||||||
|
"default_hostname": "test",
|
||||||
|
"cluster_domain": "test.com",
|
||||||
|
"namespaces": {
|
||||||
|
"default": {
|
||||||
|
"vms": [],
|
||||||
|
"vmis": [WINDOWS_VMI_1],
|
||||||
|
"services": {
|
||||||
|
"testdomain": [
|
||||||
|
SVC_LB_SSH_2222,
|
||||||
|
SVC_LB_WINRM_HTTPS_59861,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InventoryOptions(
|
||||||
|
use_service=True,
|
||||||
|
default_win_ansible_connection=default_win_ansible_connection,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
host = f"{DEFAULT_NAMESPACE}-{WINDOWS_VMI_1['metadata']['name']}"
|
||||||
|
assert hosts[host]["ansible_connection"] == default_win_ansible_connection
|
||||||
|
assert hosts[host]["ansible_host"] == "192.168.1.100"
|
||||||
|
assert hosts[host]["ansible_port"] == expected_port
|
||||||
|
|||||||
@@ -120,6 +120,56 @@ def test_set_connection_if_windows(mocker, inventory, default_win_ansible_connec
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"existing_ansible_connection,default_win_ansible_connection,target_port",
|
||||||
|
[
|
||||||
|
("ssh", "winrm", 22),
|
||||||
|
("winrm", "ssh", 5986),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_respect_existing_ansible_connection(
|
||||||
|
mocker,
|
||||||
|
inventory,
|
||||||
|
existing_ansible_connection,
|
||||||
|
default_win_ansible_connection,
|
||||||
|
target_port,
|
||||||
|
):
|
||||||
|
mocker.patch.object(inventory, "_set_common_vars")
|
||||||
|
mocker.patch.object(inventory, "_is_windows", return_value=True)
|
||||||
|
set_ansible_host_and_port = mocker.patch.object(
|
||||||
|
inventory, "_set_ansible_host_and_port"
|
||||||
|
)
|
||||||
|
mocker.patch.object(
|
||||||
|
inventory.inventory,
|
||||||
|
"get_host",
|
||||||
|
return_value=mocker.Mock(
|
||||||
|
get_vars=mocker.Mock(
|
||||||
|
return_value={"ansible_connection": existing_ansible_connection}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
set_variable = mocker.patch.object(inventory.inventory, "set_variable")
|
||||||
|
|
||||||
|
hostname = "default-testvm"
|
||||||
|
vmi = {
|
||||||
|
"metadata": {"labels": {LABEL_KUBEVIRT_IO_DOMAIN: "testdomain"}},
|
||||||
|
"status": {"interfaces": [{"ipAddress": "1.1.1.1"}]},
|
||||||
|
}
|
||||||
|
service = {
|
||||||
|
"metadata": {"name": "testsvc"},
|
||||||
|
"spec": {"ports": [{"targetPort": target_port}]},
|
||||||
|
}
|
||||||
|
opts = InventoryOptions(
|
||||||
|
default_win_ansible_connection=default_win_ansible_connection
|
||||||
|
)
|
||||||
|
inventory._set_vars_from_vmi(hostname, vmi, {"testdomain": [service]}, opts)
|
||||||
|
|
||||||
|
set_variable.assert_not_called()
|
||||||
|
set_ansible_host_and_port.assert_called_once_with(
|
||||||
|
vmi, hostname, "1.1.1.1", service, opts
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"is_windows,target_port",
|
"is_windows,target_port",
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user