Skip to content
Merged
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
77 changes: 77 additions & 0 deletions tests/foreman/cli/test_rhcloud_iop.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,80 @@ def test_insights_client_registration_with_http_proxy(
assert rhel_contenthost.execute('insights-client --test-connection').status == 0
assert rhel_contenthost.execute('insights-client --status').status == 0
assert rhel_contenthost.execute('insights-client --unregister').status == 0


def process_iop_log_options(installer_output):
"""Takes satellite-installer help output as input and returns a dictionary
with the options as keys and the descriptions of the options as values.
"""
options_dict = {}
for line in installer_output.split('\n'):
parts = line.split()
if parts:
option = parts[0]
description = ' '.join(parts[1:])
options_dict[option] = description
return options_dict


def test_set_iop_log_level_via_installer(module_satellite_iop):
"""Set IoP log level to DEBUG using satellite-installer options.

:id: 0268a6c1-56b5-4a0c-9df9-6c1b34f6cbd7

:steps:
1. Run `satellite-installer --full-help` to get the current IoP log levels.
2. Use satellite-installer to set all IoP log levels to DEBUG.
3. Use satellite-installer to reset all IoP log levels to defaults.

:expectedresults:
1. No IoP log levels are set to DEBUG by default.
2. All IoP log levels can be set to DEBUG using satellite-installer.
3. All IoP log levels can be reset to their default values using satellite-installer.

:Verifies: SAT-41750
"""
NEW_LOG_LEVEL = 'DEBUG'

# Retrieve the IoP log level settings from satellite-installer help output
help_command = InstallerCommand('full-help').get_command()
log_level_settings = module_satellite_iop.execute(
f'{help_command} | grep iop.*log-level | grep -v reset'
).stdout

# Process the log level options into a dictionary
settings_dict = process_iop_log_options(log_level_settings)

# Verify that no IoP log levels are set to DEBUG by default
assert NEW_LOG_LEVEL not in settings_dict.values()

# Use the installer to set all IoP log levels to DEBUG
command = InstallerCommand(
iop_core_engine_log_level_insights_core_dr=NEW_LOG_LEVEL,
iop_core_engine_log_level_insights_kafka_service=NEW_LOG_LEVEL,
iop_core_engine_log_level_insights_messaging=NEW_LOG_LEVEL,
iop_core_engine_log_level_root=NEW_LOG_LEVEL,
).get_command()
module_satellite_iop.execute(command)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (testing): Assert the success of satellite-installer commands instead of ignoring the exit status.

These module_satellite_iop.execute(command) calls for setting/resetting log levels should check the command result. Without asserting status == 0 (and optionally validating stderr), the test may continue after a failed installer invocation and yield misleading assertion failures later. Please assert on the execution result so the test fails immediately when the installer call itself fails.


# Verify that log levels are now DEBUG
new_log_level_settings = module_satellite_iop.execute(
f'{help_command} | grep iop.*log-level | grep -v reset'
).stdout
new_settings_dict = process_iop_log_options(new_log_level_settings)
for setting in new_settings_dict.values():
assert 'DEBUG' in setting

# Ensure log levels are reset to defaults
command = InstallerCommand(
'reset-iop-core-engine-log-level-insights-core-dr',
'reset-iop-core-engine-log-level-insights-kafka-service',
'reset-iop-core-engine-log-level-insights-messaging',
'reset-iop-core-engine-log-level-root',
).get_command()
module_satellite_iop.execute(command)
log_level_settings = module_satellite_iop.execute(
f'{help_command} | grep iop.*log-level | grep -v reset'
).stdout
settings_dict = process_iop_log_options(log_level_settings)
assert NEW_LOG_LEVEL not in settings_dict.values()
Loading