-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add insights-clilent test case for tags
- Loading branch information
1 parent
125d22c
commit dc16fba
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
import conftest | ||
import contextlib | ||
import os | ||
import yaml | ||
|
||
pytestmark = pytest.mark.usefixtures("register_subman") | ||
|
||
|
||
def test_tags(insights_client, external_inventory, test_config): | ||
""" | ||
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 | ||
""" | ||
# Register insights | ||
insights_client.register() | ||
assert conftest.loop_until(lambda: insights_client.is_registered) | ||
|
||
# Remove the tags.yaml if it exists | ||
with contextlib.suppress(FileNotFoundError): | ||
os.remove("/etc/insights-client/tags.yaml") | ||
|
||
# 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 os.path.exists("/etc/insights-client/tags.yaml") | ||
|
||
# Run insights-client --group | ||
insights_client.run("--group=first_tag") | ||
assert os.path.exists("/etc/insights-client/tags.yaml") | ||
|
||
with open("/etc/insights-client/tags.yaml", "r") as tags_yaml: | ||
data_loaded = yaml.safe_load(tags_yaml) | ||
assert data_loaded["group"] == "first_tag" | ||
|
||
# Check new tag from inventory | ||
insights_client.run() | ||
system_tags = external_inventory.this_system_tags() | ||
assert system_tags[-1]["namespace"] == "insights-client" | ||
assert system_tags[-1]["key"] == "group" | ||
assert system_tags[-1]["value"] == "first_tag" | ||
|
||
# Add new tag in tags.yaml file and check on inventory | ||
with open("/etc/insights-client/tags.yaml", "r") as tags_yaml: | ||
data_loaded = yaml.safe_load(tags_yaml) | ||
data_loaded["add_by_file"] = "second_tag" | ||
with open("/etc/insights-client/tags.yaml", "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 system_tags[-1]["namespace"] == "insights-client" | ||
assert system_tags[-1]["key"] == "add_by_file" | ||
assert system_tags[-1]["value"] == "second_tag" |