def test_system_profile_valid_date_format(mq_create_or_update_host, boot_time): system_profile = valid_system_profile() system_profile["owner_id"] = OWNER_ID system_profile["last_boot_time"] = boot_time host = minimal_host(system_profile=system_profile) mq_create_or_update_host(host)
def test_add_host_with_sap_system(event_datetime_mock, mq_create_or_update_host): expected_insights_id = generate_uuid() timestamp_iso = event_datetime_mock.isoformat() system_profile = valid_system_profile() system_profile["sap_system"] = True host = minimal_host(insights_id=expected_insights_id, system_profile=system_profile) expected_results = { "host": { **host.data() }, "platform_metadata": {}, "timestamp": timestamp_iso, "type": "created", } host_keys_to_check = [ "display_name", "insights_id", "account", "system_profile" ] key, event, headers = mq_create_or_update_host(host, return_all_data=True) assert_mq_host_data(key, event, expected_results, host_keys_to_check)
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_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_system_profile_invalid_date_format(mq_create_or_update_host, boot_time): system_profile = valid_system_profile() system_profile["owner_id"] = OWNER_ID system_profile["last_boot_time"] = boot_time host = minimal_host(system_profile=system_profile) with pytest.raises(ValidationException): mq_create_or_update_host(host)
def test_system_profile_includes_owner_id(mq_create_or_update_host, api_get, subtests): system_profile = valid_system_profile() host = minimal_host(system_profile=system_profile) created_host = mq_create_or_update_host(host) url = build_system_profile_url(host_list_or_id=created_host.id) response_status, response_data = api_get(url) assert response_data["results"][0]["system_profile"] == system_profile assert response_status == 200
def test_get_system_profile_of_multiple_hosts(api_create_or_update_host, api_get): host_id_list = [] expected_system_profiles = [] for i in range(2): system_profile = valid_system_profile() system_profile["number_of_cpus"] = i host = minimal_host(ip_addresses=[f"10.0.0.{i}"], 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"] host_id_list.append(created_host_id) expected_system_profiles.append({ "id": created_host_id, "system_profile": host.system_profile }) url_host_id_list = ",".join(host_id_list) test_url = f"{HOST_URL}/{url_host_id_list}/system_profile" response_status, response_data = api_get(test_url) assert_response_status(response_status, 200) assert len(expected_system_profiles) == len(response_data["results"]) for expected_system_profile in expected_system_profiles: assert expected_system_profile in response_data["results"]