def test_create_host_with_system_profile_sap_fact(api_create_or_update_host, api_get): system_profile = valid_system_profile() system_profile["sap_system"] = True host = minimal_host(system_profile=system_profile) # 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 = create_host_response["host"] response_status, response_data = api_get( f"{HOST_URL}/{created_host['id']}/system_profile") assert_response_status(response_status, 200) host_response = get_host_from_response(response_data) assert host_response["system_profile"] == host.system_profile assert host_response["system_profile"]["sap_system"] == system_profile[ "sap_system"]
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)
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)
def test_get_system_profile_of_host_that_does_not_have_system_profile( api_create_or_update_host, api_get): host = minimal_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 = create_host_response["host"] # verify system_profile is not included assert "system_profile" not in created_host response_status, response_data = api_get( f"{HOST_URL}/{created_host['id']}/system_profile") assert_response_status(response_status, 200) host_response = get_host_from_response(response_data) assert host_response["id"] == created_host["id"] assert host_response["system_profile"] == {}
def test_create_host_with_system_profile_with_different_cloud_providers( api_create_or_update_host, api_get, cloud_provider): host = minimal_host(system_profile={"cloud_provider": cloud_provider}) # 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 = create_host_response["host"] # verify system_profile is not included assert "system_profile" not in created_host response_status, response_data = api_get( f"{HOST_URL}/{created_host['id']}/system_profile") assert_response_status(response_status, 200) host_response = get_host_from_response(response_data) assert host_response["id"] == created_host["id"] assert host_response["system_profile"] == host.system_profile
def test_create_host_with_system_profile_and_query_with_branch_id( api_create_or_update_host, api_get): host = minimal_host(system_profile=valid_system_profile()) # 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 = create_host_response["host"] # verify system_profile is not included assert "system_profile" not in created_host response_status, response_data = api_get( f"{HOST_URL}/{created_host['id']}/system_profile", query_parameters={"branch_id": 1234}) assert_response_status(response_status, 200) host_response = get_host_from_response(response_data) assert host_response["id"] == created_host["id"] assert host_response["system_profile"] == host.system_profile
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)
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)
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)
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)
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)
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)
def test_create_host_with_system_profile_with_different_yum_urls( api_create_or_update_host, api_get, yum_url): system_profile = { "yum_repos": [{ "name": "repo1", "gpgcheck": True, "enabled": True, "base_url": yum_url }] } host = minimal_host(system_profile=system_profile) # 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 = create_host_response["host"] # verify system_profile is not included assert "system_profile" not in created_host response_status, response_data = api_get( f"{HOST_URL}/{created_host['id']}/system_profile") assert_response_status(response_status, 200) host_response = get_host_from_response(response_data) assert host_response["id"] == created_host["id"] assert host_response["system_profile"] == host.system_profile