Skip to content

Commit

Permalink
update loop&check message&duplicated code etc
Browse files Browse the repository at this point in the history
  • Loading branch information
yanpliu committed Mar 14, 2024
1 parent af59aa5 commit b8e7427
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 63 deletions.
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)
102 changes: 51 additions & 51 deletions tests/foreman/virtwho/cli/test_esx_sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,69 +529,69 @@ def test_positive_rhsm_username_option(
:BZ: 2063218
"""
# get the service account for the first virt-who config on module_sca_manifest_org
name_1 = form_data_cli['name']
virtwho_config_cli_1 = target_sat.cli.VirtWhoConfig.create(form_data_cli)[
'general-information'
]
config_file_1 = get_configure_file(virtwho_config_cli_1['id'])
command = get_configure_command(virtwho_config_cli_1['id'], module_sca_manifest_org.name)
deploy_configure_by_command(
command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label
)
rhsm_username_1 = get_configure_option('rhsm_username', config_file_1)
# create two virt-who config in the same organization, get the service account rhsm_username
vc_id = []
rhsm_username = []
for _i 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))

# create the second virt-who config and get the service account for the first virt-who config on module_sca_manifest_org
name_2 = gen_string('alpha')
form_data_cli['name'] = name_2
virtwho_config_cli_2 = target_sat.cli.VirtWhoConfig.create(form_data_cli)[
'general-information'
]
config_file_2 = get_configure_file(virtwho_config_cli_2['id'])
command_2 = get_configure_command(virtwho_config_cli_2['id'], module_sca_manifest_org.name)
deploy_configure_by_command(
command_2, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label
)
rhsm_username_2 = get_configure_option('rhsm_username', config_file_2)
# verify the two service account belong to the same org
assert rhsm_username_1 == rhsm_username_2
# Create a different org and then create virt-who config
# verify the two service account belong 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, 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_3 = target_sat.cli.VirtWhoConfig.create(form_data_cli)[
virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[
'general-information'
]
command = get_configure_command(virtwho_config_cli_3['id'], org.name)
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_3 = get_configure_file(virtwho_config_cli_3['id'])
rhsm_username_3 = get_configure_option('rhsm_username', config_file_3)
assert rhsm_username_3 != rhsm_username_1
# hypervisors and guest mapping info send by group of org and service account exist in rhsm.log
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 account belong to the different org are different
assert rhsm_username[2] != rhsm_username[0]

# Verify virt-who config with the same service account send hypervisors and guest mapping info in the same organization section, and service account exist in rhsm.log
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_1}",
f"Authenticating with RHSM username {rhsm_username_3}",
f"Host-to-guest mapping being sent to '{module_sca_manifest_org}'",
f"Host-to-guest mapping being sent to '{org}'",
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:
check_message_in_rhsm_log(item)
# delete one of the virt-who config on module_sca_manifest_org, verify service account rhsm_username_1 exit
target_sat.cli.VirtWhoConfig.delete({'name': name_1})
runcmd(command_2)
runcmd(f"rm -f {config_file_1}")
target_sat.cli.VirtWhoConfig.info({'name': name_2})
restart_virtwho_service()
message = f"Authenticating with RHSM username {rhsm_username_2}"
assert check_message_in_rhsm_log(message) == message

# delete all the virt-who config on module_sca_manifest_org, verify service account rhsm_username_1 does not exit
target_sat.cli.VirtWhoConfig.delete({'name': name_2})
runcmd(f"rm -f {config_file_2}")
assert check_message_in_rhsm_log(item)

# delete one of the virt-who config belong to module_sca_manifest_org, verify service account rhsm_username_1 exist
target_sat.cli.VirtWhoConfig.delete({'id': vc_id[0]})
config_file = get_configure_file(vc_id[0])
runcmd(f"rm -f {config_file}")
runcmd(get_configure_command(vc_id[1], module_sca_manifest_org.name))
message = f"Authenticating with RHSM username {rhsm_username[0]}"
assert check_message_in_rhsm_log(message)

# delete all the virt-who config belong to module_sca_manifest_org, verify service account rhsm_username_1 does not exist
target_sat.cli.VirtWhoConfig.delete({'id': vc_id[1]})
config_file = get_configure_file(vc_id[1])
runcmd(f"rm -f {config_file}")
restart_virtwho_service()
message = f"Authenticating with RHSM username {rhsm_username_1}"
assert check_message_in_rhsm_log(message) is False
message = f"Authenticating with RHSM username {rhsm_username[1]}"
assert not check_message_in_rhsm_log(message)
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)

0 comments on commit b8e7427

Please sign in to comment.