Description: - Added a missing import for SSHConnection. - Added data types to function arguments and return values. - Removed Returns section in docstring when function return type is None Change-Id: Id96217573f629d40a52459a3b45d26ae0649aa03 Signed-off-by: aabhinav <ayyapasetti.abhinav@windriver.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from framework.ssh.ssh_connection import SSHConnection
|
|
from keywords.base_keyword import BaseKeyword
|
|
|
|
|
|
class SystemCTLIsActiveKeywords(BaseKeyword):
|
|
"""
|
|
Class for "systemctl is-active" keywords
|
|
"""
|
|
|
|
def __init__(self, ssh_connection: SSHConnection):
|
|
"""
|
|
Constructor
|
|
|
|
Args:
|
|
ssh_connection (SSHConnection): SSH connection to the active controller
|
|
"""
|
|
self.ssh_connection = ssh_connection
|
|
|
|
def is_active(self, service_name: str) -> str:
|
|
"""
|
|
Checks if the service is active using "systemctl is-active <service_name>"
|
|
|
|
Args:
|
|
service_name (str): The name of the service
|
|
|
|
Returns:
|
|
str: 'active' or 'inactive'
|
|
"""
|
|
output = self.ssh_connection.send(f"systemctl is-active {service_name}")
|
|
self.validate_success_return_code(self.ssh_connection)
|
|
|
|
# output is a List of 1 string. "active/n"
|
|
output_string = ""
|
|
if output and len(output) > 0:
|
|
output_string = output[0].strip()
|
|
else:
|
|
raise "Output is expected to be a List with one element."
|
|
|
|
return output_string
|