示例#1
0
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_add_host_with_tags(event_datetime_mock, mq_create_or_update_host):
    """
     Tests adding a host with message containing tags
    """
    expected_insights_id = generate_uuid()
    expected_tags = [
        {"namespace": "NS1", "key": "key3", "value": "val3"},
        {"namespace": "NS3", "key": "key2", "value": "val2"},
        {"namespace": "Sat", "key": "prod", "value": None},
        {"namespace": "Sat", "key": "dev", "value": ""},
        {"namespace": "Sat", "key": "test"},
        {"namespace": None, "key": "key", "value": "val1"},
        {"namespace": "", "key": "key", "value": "val4"},
        {"namespace": "null", "key": "key", "value": "val5"},
        {"namespace": None, "key": "only_key", "value": None},
        {"key": "just_key"},
        {"namespace": " \t\n\r\f\v", "key": " \t\n\r\f\v", "value": " \t\n\r\f\v"},
    ]
    timestamp_iso = event_datetime_mock.isoformat()

    host = minimal_host(insights_id=expected_insights_id, tags=expected_tags)

    expected_results = {
        "host": {**host.data()},
        "platform_metadata": {},
        "timestamp": timestamp_iso,
        "type": "created",
    }
    host_keys_to_check = ["display_name", "insights_id", "account"]

    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)

    assert len(event["host"]["tags"]) == len(expected_tags)
示例#3
0
def test_add_host_stale_timestamp(event_datetime_mock,
                                  mq_create_or_update_host):
    """
    Tests to see if the host is successfully created with both reporter
    and stale_timestamp set.
    """
    expected_insights_id = generate_uuid()
    timestamp_iso = event_datetime_mock.isoformat()
    stale_timestamp = now()

    host = minimal_host(insights_id=expected_insights_id,
                        stale_timestamp=stale_timestamp.isoformat())

    expected_results = {
        "host": {
            **host.data(),
            "stale_warning_timestamp":
            (stale_timestamp + timedelta(weeks=1)).isoformat(),
            "culled_timestamp":
            (stale_timestamp + timedelta(weeks=2)).isoformat(),
        },
        "platform_metadata": {},
        "timestamp": timestamp_iso,
        "type": "created",
    }

    host_keys_to_check = ["reporter", "stale_timestamp", "culled_timestamp"]

    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_add_host_simple(event_datetime_mock, mq_create_or_update_host):
    """
    Tests adding a host with some simple data
    """
    expected_insights_id = generate_uuid()
    timestamp_iso = event_datetime_mock.isoformat()

    host = minimal_host(insights_id=expected_insights_id)

    expected_results = {
        "host": {**host.data()},
        "platform_metadata": {},
        "timestamp": timestamp_iso,
        "type": "created",
    }

    host_keys_to_check = ["display_name", "insights_id", "account"]

    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)