Skip to content

Commit

Permalink
feat(test): Adding docstrings to test_registration.py (CCT-670)
Browse files Browse the repository at this point in the history
  • Loading branch information
zpetrace committed Sep 18, 2024
1 parent 81b2d9d commit 7c632ec
Showing 1 changed file with 155 additions and 18 deletions.
173 changes: 155 additions & 18 deletions integration-tests/test_registration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
:casecomponent: insights-client
:requirement: RHSS-291297
:subsystemteam: sst_csi_client_tools
:caseautomation: Automated
:upstream: Yes
"""

import os
import pytest
import contextlib
Expand All @@ -9,7 +17,25 @@


def test_register(insights_client):
"""Test `insights-client --register` on an unregistered client"""
"""
:id: 5371018d-7b4a-4535-9bf9-7a7e60a9ee4a
:title: Test client registration
:description:
This test verifies that the --register command successfully registers
an unregistered client
:reference:
:tier: Tier 1
:steps:
1. Run insights-client with --register option
2. Verify the client successfully registered
3. Verify the report is successfully uploaded
:expectedresults:
1. The client attempts to register
2. The client is confirmed as registered and the output includes
"Starting to collect Insights data."
3. The output includes "Successfully uploaded report" and
"View the Red Hat Insights console."
"""
register_result = insights_client.run("--register")
assert conftest.loop_until(lambda: insights_client.is_registered)

Expand All @@ -19,8 +45,23 @@ def test_register(insights_client):


def test_register_auth_proxy(insights_client, test_config):
"""This test verifies that `insights-client --register` successfully
registers host when auth proxy is configured.
"""
:id: 1387745b-59a1-4a90-8f6d-dee2afa4723c
:title: Test register with auth proxy
:description:
This test verifies that the --register command successfully registers the
host when an authentication proxy is configured
:reference:
:tier: Tier 1
:steps:
1. Set the proxy configuration in the insights-client.conf file
2. Run the insights-client with --register option and verbose output
3. Verify the client is successfully registered
:expectedresults:
1. The proxy details are saved to the client config file
2. The client attempts to register, using the configured proxy
3. The client is confirmed as registered and the output includes
the proxy details (host,user) and 'Proxy Scheme'
"""
try:
proxy_host = test_config.get("auth_proxy", "host")
Expand All @@ -44,8 +85,23 @@ def test_register_auth_proxy(insights_client, test_config):


def test_register_noauth_proxy(insights_client, test_config):
"""This test verifies that `insights-client --register` successfully
registers host when no-auth proxy is configured.
"""
:id: cbde1ce7-97fc-48d4-85bb-955ca45c8862
:title: Test register with no-auth proxy
:description:
This test verifies that the --register command successfully registers the
host when a no-auth proxy is configured
:reference:
:tier: Tier 1
:steps:
1. Set the proxy configuration in the insights-client.conf file
2. Run the insights-client with --register option and verbose output
3. Verify the client is successfully registered
:expectedresults:
1. The proxy details are saved to the client config file
2. The client attempts to register, using the configured proxy
3. The client is confirmed as registered and the output includes
'CONF Proxy' and the no-auth proxy details
"""
try:
proxy_host = test_config.get("noauth_proxy", "host")
Expand All @@ -62,7 +118,26 @@ def test_register_noauth_proxy(insights_client, test_config):


def test_machineid_exists_only_when_registered(insights_client):
"""`machine-id` is only present when insights-client is registered."""
"""
:id: 27440051-e0d3-452e-b052-070cddf65aa1
:title: Test machine id exists only when registered
:description:
This test verifies that the machine ID file is created only when the client
is registered
:reference:
:tier: Tier 1
:steps:
1. Verify the client is not registered and machine id does not exist
2. Run the insights-client without registration
3. Register insights-client and check machine id
4. Unregister insights-client and confirm machine-id is removed
:expectedresults:
1. The client is not registered and machine id does not exist
2. The command fails with instructions to register in output and
machine id still does not exist
3. Client is successfully registered and machine id is present on the system
4. The client is successfully unregistered and machine id file is removed
"""
assert conftest.loop_until(lambda: not insights_client.is_registered)
assert not os.path.exists(MACHINE_ID_FILE)

Expand All @@ -82,7 +157,25 @@ def test_machineid_exists_only_when_registered(insights_client):


def test_machineid_changes_on_new_registration(insights_client):
"""machine-id content changes when insights-client is un- & registered."""
"""
:id: ada04c6f-c351-4018-92f0-f3f21b7d645a
:title: Test machine id changes on new registration
:description:
This test verifies that the machine id file contwnt changes when
the client is unregistered and then registered again
:reference:
:tier: Tier 1
:steps:
1. Register insights-client and store current machine id
2. Unregister the client
3. Register client again and check the machine id
:expectedresults:
1. Client is registered and machine id stored
2. Client successfully unregisters and machine is removed
3. After the registration on systems with version 3.3.16 and higher
the machine-id should stay the same, on lower versions the number
should change
"""
insights_client.register()
with open(MACHINE_ID_FILE, "r") as f:
machine_id_old = f.read()
Expand All @@ -102,12 +195,23 @@ def test_machineid_changes_on_new_registration(insights_client):


def test_double_registration(insights_client):
"""`--register` can be passed multiple times.
Even system that is already registered should allow the `--register` flag to be
passed in, without resulting in non-zero exit code.
This behavior has changed multiple times during the package lifetime.
"""
:id: b1cf2516-aab9-438d-b4c0-42182c84fde9
:title: Test double registration
:description:
This test verifies that the --register flag can be passed multiple
times on a system that is already registered without causing errors
:reference:
:tier: Tier 1
:steps:
1. Register insights-client and store its machine id
2. Run the --register command again on the registered system
3. Verify the machine id remains unchanged
:expectedresults:
1. System is registered and machine-id stored
2. The command does not fail and shows a message
'This host has already been registered'
3. The machine id stayed unchanged
"""
assert conftest.loop_until(lambda: not insights_client.is_registered)

Expand All @@ -134,10 +238,22 @@ def test_double_registration(insights_client):
)
def test_register_group_option(insights_client, legacy_upload_value):
"""
Bug https://issues.redhat.com/browse/RHINENG-7567 exists on both
production env and satellite env with legacy_upload=True.
With legacy_upload=False, "insights-client --register --group=tag"
works well on both envs.
:id: 5213a950-e66f-4749-8a76-66b6d4ed9aa5
:title: Test register with group option
:description:
This test verifies that the --register command works as expected when
--group option is used
:reference: https://issues.redhat.com/browse/RHINENG-7567
:tier: Tier 1
:steps:
1. Unregister the client if registered
2. Set the legacy_upload value and save the configuration
3. Run insights-client with --register and --group=tag options
:expectedresults:
1. Client is unregistered successfully
2. The configuration is updated successfully
3. The client is registered with the specified group and the return
code is 0
"""
# make sure the system is not registered to insights
with contextlib.suppress(Exception):
Expand All @@ -154,7 +270,28 @@ def test_register_group_option(insights_client, legacy_upload_value):


def test_registered_and_unregistered_files_are_created_and_deleted(insights_client):
"""'.registered and .unregistered file gets created and deleted"""
"""
:id: 6e692793-f9ae-4ccb-a9d6-813b6d9aa7c3
:title: Test files creation and deletion while registering and unregistering
:description:
This test verifies that the .registered file is created when the client
is registered and the .unregistered file is created when the client is
unregistered
:reference:
:tier: Tier 1
:steps:
1. Verify that the client is not registered and .registered file does not exist
2. Register the client and verify that the .registered file was created
and .unregistered does not appear
3. Unregistred the client and verify that .registered file was removed and
.unregistered file was created
:expectedresults:
1. Client is not registered and .registered file does not exist
2. The client registers and .registered file is created, .unregistered
does not exist
3. The client is unregistered, .registered file was removed and .unregistered
appears
"""
assert conftest.loop_until(lambda: not insights_client.is_registered)
assert not os.path.exists("/etc/insights-client/.registered")

Expand Down

0 comments on commit 7c632ec

Please sign in to comment.