USM:Added software list and software show keywords

Keywords for USM software list and software show commands added

JIRA:CGTS-74416
JIRA:CGTS-75185

Change-Id: Ic5a7a5a47bf301b5f5d17c0434ef1aaea07e4feb
Signed-off-by: Immaculate Shaloom <Shaloom.Immaculate@windriver.com>
This commit is contained in:
Immaculate Shaloom
2025-03-12 02:14:32 -04:00
parent cadeb11f01
commit 034b8e39f3
6 changed files with 287 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
class SoftwareListObject:
"""
Class to hold attributes of a software list as returned by software list command
"""
def __init__(
self,
release: str,
rr: str,
state: str,
):
self.release = release
self.rr = rr
self.state = state
def get_release(self) -> str:
"""
Get release
Returns:
(str): release object
"""
return self.release
def get_rr(self) -> str:
"""
Get rr
Returns:
(str): rr object
"""
return self.rr
def get_state(self) -> str:
"""
Get state
Returns:
(str): state object
"""
return self.state

View File

@@ -0,0 +1,89 @@
"""Software List Output."""
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
from keywords.cloud_platform.upgrade.objects.software_list_object import SoftwareListObject
class SoftwareListOutput:
"""
This class parses o/p 'software list' command into an object of
type SoftwareListObject.
"""
def __init__(self, software_list_output):
"""
Constructor
Args:
software_list_output (str): output of 'software list' command
"""
self.software_list: SoftwareListObject = []
system_table_parser = SystemTableParser(software_list_output)
self.output_values = system_table_parser.get_output_values_list()
for value in self.output_values:
software_list_object = SoftwareListObject(
value["Release"],
value["RR"],
value["State"],
)
self.software_list.append(software_list_object)
def get_software_lists(self) -> list[SoftwareListObject]:
"""
Get all software list objects.
Returns:
the list of software list objects
"""
return self.software_list
def get_software_list_details(self):
"""
Get software list details in a list of dictionaries.
Returns:
list of software list dict
"""
return self.output_values
def get_release_name_by_state(self, state):
"""
Get Release name of a release based in its state.
Args:
state: State of the release.
Returns:
list of release name.
"""
software_list_details = self.output_values
release_name = []
for j in range(len(software_list_details)):
if software_list_details[j]["State"] == state:
release_details = software_list_details[j]
release_name.append(release_details["Release"])
return release_name
def get_release_state_by_release_name(self, release_name):
"""
Get the Release State based on the release name.
Args:
release_name: name of the release.
Returns:
state of the release
"""
software_list_details = self.output_values
for j in range(len(software_list_details)):
for i in software_list_details:
if software_list_details[j]["Release"] == release_name:
release_details = software_list_details[j]
return release_details["State"]

View File

@@ -0,0 +1,32 @@
class SoftwareShowObject:
"""
Class to hold attributes of a software show as returned by
software show command
"""
def __init__(
self,
property: str,
value: str,
):
self.property = property
self.value = value
def get_property(self) -> str:
"""
Getter for property
Returns: the property
"""
return self.property
def get_value(self) -> str:
"""
Getter for value
Returns: the value
"""
return self.value

View File

@@ -0,0 +1,41 @@
"""Software Show Output."""
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
from keywords.cloud_platform.upgrade.objects.software_show_object import SoftwareShowObject
class SoftwareShowOutput:
"""
This class parses o/p 'software show' command into an object of
type SoftwareShowObject.
"""
def __init__(self, software_show_output):
"""
Instance of the class.
Args:
software_show_output: output of 'software show' command as a list of strings.
"""
self.software_show: SoftwareShowObject = []
system_table_parser = SystemTableParser(software_show_output)
self.output_values = system_table_parser.get_output_values_list()
for value in self.output_values:
software_show_object = SoftwareShowObject(
value["Property"],
value["Value"],
)
self.software_show.append(software_show_object)
def get_software_show(self) -> SoftwareShowObject:
"""
Get all software show objects.
Returns:
the list of software show objects
"""
software_show = self.software_show
return software_show

View File

@@ -0,0 +1,42 @@
"""Software list keywords."""
from keywords.base_keyword import BaseKeyword
from keywords.cloud_platform.command_wrappers import source_openrc
from keywords.cloud_platform.upgrade.objects.software_list_output import SoftwareListOutput
class SoftwareListKeywords(BaseKeyword):
"""
This class contains all the keywords related to the
'software list' commands.
Attributes:
ssh_connection: An instance of an SSH connection.
"""
def __init__(self, ssh_connection):
"""
Instance of the class.
Args:
ssh_connection: An instance of an SSH connection.
"""
self.ssh_connection = ssh_connection
def get_software_list(self, sudo=False) -> SoftwareListOutput:
"""
Get the software list.
Args:
sudo: True or False
"""
if sudo:
output = self.ssh_connection.send_as_sudo("software list")
else:
output = self.ssh_connection.send(source_openrc("software list"))
self.validate_success_return_code(self.ssh_connection)
software_list_output = SoftwareListOutput(output)
return software_list_output

View File

@@ -0,0 +1,39 @@
from keywords.base_keyword import BaseKeyword
from keywords.cloud_platform.command_wrappers import source_openrc
from keywords.cloud_platform.upgrade.objects.software_show_output import SoftwareShowOutput
class SoftwareShowKeywords(BaseKeyword):
"""
This class contains all the keywords related to the
'software show <rel-id>' commands.
Attributes:
ssh_connection: An instance of an SSH connection.
"""
def __init__(self, ssh_connection):
"""
Instance of the class.
Args:
ssh_connection: An instance of an SSH connection.
"""
self.ssh_connection = ssh_connection
def get_software_show(self, sudo=False, release_id=None) -> SoftwareShowOutput:
"""
Get the software show.
Args:
sudo: True or False
release_id: Release Name
"""
if sudo:
output = self.ssh_connection.send_as_sudo(f"software show {release_id}")
else:
output = self.ssh_connection.send(source_openrc(f"software show {release_id}"))
self.validate_success_return_code(self.ssh_connection)
software_show_output = SoftwareShowOutput(output)
return software_show_output