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

code coverage bug2063218 #14308

Merged
merged 16 commits into from
May 14, 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
5 changes: 1 addition & 4 deletions robottelo/utils/virtwho.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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 @@ -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'
Expand All @@ -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)
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 @@ -18,13 +18,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 @@ -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:
yanpliu marked this conversation as resolved.
Show resolved Hide resolved
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}'",
Comment on lines +572 to +574
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single quotes wherever possible, to ensure consistency :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gauravtalreja1 Thank you very much for your suggestion, this used double quotes , it is because there is single quotes in the string, so used double quotes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yanpliu yes, but we can switch it with single quotes with double quotes inside, but I wouldn't block this PR merge for it

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])
yanpliu marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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'
Expand All @@ -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)
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 @@ -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})
Expand All @@ -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)
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 @@ -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})
Expand All @@ -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)
Loading