Skip to content

Commit

Permalink
[6.15.z] code coverage bug2063218 (SatelliteQE#15059)
Browse files Browse the repository at this point in the history
code coverage bug2063218 (SatelliteQE#14308)

* code coverage bug2063218

* update loop&check message&duplicated code etc

* Update the descriptions for expectresults

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Lukáš Hellebrandt <[email protected]>

* update code to fix repeating anti-pattern

* Update the comments

* Update robottelo/utils/virtwho.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Gaurav Talreja <[email protected]>

* Update tests/foreman/virtwho/cli/test_esx_sca.py

Co-authored-by: Gaurav Talreja <[email protected]>

---------

Co-authored-by: Lukáš Hellebrandt <[email protected]>
Co-authored-by: Gaurav Talreja <[email protected]>
(cherry picked from commit cc3c119)

Co-authored-by: yanpliu <[email protected]>
  • Loading branch information
Satellite-QE and yanpliu authored May 14, 2024
1 parent a4f183e commit fc920d5
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 12 deletions.
5 changes: 1 addition & 4 deletions robottelo/utils/virtwho.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,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):
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/virtwho/api/test_nutanix.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,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'
Expand All @@ -266,4 +266,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)
92 changes: 92 additions & 0 deletions tests/foreman/virtwho/cli/test_esx_sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
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,
get_configure_command,
get_configure_file,
get_configure_option,
hypervisor_json_create,
restart_virtwho_service,
runcmd,
virtwho_package_locked,
)

Expand Down Expand Up @@ -501,3 +504,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])
4 changes: 2 additions & 2 deletions tests/foreman/virtwho/cli/test_nutanix.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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'
Expand All @@ -241,4 +241,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)
4 changes: 2 additions & 2 deletions tests/foreman/virtwho/ui/test_nutanix.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,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})
Expand All @@ -246,4 +246,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)
4 changes: 2 additions & 2 deletions tests/foreman/virtwho/ui/test_nutanix_sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,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})
Expand All @@ -214,4 +214,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)

0 comments on commit fc920d5

Please sign in to comment.