diff --git a/robottelo/utils/virtwho.py b/robottelo/utils/virtwho.py index e159a487394..a904c79f138 100644 --- a/robottelo/utils/virtwho.py +++ b/robottelo/utils/virtwho.py @@ -214,10 +214,7 @@ def check_message_in_rhsm_log(message): delay=2, ) logs = get_rhsm_log() - for line in logs.split('\n'): - if message in line: - return message - return False + return any(message in line for line in logs.split('\n')) def _get_hypervisor_mapping(hypervisor_type): diff --git a/tests/foreman/virtwho/api/test_nutanix.py b/tests/foreman/virtwho/api/test_nutanix.py index e40433b1c57..33ce064c86f 100644 --- a/tests/foreman/virtwho/api/test_nutanix.py +++ b/tests/foreman/virtwho/api/test_nutanix.py @@ -241,7 +241,7 @@ def test_positive_ahv_internal_debug_option( assert str(exc_info.value) == env_error # check message exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert check_message_in_rhsm_log(message) == message + assert check_message_in_rhsm_log(message) # Update ahv_internal_debug option to true value = 'true' @@ -265,4 +265,4 @@ def test_positive_ahv_internal_debug_option( assert get_configure_option("ahv_internal_debug", config_file) == 'true' # check message does not exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert str(check_message_in_rhsm_log(message)) == 'False' + assert not check_message_in_rhsm_log(message) diff --git a/tests/foreman/virtwho/cli/test_esx_sca.py b/tests/foreman/virtwho/cli/test_esx_sca.py index 6b15b6803f9..782bac8e5cd 100644 --- a/tests/foreman/virtwho/cli/test_esx_sca.py +++ b/tests/foreman/virtwho/cli/test_esx_sca.py @@ -18,6 +18,7 @@ from robottelo.config import settings from robottelo.utils.virtwho import ( ETC_VIRTWHO_CONFIG, + check_message_in_rhsm_log, create_http_proxy, deploy_configure_by_command, deploy_configure_by_command_check, @@ -25,6 +26,8 @@ get_configure_file, get_configure_option, hypervisor_json_create, + restart_virtwho_service, + runcmd, virtwho_package_locked, ) @@ -502,3 +505,92 @@ def test_positive_remove_env_option( env_warning = f"Ignoring unknown configuration option \"{option}\"" result = target_sat.execute(f'grep "{env_warning}" /var/log/messages') assert result.status == 1 + + @pytest.mark.tier2 + def test_positive_rhsm_username_option( + self, module_sca_manifest_org, form_data_cli, target_sat + ): + """Verify rhsm_username options in the configure file" + + :id: 2d0d3126-859f-4092-9196-a553bc1d3bd9 + + :expectedresults: + 1. virt-who config belongs to the same org with the same rhsm_username + 2. virt-who config belongs to a different org with the different rhsm_username + 3. rhsm.log contains the correct orgs where hypervisors-guest mapping is sent to + 4. rhsm.log contains the correct account + 5. After deleting all virt-who config belong to the same org, verify that the rhsm user belong to this org has been deleted + :customerscenario: true + + :CaseImportance: Medium + + :BZ: 2063218 + """ + # create two virt-who configs in the same organization, get the service account rhsm_username + vc_id = [] + rhsm_username = [] + for _ in range(2): + form_data_cli['name'] = gen_string('alpha') + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label + ) + vc_id.append(virtwho_config_cli['id']) + config_file = get_configure_file(virtwho_config_cli['id']) + rhsm_username.append(get_configure_option('rhsm_username', config_file)) + + # verify the two service accounts belonging to the same org are the same + assert rhsm_username[0] == rhsm_username[1] + + # Create a different org virtwho_fake_XXXX and then create virt-who config in that org, get the service account rhsm_username + ORG_DATA = {'name': f'virtwho_fake_{gen_string("alpha")}'} + org = target_sat.api.Organization(name=ORG_DATA['name']).create() + target_sat.api.Location(organization=[org]).create() + form_data_cli['organization-id'] = org.id + form_data_cli['name'] = gen_string('alpha') + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + command = get_configure_command(virtwho_config_cli['id'], org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], debug=True, org=org.label + ) + config_file = get_configure_file(virtwho_config_cli['id']) + rhsm_username.append(get_configure_option('rhsm_username', config_file)) + vc_id.append(virtwho_config_cli['id']) + + # verify the two service accounts belonging to different orgs are different + assert rhsm_username[2] != rhsm_username[0] + + # Verify rhsm.log contains correct orgs to which hypervisor-guest mapping is sent to, and rhsm.log contains the correct user names. + runcmd(get_configure_command(vc_id[0], module_sca_manifest_org.name)) + runcmd(get_configure_command(vc_id[1], module_sca_manifest_org.name)) + service_account_message = [ + f"Authenticating with RHSM username {rhsm_username[0]}", + f"Authenticating with RHSM username {rhsm_username[2]}", + f"Host-to-guest mapping being sent to '{module_sca_manifest_org.name}'", + f"Host-to-guest mapping being sent to '{org.name}'", + ] + for item in service_account_message: + assert check_message_in_rhsm_log(item) + + # delete one of the virt-who configs belonging to module_sca_manifest_org, verify the other service account for that org still exists + # delete the other config in that org, verify the service account doesn't exist anymore + vd_ids = [vc_id[0], vc_id[1]] + messages = [ + f"Authenticating with RHSM username {rhsm_username[0]}", + f"Authenticating with RHSM username {rhsm_username[1]}", + ] + for index, id in enumerate(vd_ids): + target_sat.cli.VirtWhoConfig.delete({'id': id}) + config_file = get_configure_file(id) + runcmd(f"rm -f {config_file}") + if index == 0: + runcmd(get_configure_command(id, module_sca_manifest_org.name)) + assert check_message_in_rhsm_log(messages[0]) + elif index == 1: + restart_virtwho_service() + assert not check_message_in_rhsm_log(messages[1]) diff --git a/tests/foreman/virtwho/cli/test_nutanix.py b/tests/foreman/virtwho/cli/test_nutanix.py index b5478912ab7..8f6ea3796f5 100644 --- a/tests/foreman/virtwho/cli/test_nutanix.py +++ b/tests/foreman/virtwho/cli/test_nutanix.py @@ -216,7 +216,7 @@ def test_positive_ahv_internal_debug_option( assert str(exc_info.value) == env_error # check message exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert check_message_in_rhsm_log(message) == message + assert check_message_in_rhsm_log(message) # Update ahv_internal_debug option to true value = 'true' @@ -240,4 +240,4 @@ def test_positive_ahv_internal_debug_option( assert get_configure_option("ahv_internal_debug", config_file) == 'true' # check message does not exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert str(check_message_in_rhsm_log(message)) == 'False' + assert not check_message_in_rhsm_log(message) diff --git a/tests/foreman/virtwho/ui/test_nutanix.py b/tests/foreman/virtwho/ui/test_nutanix.py index 7ec05f191df..7c5b1765ed5 100644 --- a/tests/foreman/virtwho/ui/test_nutanix.py +++ b/tests/foreman/virtwho/ui/test_nutanix.py @@ -227,7 +227,7 @@ def test_positive_ahv_internal_debug_option( assert str(exc_info.value) == env_error # check message exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert check_message_in_rhsm_log(message) == message + assert check_message_in_rhsm_log(message) # Update ahv_internal_debug option to true org_session.virtwho_configure.edit(name, {'ahv_internal_debug': True}) @@ -245,4 +245,4 @@ def test_positive_ahv_internal_debug_option( assert get_configure_option("ahv_internal_debug", config_file) == 'true' # check message does not exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert str(check_message_in_rhsm_log(message)) == 'False' + assert not check_message_in_rhsm_log(message) diff --git a/tests/foreman/virtwho/ui/test_nutanix_sca.py b/tests/foreman/virtwho/ui/test_nutanix_sca.py index bb2483195d1..55fbfb6fc3f 100644 --- a/tests/foreman/virtwho/ui/test_nutanix_sca.py +++ b/tests/foreman/virtwho/ui/test_nutanix_sca.py @@ -195,7 +195,7 @@ def test_positive_ahv_internal_debug_option( assert str(exc_info.value) == env_error # check message exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert check_message_in_rhsm_log(message) == message + assert check_message_in_rhsm_log(message) # Update ahv_internal_debug option to true org_session.virtwho_configure.edit(name, {'ahv_internal_debug': True}) @@ -213,4 +213,4 @@ def test_positive_ahv_internal_debug_option( assert get_configure_option("ahv_internal_debug", config_file) == 'true' # check message does not exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' - assert str(check_message_in_rhsm_log(message)) == 'False' + assert not check_message_in_rhsm_log(message)