From bd93161a2d6227eeb7916540171a72567e863f83 Mon Sep 17 00:00:00 2001 From: jpike Date: Tue, 18 Feb 2025 09:43:30 -0500 Subject: [PATCH] Adding ability to use source with a sudo command Also adding missing parser test from previous commit Change-Id: If07271d3387c7a74439fe71408d6c9b0378d74d9 --- keywords/cloud_platform/command_wrappers.py | 4 ++ .../parser/ptp/ptp4l_status_parser_test.py | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 unit_tests/parser/ptp/ptp4l_status_parser_test.py diff --git a/keywords/cloud_platform/command_wrappers.py b/keywords/cloud_platform/command_wrappers.py index 38d4de3f..6f62595d 100644 --- a/keywords/cloud_platform/command_wrappers.py +++ b/keywords/cloud_platform/command_wrappers.py @@ -1,2 +1,6 @@ def source_openrc(cmd: str): return f"source /etc/platform/openrc;{cmd}" + + +def source_sudo_openrc(cmd: str): + return f"bash -c 'source /etc/platform/openrc;{cmd}'" diff --git a/unit_tests/parser/ptp/ptp4l_status_parser_test.py b/unit_tests/parser/ptp/ptp4l_status_parser_test.py new file mode 100644 index 00000000..000d19f5 --- /dev/null +++ b/unit_tests/parser/ptp/ptp4l_status_parser_test.py @@ -0,0 +1,59 @@ +from keywords.ptp.ptp4l.objects.ptp4l_status_output import PTP4LStatusOutput + +ptp4l_status_output = [ + '● ptp4l@ptp1.service - Precision Time Protocol (PTP) service\n', + 'Loaded: loaded (/etc/systemd/system/ptp4l@.service; enabled; vendor preset: disabled)\n', + 'Active: active (running) since Mon 2025-02-10 18:36:34 UTC; 3 days ago\n', + 'Main PID: 15221 (ptp4l)\n', + 'Tasks: 1 (limit: 150897)\n', + 'Memory: 336.0K\n', + 'CPU: 1min 33.917s\n', + 'CGroup: /system.slice/system-ptp4l.slice/ptp4l@ptp1.service\n', + '└─15221 /usr/sbin/ptp4l -f /etc/linuxptp/ptpinstance/ptp4l-ptp1.conf\n', + '\n', + '● ptp4l@ptp3.service - Precision Time Protocol (PTP) service\n', + 'Loaded: loaded (/etc/systemd/system/ptp4l@.service; enabled; vendor preset: disabled)\n', + 'Active: active (running) since Wed 2025-02-12 16:22:23 UTC; 2 days ago\n', + 'Process: 3816049 ExecStartPost=/bin/bash -c echo $MAINPID > /var/run/ptp4l-ptp3.pid (code=exited, status=0/SUCCESS)\n', + 'Main PID: 3816048 (ptp4l)\n', + 'Tasks: 1 (limit: 150897)\n', + 'Memory: 328.0K\n', + 'CPU: 38.984s\n', + 'CGroup: /system.slice/system-ptp4l.slice/ptp4l@ptp3.service\n', + '└─3816048 /usr/sbin/ptp4l -f /etc/linuxptp/ptpinstance/ptp4l-ptp3.conf\n', +] + + +def test_ptp4l_service_status_output_parser(): + """ + Tests ptp4l_status_output parser + Returns: + + """ + ptp4l_service_status_output = PTP4LStatusOutput(ptp4l_status_output) + + # validate first service 'ptp1.service' + ptp4l_status_object = ptp4l_service_status_output.get_ptp4l_object('ptp1.service') + + assert ptp4l_status_object.get_active() == 'active (running) since Mon 2025-02-10 18:36:34 UTC; 3 days ago' + assert ptp4l_status_object.get_c_group() == '/system.slice/system-ptp4l.slice/ptp4l@ptp1.service' + assert ptp4l_status_object.get_command() == '15221 /usr/sbin/ptp4l -f /etc/linuxptp/ptpinstance/ptp4l-ptp1.conf' + assert ptp4l_status_object.get_cpu() == '1min 33.917s' + assert ptp4l_status_object.get_loaded() == 'loaded (/etc/systemd/system/ptp4l@.service; enabled; vendor preset: disabled)' + assert ptp4l_status_object.get_main_pid() == '15221 (ptp4l)' + assert ptp4l_status_object.get_memory() == '336.0K' + assert ptp4l_status_object.get_process() == '' + assert ptp4l_status_object.get_tasks() == '1 (limit: 150897)' + + # validate second service 'ptp3.service + ptp4l_status_object = ptp4l_service_status_output.get_ptp4l_object('ptp3.service') + + assert ptp4l_status_object.get_active() == 'active (running) since Wed 2025-02-12 16:22:23 UTC; 2 days ago' + assert ptp4l_status_object.get_c_group() == '/system.slice/system-ptp4l.slice/ptp4l@ptp3.service' + assert ptp4l_status_object.get_command() == '3816048 /usr/sbin/ptp4l -f /etc/linuxptp/ptpinstance/ptp4l-ptp3.conf' + assert ptp4l_status_object.get_cpu() == '38.984s' + assert ptp4l_status_object.get_loaded() == 'loaded (/etc/systemd/system/ptp4l@.service; enabled; vendor preset: disabled)' + assert ptp4l_status_object.get_main_pid() == '3816048 (ptp4l)' + assert ptp4l_status_object.get_memory() == '328.0K' + assert ptp4l_status_object.get_process() == '3816049 ExecStartPost=/bin/bash -c echo $MAINPID > /var/run/ptp4l-ptp3.pid (code=exited, status=0/SUCCESS)' + assert ptp4l_status_object.get_tasks() == '1 (limit: 150897)'