コード例 #1
0
def test_update_host_with_tags(db_create_host):
    insights_id = str(uuid.uuid4())
    old_tags = Tag("Sat", "env", "prod").to_nested()
    existing_host = db_create_host(
        extra_data={
            "canonical_facts": {
                "insights_id": insights_id
            },
            "display_name": "tagged",
            "tags": old_tags
        })

    assert existing_host.tags == old_tags

    # On update each namespace in the input host's tags should be updated.
    new_tags = Tag.create_nested_from_tags(
        [Tag("Sat", "env", "ci"),
         Tag("AWS", "env", "prod")])
    input_host = db_create_host(
        extra_data={
            "canonical_facts": {
                "insights_id": insights_id
            },
            "display_name": "tagged",
            "tags": new_tags
        })

    existing_host.update(input_host)

    assert existing_host.tags == new_tags
コード例 #2
0
def find_hosts_by_tag(account_number, string_tags, query):
    tags = []

    for string_tag in string_tags:
        tags.append(Tag().from_string(string_tag))

    tags_to_find = Tag.create_nested_from_tags(tags)

    return query.filter(Host.tags.contains(tags_to_find))
コード例 #3
0
def _find_hosts_by_tag(string_tags, query):
    logger.debug("_find_hosts_by_tag(%s)", string_tags)

    tags = []

    for string_tag in string_tags:
        tags.append(Tag.from_string(string_tag))

    tags_to_find = Tag.create_nested_from_tags(tags)

    return query.filter(Host.tags.contains(tags_to_find))
コード例 #4
0
def test_update_host_with_tags(flask_app_fixture):
    insights_id = str(uuid.uuid4())
    old_tags = Tag("Sat", "env", "prod").to_nested()
    existing_host = _create_host(insights_id=insights_id, display_name="tagged", tags=old_tags)

    assert existing_host.tags == old_tags

    # On update each namespace in the input host's tags should be updated.
    new_tags = Tag.create_nested_from_tags([Tag("Sat", "env", "ci"), Tag("AWS", "env", "prod")])
    input_host = _create_host(insights_id=insights_id, display_name="tagged", tags=new_tags)
    existing_host.update(input_host)

    assert existing_host.tags == new_tags
コード例 #5
0
def test_tag_deserialization():
    tags = [
        {"namespace": "Sat", "key": "env", "value": "prod"},
        {"namespace": "Sat", "key": "env", "value": "test"},
        {"namespace": "Sat", "key": "geo", "value": "somewhere"},
        {"namespace": "AWS", "key": "env", "value": "ci"},
        {"namespace": "AWS", "key": "env"},
    ]
    expected_tags = {"Sat": {"env": ["prod", "test"], "geo": ["somewhere"]}, "AWS": {"env": ["ci"]}}
    deserialized_tags = Tag.create_nested_from_tags(Tag.create_structered_tags_from_tag_data_list(tags))

    assert sorted(deserialized_tags["Sat"]["env"]) == sorted(expected_tags["Sat"]["env"])
    assert sorted(deserialized_tags["Sat"]["geo"]) == sorted(expected_tags["Sat"]["geo"])
    assert sorted(deserialized_tags["AWS"]["env"]) == sorted(expected_tags["AWS"]["env"])
コード例 #6
0
def _deserialize_tags(tags):
    # TODO: Move the deserialization logic to this method.
    return Tag.create_nested_from_tags(
        Tag.create_structered_tags_from_tag_data_list(tags))