Add platform_integ_apps update test case

Change-Id: Ie0358dd767d243726016a0265a38fd754a719a9a
Signed-off-by: Rity Menon <rity.menon@windriver.com>
This commit is contained in:
Rity Menon
2025-11-19 10:19:13 -08:00
parent 9cbb8300e3
commit 6db91c330b
3 changed files with 171 additions and 22 deletions

View File

@@ -133,7 +133,7 @@ class FileKeywords(BaseKeyword):
Args:
file_name (str): the full path and filename ex. /var/log/user.log.
grep_pattern (str): the pattern to use to filter lines ex. 'ptp4l\|phc2sys'.
grep_pattern (str): the pattern to use to filter lines ex. 'ptp4l\\|phc2sys'.
Returns:
list[str]: The output of the file.
@@ -289,6 +289,21 @@ class FileKeywords(BaseKeyword):
"""
self.ssh_connection.send_as_sudo(f"mv {old_file_name} {new_file_name}")
def move_file(self, source: str, destination: str, sudo: bool = False) -> None:
"""
Move file or directory from source to destination.
Args:
source (str): Source file or directory path.
destination (str): Destination file or directory path.
sudo (bool): Whether to use sudo privileges. Defaults to False.
"""
if sudo:
self.ssh_connection.send_as_sudo(f"mv {source} {destination}")
else:
self.ssh_connection.send(f"mv {source} {destination}")
self.validate_success_return_code(self.ssh_connection)
def rsync_to_remote_server(self, local_dest_path: str, remote_server: str, remote_user: str, remote_password: str, remote_path: str, recursive: bool = False, rsync_options: str = "") -> None:
"""
Rsync a file or directory to a remote server from the target host.

View File

@@ -0,0 +1,25 @@
from framework.logging.automation_logger import get_logger
from framework.ssh.ssh_connection import SSHConnection
class MountKeywords:
"""Keywords for Linux mount operations."""
def __init__(self, ssh_connection: SSHConnection):
"""
Initialize MountKeywords.
Args:
ssh_connection (SSHConnection): SSH connection to execute mount commands.
"""
self.ssh_connection = ssh_connection
def remount_read_write(self, mount_point: str) -> None:
"""
Remount a filesystem with read-write permissions.
Args:
mount_point (str): The mount point to remount (e.g., "/usr").
"""
get_logger().log_info(f"Remounting {mount_point} with read-write permissions")
self.ssh_connection.send_as_sudo(f"mount -o rw,remount {mount_point}")

View File

@@ -2,10 +2,6 @@ from pytest import FixtureRequest, mark
from config.configuration_manager import ConfigurationManager
from framework.logging.automation_logger import get_logger
from framework.resources.resource_finder import get_stx_resource_path
from framework.ssh.secure_transfer_file.secure_transfer_file import SecureTransferFile
from framework.ssh.secure_transfer_file.secure_transfer_file_enum import TransferDirection
from framework.ssh.secure_transfer_file.secure_transfer_file_input_object import SecureTransferFileInputObject
from framework.validation.validation import validate_equals, validate_not_equals
from keywords.ceph.ceph_status_keywords import CephStatusKeywords
from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords
@@ -20,6 +16,8 @@ from keywords.cloud_platform.system.application.system_application_remove_keywor
from keywords.cloud_platform.system.application.system_application_show_keywords import SystemApplicationShowKeywords
from keywords.cloud_platform.system.application.system_application_update_keywords import SystemApplicationUpdateKeywords
from keywords.cloud_platform.system.application.system_application_upload_keywords import SystemApplicationUploadKeywords
from keywords.files.file_keywords import FileKeywords
from keywords.linux.mount.mount_keywords import MountKeywords
def setup(request, active_ssh_connection):
@@ -145,11 +143,11 @@ def test_rollback_platform_integ_app(request: FixtureRequest):
# Copy original tarball from /home/sysadmin to base_application_path
get_logger().log_teardown_step("Copy original tarball to base application path")
active_ssh_connection.send_as_sudo(f"mv /home/sysadmin/platform-integ-app*.tgz {app_config.get_base_application_path()}")
FileKeywords(active_ssh_connection).move_file("/home/sysadmin/platform-integ-app*.tgz", app_config.get_base_application_path(), sudo=True)
# Move rollback tarball from base_application_path to /home/sysadmin
get_logger().log_teardown_step("Move rollback tarball to /home/sysadmin")
active_ssh_connection.send_as_sudo(f"mv {app_config.get_base_application_path()}{tarball_filename} /home/sysadmin/")
FileKeywords(active_ssh_connection).move_file(app_config.get_base_application_path() + tarball_filename, "/home/sysadmin/", sudo=True)
# Upload original version
system_application_upload_input = SystemApplicationUploadInput()
@@ -162,7 +160,7 @@ def test_rollback_platform_integ_app(request: FixtureRequest):
# Delete tarball file from /home/sysadmin
get_logger().log_teardown_step("Delete tarball file from /home/sysadmin")
active_ssh_connection.send_as_sudo(f"rm -f /home/sysadmin/{tarball_filename}")
FileKeywords(active_ssh_connection).delete_file(f"/home/sysadmin/{tarball_filename}")
else:
get_logger().log_teardown_step("No restore needed - version unchanged")
@@ -171,31 +169,21 @@ def test_rollback_platform_integ_app(request: FixtureRequest):
# Transfer tarball from local machine to /home/sysadmin
get_logger().log_test_case_step("Transfer rollback tarball from local machine to /home/sysadmin")
app_config = ConfigurationManager.get_app_config()
local_path = get_stx_resource_path(app_config.get_base_application_localhost())
tarball_filename = app_config.get_base_application_localhost().split("/")[-1]
temp_remote_path = f"/home/sysadmin/{tarball_filename}"
sftp_client = active_ssh_connection.get_sftp_client()
transfer_input = SecureTransferFileInputObject()
transfer_input.set_sftp_client(sftp_client)
transfer_input.set_origin_path(local_path)
transfer_input.set_destination_path(temp_remote_path)
transfer_input.set_transfer_direction(TransferDirection.FROM_LOCAL_TO_REMOTE)
transfer_input.set_force(True)
SecureTransferFile(transfer_input).transfer_file()
FileKeywords(active_ssh_connection).upload_file(app_config.get_base_application_localhost(), temp_remote_path)
# Mount /usr to be able to write the tarball
get_logger().log_test_case_step("Mount /usr with read-write permissions")
active_ssh_connection.send_as_sudo("mount -o rw,remount /usr")
MountKeywords(active_ssh_connection).remount_read_write("/usr")
# Copy platform_integ_app*.tgz from base_application_path to /home/sysadmin
get_logger().log_test_case_step("Move platform_integ_app*.tgz to /home/sysadmin")
active_ssh_connection.send_as_sudo(f"mv {app_config.get_base_application_path()}platform-integ-app*.tgz /home/sysadmin/")
FileKeywords(active_ssh_connection).move_file(f"{app_config.get_base_application_path()}platform-integ-app*.tgz", "/home/sysadmin/", sudo=True)
# Copy tarball from /home/sysadmin to base_application_path
get_logger().log_test_case_step("Move tarball to base application path")
active_ssh_connection.send_as_sudo(f"mv {temp_remote_path} {app_config.get_base_application_path()}")
FileKeywords(active_ssh_connection).move_file(temp_remote_path, app_config.get_base_application_path(), sudo=True)
# Rollback platform-integ-apps with tarball
get_logger().log_test_case_step("Rollback platform-integ-apps with tarball")
@@ -209,3 +197,124 @@ def test_rollback_platform_integ_app(request: FixtureRequest):
rollback_app_info = SystemApplicationShowKeywords(active_ssh_connection).get_system_application_show(platform_integ_apps_name)
rollback_version = rollback_app_info.get_system_application_object().get_version()
validate_not_equals(current_version, rollback_version, "Application version should have changed after rollback")
@mark.p2
def test_update_platform_integ_app(request: FixtureRequest):
"""
Update platform-integ-apps application.
Test Steps:
- Roll back the platform-integ-apps
- Remove tarball from application base path
- Copy tarball from /home/sysadmin to application base path
- Check if the application was upgraded
Args:
request (FixtureRequest): pytest request fixture for test setup and teardown
"""
active_ssh_connection = LabConnectionKeywords().get_active_controller_ssh()
platform_integ_apps_name = setup(request, active_ssh_connection)
def teardown():
get_logger().log_teardown_step("Test- Teardown: Check if restore needed")
# Check current version on system
current_app_info = SystemApplicationShowKeywords(active_ssh_connection).get_system_application_show(platform_integ_apps_name)
system_version = current_app_info.get_system_application_object().get_version()
if system_version != current_version:
get_logger().log_teardown_step("Restoring original platform-integ-apps version")
# Remove the rolled back version
system_application_remove_input = SystemApplicationRemoveInput()
system_application_remove_input.set_app_name(platform_integ_apps_name)
SystemApplicationRemoveKeywords(active_ssh_connection).system_application_remove(system_application_remove_input)
# Delete the rolled back version
system_application_delete_input = SystemApplicationDeleteInput()
system_application_delete_input.set_app_name(platform_integ_apps_name)
SystemApplicationDeleteKeywords(active_ssh_connection).get_system_application_delete(system_application_delete_input)
# Copy original tarball from /home/sysadmin to base_application_path
get_logger().log_teardown_step("Move original tarball to base application path")
FileKeywords(active_ssh_connection).move_file("/home/sysadmin/platform-integ-app*.tgz", app_config.get_base_application_path(), sudo=True)
# Move rollback tarball from base_application_path to /home/sysadmin
get_logger().log_teardown_step("Move rollback tarball to /home/sysadmin")
FileKeywords(active_ssh_connection).move_file(app_config.get_base_application_path() + tarball_filename, "/home/sysadmin/", sudo=True)
# Upload original version
system_application_upload_input = SystemApplicationUploadInput()
system_application_upload_input.set_app_name(platform_integ_apps_name)
system_application_upload_input.set_tar_file_path(f"{app_config.get_base_application_path()}platform-integ-app*.tgz")
SystemApplicationUploadKeywords(active_ssh_connection).system_application_upload(system_application_upload_input)
# Apply original version
SystemApplicationApplyKeywords(active_ssh_connection).system_application_apply(app_name=platform_integ_apps_name)
# Delete tarball file from /home/sysadmin
get_logger().log_teardown_step("Delete tarball file from /home/sysadmin")
FileKeywords(active_ssh_connection).delete_file(f"/home/sysadmin/{tarball_filename}")
else:
get_logger().log_teardown_step("No restore needed - version unchanged")
request.addfinalizer(teardown)
# Record current version before rollback
get_logger().log_test_case_step("Record current platform-integ-apps version")
current_app_info = SystemApplicationShowKeywords(active_ssh_connection).get_system_application_show(platform_integ_apps_name)
current_version = current_app_info.get_system_application_object().get_version()
# Transfer tarball from local machine to /home/sysadmin
get_logger().log_test_case_step("Transfer rollback tarball from local machine to /home/sysadmin")
app_config = ConfigurationManager.get_app_config()
tarball_filename = app_config.get_base_application_localhost().split("/")[-1]
temp_remote_path = f"/home/sysadmin/{tarball_filename}"
FileKeywords(active_ssh_connection).upload_file(app_config.get_base_application_localhost(), temp_remote_path)
# Mount /usr to be able to write the tarball
get_logger().log_test_case_step("Mount /usr with read-write permissions")
MountKeywords(active_ssh_connection).remount_read_write("/usr")
# Copy platform_integ_app*.tgz from base_application_path to /home/sysadmin
get_logger().log_test_case_step("Move platform_integ_app*.tgz to /home/sysadmin")
FileKeywords(active_ssh_connection).move_file(f"{app_config.get_base_application_path()}platform-integ-app*.tgz", "/home/sysadmin/", sudo=True)
# Copy tarball from /home/sysadmin to base_application_path
get_logger().log_test_case_step("Move tarball to base application path")
FileKeywords(active_ssh_connection).move_file(temp_remote_path, app_config.get_base_application_path(), sudo=True)
# Rollback platform-integ-apps with tarball
get_logger().log_test_case_step("Rollback platform-integ-apps with tarball")
system_application_update_input = SystemApplicationUpdateInput()
system_application_update_input.set_app_name(platform_integ_apps_name)
system_application_update_input.set_tar_file_path(f"{app_config.get_base_application_path()}{tarball_filename}")
SystemApplicationUpdateKeywords(active_ssh_connection).system_application_update(system_application_update_input)
# Verify the application version has changed (rollback)
get_logger().log_test_case_step("Verify platform-integ-apps version has changed after rollback")
rollback_app_info = SystemApplicationShowKeywords(active_ssh_connection).get_system_application_show(platform_integ_apps_name)
rollback_version = rollback_app_info.get_system_application_object().get_version()
validate_not_equals(current_version, rollback_version, "Application version should have changed after rollback")
# Remove tarball from application base path
get_logger().log_test_case_step("Remove tarball from application base path")
FileKeywords(active_ssh_connection).delete_file(f"{app_config.get_base_application_path()}{tarball_filename}")
# Move tarball from /home/sysadmin to base application path
get_logger().log_test_case_step("Copy tarball from /home/sysadmin to base application path")
FileKeywords(active_ssh_connection).move_file("/home/sysadmin/platform-integ-app*.tgz", app_config.get_base_application_path(), sudo=True)
# Update platform-integ-apps with new tarball
get_logger().log_test_case_step("Update platform-integ-apps with new tarball")
upgrade_tarball_path = f"{app_config.get_base_application_path()}platform-integ-app*.tgz"
system_application_update_input = SystemApplicationUpdateInput()
system_application_update_input.set_app_name(platform_integ_apps_name)
system_application_update_input.set_tar_file_path(upgrade_tarball_path)
SystemApplicationUpdateKeywords(active_ssh_connection).system_application_update(system_application_update_input)
# Check if the application was upgraded
get_logger().log_test_case_step("Check if the application was upgraded")
upgraded_app_info = SystemApplicationShowKeywords(active_ssh_connection).get_system_application_show(platform_integ_apps_name)
upgraded_version = upgraded_app_info.get_system_application_object().get_version()
validate_equals(upgraded_version, current_version, "Application version should match original version after upgrade")
get_logger().log_info(f"Application status after upgrade: {upgraded_app_info.get_system_application_object()}")