Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add insights-client test case for tags #293

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integration-tests/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import pathlib

HOST_DETAILS: str = "/var/lib/insights/host-details.json"
MACHINE_ID_FILE: str = "/etc/insights-client/machine-id"
TAGS_FILE = pathlib.Path("/etc/insights-client/tags.yaml")
91 changes: 91 additions & 0 deletions integration-tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
:casecomponent: insights-client
:requirement: RHSS-291297
:subsystemteam: sst_csi_client_tools
:caseautomation: Automated
:upstream: Yes
"""

import pytest
import conftest
import contextlib
import os
import yaml
from constants import TAGS_FILE

pytestmark = pytest.mark.usefixtures("register_subman")


def test_tags(insights_client, external_inventory, test_config):
"""
:id: 3e9d5b76-7065-4ade-8397-5854a8fef83b
:title: Test tags
:description:
Test how the tags generated, and check the tags on inventory
:reference:
:tier: Tier 1
steps:
1. Register insights-client, and check satellite related
tags on the inventory if the test env is satellte.

2. Run insights-client with the --group

3. Add a new tag in tags.yaml, and run insights-client,
then check the inventory
:expectedresults:
1. system is registered to insights, and there will be
satellite related tags supported by branch_info with
satellite env.

2. tags.yaml will be created with group option, and new tag
generated by tags.yaml

3. The new tag shows on inventory by modifying tags.yaml
"""
# Remove the tags.yaml if it exists
with contextlib.suppress(FileNotFoundError):
TAGS_FILE.unlink()

# Register insights
insights_client.register()
assert conftest.loop_until(lambda: insights_client.is_registered)

# When test env is satellite, check the tags from branch_info
# the tags from satellite are not generated by tags.yaml
if "satellite" in test_config.environment:
insights_client.run()
system_tags = external_inventory.this_system_tags()
for tag in system_tags:
assert tag["namespace"] == "satellite"
assert not TAGS_FILE.exists()

with contextlib.ExitStack() as stack:
# Run insights-client --group
insights_client.run("--group=first_tag")
stack.callback(os.remove, TAGS_FILE)
assert TAGS_FILE.exists()
with TAGS_FILE.open("r") as tags_yaml:
data_loaded = yaml.safe_load(tags_yaml)
assert data_loaded["group"] == "first_tag"

# Check new tag from inventory
system_tags = external_inventory.this_system_tags()
assert {
"namespace": "insights-client",
"key": "group",
"value": "first_tag",
} in system_tags

# Add new tag in tags.yaml file and check on inventory
with TAGS_FILE.open("r") as tags_yaml:
data_loaded = yaml.safe_load(tags_yaml)
data_loaded["add_by_file"] = "second_tag"
with TAGS_FILE.open("w") as tags_yaml:
yaml.dump(data_loaded, tags_yaml, default_flow_style=False)
insights_client.run()
system_tags = external_inventory.this_system_tags()
assert {
"namespace": "insights-client",
"key": "add_by_file",
"value": "second_tag",
} in system_tags
Loading