Files
test/keywords/linux/systemctl/systemctl_is_active_keywords.py
croy 82d417b9e6 New StarlingX Automation Framework
Fresh start for the StarlingX automation framework.

Change-Id: Ie265e0791024f45f71faad6315c2b91b022934d1
2024-11-29 16:01:57 -05:00

37 lines
1010 B
Python

from keywords.base_keyword import BaseKeyword
class SystemCTLIsActiveKeywords(BaseKeyword):
"""
Class for "systemctl is-active" keywords
"""
def __init__(self, ssh_connection):
"""
Constructor
Args:
ssh_connection:
"""
self.ssh_connection = ssh_connection
def is_active(self, service_name) -> str:
"""
Checks if the service is active using "systemctl is-active <service_name>"
Args:
service_name: The name of the service
Returns: '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