Merge "Added the cli confirmation for --yes flag"

This commit is contained in:
Zuul
2025-07-30 16:25:43 +00:00
committed by Gerrit Code Review
2 changed files with 75 additions and 3 deletions

View File

@@ -46,19 +46,29 @@ class SystemHostLockKeywords(BaseKeyword):
raise KeywordException("Lock host did not lock in the required time. Host values were: " f"Operational: {host_value.get_operational()} " f"Administrative: {host_value.get_administrative()} " f"Availability: {host_value.get_availability()}")
return True
def lock_host_with_error(self, host_name: str) -> str:
def lock_host_with_error(self, host_name: str, confirm_flag: bool = False) -> str:
"""
Locks the given host name. It's expected that the cmd returns error
Args:
host_name (str): the name of the host
confirm_flag (bool): whether to add --yes flag to bypass confirmation prompts
Returns:
str: a str of error message
"""
msg = self.ssh_connection.send(source_openrc(f"system host-lock {host_name}"))
return msg[0]
cmd = f"system host-lock {host_name}"
if confirm_flag:
cmd += " --yes"
output = self.ssh_connection.send(source_openrc(cmd))
# Handle empty output or return complete output
if not output:
return "No output received from lock command"
# Join all output lines to capture complete error message
return "\n".join(output) if isinstance(output, list) else str(output)
def wait_for_host_locked(self, host_name: str) -> bool:
"""

View File

@@ -5,6 +5,7 @@ from framework.ssh.prompt_response import PromptResponse
from framework.validation.validation import validate_str_contains
from keywords.cloud_platform.command_wrappers import source_openrc
from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords
from keywords.cloud_platform.system.host.system_host_lock_keywords import SystemHostLockKeywords
from keywords.cloud_platform.system.service.system_service_keywords import SystemServiceKeywords
@@ -71,3 +72,64 @@ def test_cli_with_confirmations_enabled(request: FixtureRequest):
get_logger().log_info("CLI confirmation prompt appeared and was handled correctly - operation cancelled")
get_logger().log_info("system host-lock confirmation test completed")
@mark.p1
def test_yes_flag_with_cli_disabled():
"""
Test system host-lock controller-5 --yes command with CLI confirmations disabled.
Verifies that --yes flag works properly when CLI confirmations are disabled.
"""
ssh_connection = LabConnectionKeywords().get_active_controller_ssh()
service_keywords = SystemServiceKeywords(ssh_connection)
get_logger().log_info("Ensuring CLI confirmations are disabled")
service_keywords.modify_service_parameter("platform", "client", "cli_confirmations", "disabled")
service_keywords.apply_service_parameters("platform")
# Exit from lab session to force fresh login for settings to take effect
get_logger().log_info("Exiting from lab session to force fresh login")
ssh_connection.send("exit")
ssh_connection.close()
# Create fresh SSH connection to test disabled confirmations
get_logger().log_info("Creating fresh SSH connection to test disabled confirmations")
ssh_connection = LabConnectionKeywords().get_active_controller_ssh()
get_logger().log_info("Testing system host-lock controller-5 command without confirmations")
# Use the keyword to lock host with --yes flag
host_lock_keywords = SystemHostLockKeywords(ssh_connection)
output_str = host_lock_keywords.lock_host_with_error("controller-5", confirm_flag=True)
get_logger().log_info(f"Command output: {output_str}")
# Validate that command executed (should get "host not found" message since controller-5 doesn't exist)
validate_str_contains(output_str, "host not found", "Verify command executed and returned expected error message")
get_logger().log_info("system host-lock test without confirmation completed")
@mark.p2
def test_yes_flag_with_cli_enabled(request: FixtureRequest):
"""
Test --yes flag with CLI confirmations enabled using fixture.
Verifies that --yes flag bypasses confirmation prompts when CLI confirmations are enabled.
"""
# Call the enabled setup function directly
cli_confirmations_enabled(request)
ssh_connection = LabConnectionKeywords().get_active_controller_ssh()
get_logger().log_info("Testing --yes flag with confirmations enabled")
# Use the keyword to lock host with --yes flag
host_lock_keywords = SystemHostLockKeywords(ssh_connection)
output_str = host_lock_keywords.lock_host_with_error("controller-5", confirm_flag=True)
get_logger().log_info(f"Command output: {output_str}")
# Validate that command executed (should get "host not found" message since controller-5 doesn't exist)
validate_str_contains(output_str, "host not found", "Verify command executed and returned expected error message")
get_logger().log_info("--yes flag test with CLI enabled completed")