def test_get_machine_ids_one_host(mock_gethostbyname,):
    ip = "169.254.121.212"
    mock_gethostbyname.return_value = ip
    hostname = "fqdn1.example.org"
    hostnames = [hostname]
    expected = [{"hostname": hostname, "ip": ip}]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_one_host(mock_gethostbyname, ):
    ip = '169.254.121.212'
    mock_gethostbyname.return_value = ip
    hostname = 'fqdn1.example.org'
    hostnames = [hostname]
    expected = [{'hostname': hostname, 'ip': ip}]
    assert get_machine_ids(hostnames) == expected
def test_build_start_maintenance_payload(mock_gethostbyname,):
    ip = "169.254.121.212"
    mock_gethostbyname.return_value = ip
    hostname = "fqdn1.example.org"
    hostnames = [hostname]

    assert build_start_maintenance_payload(hostnames) == get_machine_ids(hostnames)
def test_get_machine_ids_multiple_hosts(
    mock_gethostbyname,
):
    ip1 = '169.254.121.212'
    ip2 = '169.254.121.213'
    ip3 = '169.254.121.214'
    mock_gethostbyname.side_effect = [ip1, ip2, ip3]
    hostname1 = 'fqdn1.example.org'
    hostname2 = 'fqdn2.example.org'
    hostname3 = 'fqdn3.example.org'
    hostnames = [hostname1, hostname2, hostname3]
    expected = [
        {
            'hostname': hostname1,
            'ip': ip1
        },
        {
            'hostname': hostname2,
            'ip': ip2
        },
        {
            'hostname': hostname3,
            'ip': ip3
        }
    ]
    assert get_machine_ids(hostnames) == expected
def test_build_start_maintenance_payload(mock_gethostbyname, ):
    ip = '169.254.121.212'
    mock_gethostbyname.return_value = ip
    hostname = 'fqdn1.example.org'
    hostnames = [hostname]

    assert build_start_maintenance_payload(hostnames) == get_machine_ids(
        hostnames)
def test_get_machine_ids_multiple_hosts_ips():
    ip1 = "169.254.121.212"
    ip2 = "169.254.121.213"
    ip3 = "169.254.121.214"
    hostname1 = "fqdn1.example.org"
    hostname2 = "fqdn2.example.org"
    hostname3 = "fqdn3.example.org"
    hostnames = [hostname1 + "|" + ip1, hostname2 + "|" + ip2, hostname3 + "|" + ip3]
    expected = [
        {"hostname": hostname1, "ip": ip1},
        {"hostname": hostname2, "ip": ip2},
        {"hostname": hostname3, "ip": ip3},
    ]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_one_host(
    mock_gethostbyname,
):
    ip = '169.254.121.212'
    mock_gethostbyname.return_value = ip
    hostname = 'fqdn1.example.org'
    hostnames = [hostname]
    expected = [
        {
            'hostname': hostname,
            'ip': ip
        }
    ]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_multiple_hosts(mock_gethostbyname,):
    ip1 = "169.254.121.212"
    ip2 = "169.254.121.213"
    ip3 = "169.254.121.214"
    mock_gethostbyname.side_effect = [ip1, ip2, ip3]
    hostname1 = "fqdn1.example.org"
    hostname2 = "fqdn2.example.org"
    hostname3 = "fqdn3.example.org"
    hostnames = [hostname1, hostname2, hostname3]
    expected = [
        {"hostname": hostname1, "ip": ip1},
        {"hostname": hostname2, "ip": ip2},
        {"hostname": hostname3, "ip": ip3},
    ]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_multiple_hosts(mock_gethostbyname, ):
    ip1 = '169.254.121.212'
    ip2 = '169.254.121.213'
    ip3 = '169.254.121.214'
    mock_gethostbyname.side_effect = [ip1, ip2, ip3]
    hostname1 = 'fqdn1.example.org'
    hostname2 = 'fqdn2.example.org'
    hostname3 = 'fqdn3.example.org'
    hostnames = [hostname1, hostname2, hostname3]
    expected = [{
        'hostname': hostname1,
        'ip': ip1
    }, {
        'hostname': hostname2,
        'ip': ip2
    }, {
        'hostname': hostname3,
        'ip': ip3
    }]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_multiple_hosts_ips():
    ip1 = '169.254.121.212'
    ip2 = '169.254.121.213'
    ip3 = '169.254.121.214'
    hostname1 = 'fqdn1.example.org'
    hostname2 = 'fqdn2.example.org'
    hostname3 = 'fqdn3.example.org'
    hostnames = [
        hostname1 + '|' + ip1, hostname2 + '|' + ip2, hostname3 + '|' + ip3
    ]
    expected = [{
        'hostname': hostname1,
        'ip': ip1
    }, {
        'hostname': hostname2,
        'ip': ip2
    }, {
        'hostname': hostname3,
        'ip': ip3
    }]
    assert get_machine_ids(hostnames) == expected
def test_get_machine_ids_multiple_hosts_ips():
    ip1 = '169.254.121.212'
    ip2 = '169.254.121.213'
    ip3 = '169.254.121.214'
    hostname1 = 'fqdn1.example.org'
    hostname2 = 'fqdn2.example.org'
    hostname3 = 'fqdn3.example.org'
    hostnames = [hostname1 + '|' + ip1, hostname2 + '|' + ip2, hostname3 + '|' + ip3]
    expected = [
        {
            'hostname': hostname1,
            'ip': ip1
        },
        {
            'hostname': hostname2,
            'ip': ip2
        },
        {
            'hostname': hostname3,
            'ip': ip3
        }
    ]
    assert get_machine_ids(hostnames) == expected