Esempio n. 1
0
def test_create_host_without_display_name_and_with_fqdn(
        api_create_or_update_host, api_get):
    """
    This test should verify that the display_name is set to the
    fqdn when a display_name is not passed in but the fqdn is passed in.
    """
    expected_display_name = "fred.flintstone.bedrock.com"

    host = minimal_host(fqdn=expected_display_name)
    del host.display_name

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    host.display_name = expected_display_name

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 2
0
def test_create_host_without_display_name_and_without_fqdn(
        api_create_or_update_host, api_get):
    """
    This test should verify that the display_name is set to the id
    when neither the display name or fqdn is set.
    """
    host = minimal_host()
    del host.display_name
    del host.fqdn

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 3
0
def test_create_host_with_20_byte_mac_address(api_create_or_update_host,
                                              api_get):
    system_profile = {
        "network_interfaces": [{
            "mac_address":
            "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33"
        }]
    }

    host = minimal_host(system_profile=system_profile)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 4
0
def test_create_host_update_with_same_insights_id_and_different_canonical_facts(
        api_create_or_update_host, api_get):
    original_insights_id = generate_uuid()

    host = minimal_host(
        insights_id=original_insights_id,
        rhel_machine_id=generate_uuid(),
        subscription_manager_id=generate_uuid(),
        satellite_id=generate_uuid(),
        bios_uuid=generate_uuid(),
        fqdn="original_fqdn",
        mac_addresses=["aa:bb:cc:dd:ee:ff"],
        external_id="abcdef",
    )

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    # Change the canonical facts except for the insights_id
    host.rhel_machine_id = generate_uuid()
    host.ip_addresses = ["192.168.1.44", "10.0.0.2"]
    host.subscription_manager_id = generate_uuid()
    host.satellite_id = generate_uuid()
    host.bios_uuid = generate_uuid()
    host.fqdn = "expected_fqdn"
    host.mac_addresses = ["ff:ee:dd:cc:bb:aa"]
    host.external_id = "fedcba"
    host.facts = [{"namespace": "ns1", "facts": {"newkey": "newvalue"}}]

    # Update the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    update_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_updated(create_host_response, update_host_response)

    # Retrieve the host using the id that we first received
    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 5
0
def test_create_and_update_multiple_hosts_with_different_accounts(
        api_create_or_update_host, monkeypatch):
    monkeypatch.setenv("INVENTORY_SHARED_SECRET", SHARED_SECRET)

    host1 = minimal_host(display_name="host1",
                         account="111111",
                         ip_addresses=["10.0.0.1"],
                         rhel_machine_id=generate_uuid())
    host2 = minimal_host(display_name="host2",
                         account="222222",
                         ip_addresses=["10.0.0.2"],
                         rhel_machine_id=generate_uuid())
    host_list = [host1, host2]

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        host_list, auth_type="token")

    assert_response_status(multi_response_status, 207)

    assert len(host_list) == len(multi_response_data["data"])
    assert multi_response_data["total"] == len(multi_response_data["data"])
    assert multi_response_status, multi_response_data["errors"] == 0

    for i, host in enumerate(host_list):
        create_host_response = get_host_from_multi_response(
            multi_response_data, host_index=i)

        assert_host_was_created(create_host_response)

        host_list[i].id = create_host_response["host"]["id"]

    host_list[0].bios_uuid = generate_uuid()
    host_list[0].display_name = "fred"

    host_list[1].bios_uuid = generate_uuid()
    host_list[1].display_name = "barney"

    # Update the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        host_list, auth_type="token")

    assert_response_status(multi_response_status, 207)

    for i, host in enumerate(host_list):
        update_host_response = get_host_from_multi_response(
            multi_response_data, host_index=i)

        assert_host_response_status(update_host_response, expected_status=200)
        assert_host_data(actual_host=update_host_response["host"],
                         expected_host=host_list[i],
                         expected_id=host_list[i].id)
Esempio n. 6
0
def test_create_host_with_empty_facts_display_name_then_update(
        api_create_or_update_host, api_get):
    # Create a host with empty facts, and display_name
    # then update those fields
    host = minimal_host()
    del host.display_name
    del host.facts

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    # Update the facts and display name
    host.facts = copy.deepcopy(FACTS)
    host.display_name = "expected_display_name"

    # Update the hosts
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    update_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_updated(create_host_response, update_host_response)

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 7
0
def test_create_host_without_ansible_host_then_update(
        api_create_or_update_host, api_get, ansible_host):
    # Create a host without ansible_host field
    # then update those fields
    host = minimal_host()
    del host.ansible_host

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    host.ansible_host = ansible_host

    # Update the hosts
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    update_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_updated(create_host_response, update_host_response)

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 8
0
def test_create_host_with_ansible_host(api_create_or_update_host, api_get):
    # Create a host with ansible_host field
    host = minimal_host(ansible_host="ansible_host_" + generate_uuid())

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)

    created_host_id = create_host_response["host"]["id"]

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)
Esempio n. 9
0
def test_create_and_update(api_create_or_update_host, api_get):
    host = minimal_host(facts=FACTS)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    create_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_created(create_host_response)
    assert_host_data(actual_host=create_host_response["host"],
                     expected_host=host)

    created_host_id = create_host_response["host"]["id"]

    host.facts = copy.deepcopy(FACTS)
    # Replace facts under the first namespace
    host.facts[0]["facts"] = {"newkey1": "newvalue1"}
    # Add a new set of facts under a new namespace
    host.facts.append({"namespace": "ns2", "facts": {"key2": "value2"}})

    # Add a new canonical fact
    host.rhel_machine_id = generate_uuid()
    host.ip_addresses = ["10.10.0.1", "10.0.0.2", "fe80::d46b:2807:f258:c319"]
    host.mac_addresses = ["c2:00:d0:c8:61:01"]
    host.external_id = "i-05d2313e6b9a42b16"
    host.insights_id = generate_uuid()

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    update_host_response = get_host_from_multi_response(multi_response_data)

    assert_host_was_updated(create_host_response, update_host_response)
    assert_host_data(actual_host=update_host_response["host"],
                     expected_host=host)

    response_status, response_data = api_get(f"{HOST_URL}/{created_host_id}")

    assert_response_status(response_status, 200)

    host_response = get_host_from_response(response_data)

    assert_host_data(actual_host=host_response,
                     expected_host=host,
                     expected_id=created_host_id)