From 2e48497ad56b6fb277e75bd2762690e69f637f1e Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Fri, 4 Aug 2023 09:56:56 +0200 Subject: [PATCH] tests(lock): improve pid detection logic to use more exact matches Signed-off-by: Reuben Miller --- .../tests/MQTT_health_check/MQTT_health_endpoints.robot | 4 ++-- .../health_c8y-configuration-plugin.robot | 4 ++-- .../tests/MQTT_health_check/health_c8y-log-plugin.robot | 4 ++-- .../tests/MQTT_health_check/health_tedge-agent.robot | 4 ++-- .../tests/MQTT_health_check/health_tedge-mapper-az.robot | 4 ++-- .../MQTT_health_check/health_tedge-mapper-collectd.robot | 6 +++--- .../tests/MQTT_health_check/health_tedge_mapper_c8y.robot | 4 ++-- tests/RobotFramework/tests/configuration/lock_file.robot | 8 ++++---- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/RobotFramework/tests/MQTT_health_check/MQTT_health_endpoints.robot b/tests/RobotFramework/tests/MQTT_health_check/MQTT_health_endpoints.robot index 0c79219934e..9aca9dbd2f8 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/MQTT_health_endpoints.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/MQTT_health_endpoints.robot @@ -15,7 +15,7 @@ c8y-log-plugin health status Execute Command sudo systemctl start c8y-log-plugin.service Sleep 5s reason=It fails without this! It needs a better way of queuing requests - ${pid}= Execute Command pgrep -f "c8y[_-]log[_-]plugin" strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/c8y[_-]log[_-]plugin' strip=${True} Execute Command sudo tedge mqtt pub 'tedge/health-check/c8y-log-plugin' '' ${messages}= Should Have MQTT Messages tedge/health/c8y-log-plugin minimum=1 maximum=2 Should Contain ${messages[0]} "pid":${pid} @@ -25,7 +25,7 @@ c8y-configuration-plugin health status Execute Command sudo systemctl start c8y-configuration-plugin.service Sleep 5s reason=It fails without this! It needs a better way of queuing requests - ${pid}= Execute Command pgrep -f "c8y[_-]configuration[_-]plugin" strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/c8y[_-]configuration[_-]plugin' strip=${True} Execute Command sudo tedge mqtt pub 'tedge/health-check/c8y-configuration-plugin' '' ${messages}= Should Have MQTT Messages tedge/health/c8y-configuration-plugin minimum=1 maximum=2 Should Contain ${messages[0]} "pid":${pid} diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_c8y-configuration-plugin.robot b/tests/RobotFramework/tests/MQTT_health_check/health_c8y-configuration-plugin.robot index a5cb5bf7d6e..9c42b3f57dd 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_c8y-configuration-plugin.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_c8y-configuration-plugin.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of c8y-configuration-plugin - ${pid}= Execute Command pgrep -f 'c8y-configuration-plugin' strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/c8y-configuration-plugin' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of c8y-configuration-plugin - ${pid1}= Execute Command pgrep -f 'c8y-configuration-plugin' strip=True + ${pid1}= Execute Command pgrep -f '^/usr/bin/c8y-configuration-plugin' strip=${True} Set Suite Variable ${pid1} Compare PID change diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_c8y-log-plugin.robot b/tests/RobotFramework/tests/MQTT_health_check/health_c8y-log-plugin.robot index a69bbfcfd2a..8829bab160a 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_c8y-log-plugin.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_c8y-log-plugin.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of c8y-log-plugin - ${pid}= Execute Command pgrep -f c8y-log-plugin strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/c8y-log-plugin' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of c8y-log-plugin - ${pid1}= Execute Command pgrep -f c8y-log-plugin strip=True + ${pid1}= Execute Command pgrep -f '^/usr/bin/c8y-log-plugin' strip=${True} Set Suite Variable ${pid1} Compare PID change diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-agent.robot b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-agent.robot index d6b79070998..61453ed132b 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-agent.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-agent.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of tedge-mapper - ${pid}= Execute Command pgrep -f tedge-agent strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of tedge-agent - ${pid1}= Execute Command pgrep -f tedge-agent strip=True + ${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True} Set Suite Variable ${pid1} Compare PID change diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-az.robot b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-az.robot index eb9d54760bc..c7436dda15b 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-az.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-az.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of tedge-mapper-az - ${pid}= Execute Command pgrep -f 'tedge-mapper az' + ${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper az' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of tedge-agent - ${pid1}= Execute Command pgrep -f 'tedge-mapper az' + ${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper az' strip=${True} Set Suite Variable ${pid1} Compare PID change diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-collectd.robot b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-collectd.robot index 0f899926edc..6e728d28a7c 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-collectd.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_tedge-mapper-collectd.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of tedge-mapper-collectd - ${pid}= Execute Command pgrep -f 'tedge-mapper collectd' + ${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of tedge-mapper-collectd - ${pid1}= Execute Command pgrep -f 'tedge-mapper collectd' strip=True + ${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True} Set Suite Variable ${pid1} Compare PID change @@ -51,7 +51,7 @@ tedge-collectd-mapper health status Execute Command sudo systemctl start tedge-mapper-collectd.service Sleep 5s reason=It fails without this! It needs a better way of queuing requests - ${pid}= Execute Command pgrep -f "tedge-mapper collectd" strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True} Execute Command sudo tedge mqtt pub 'tedge/health-check/tedge-mapper-collectd' '' ${messages}= Should Have MQTT Messages tedge/health/tedge-mapper-collectd minimum=1 maximum=2 Should Contain ${messages[0]} "pid":${pid} diff --git a/tests/RobotFramework/tests/MQTT_health_check/health_tedge_mapper_c8y.robot b/tests/RobotFramework/tests/MQTT_health_check/health_tedge_mapper_c8y.robot index a826a0e271f..c77a5384a7b 100644 --- a/tests/RobotFramework/tests/MQTT_health_check/health_tedge_mapper_c8y.robot +++ b/tests/RobotFramework/tests/MQTT_health_check/health_tedge_mapper_c8y.robot @@ -28,14 +28,14 @@ Start watchdog service Sleep 10s Check PID of tedge-mapper - ${pid}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True + ${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True} Set Suite Variable ${pid} Kill the PID Kill Process ${pid} Recheck PID of tedge-mapper - ${pid1}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True + ${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True} Set Suite Variable ${pid1} Compare PID change diff --git a/tests/RobotFramework/tests/configuration/lock_file.robot b/tests/RobotFramework/tests/configuration/lock_file.robot index 00a2f4ffa10..c031cfd236b 100644 --- a/tests/RobotFramework/tests/configuration/lock_file.robot +++ b/tests/RobotFramework/tests/configuration/lock_file.robot @@ -18,8 +18,8 @@ Check lock file existence in default folder Check PID number in lock file [Documentation] Include the pid inside the existing lock files under /run/lock/ - ${pid_agent1}= Execute Command pgrep -f 'tedge-agent' strip=True - ${pid_mapper1}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True + ${pid_agent1}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True} + ${pid_mapper1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True} ${pid_agent_lock1}= Execute Command cat /run/lock/tedge-agent.lock ${pid_mapper_lock1}= Execute Command cat /run/lock/tedge-mapper-c8y.lock Should Be Equal ${pid_agent1} ${pid_agent_lock1} @@ -30,8 +30,8 @@ Check PID number in lock file after restarting the services ... inside the existing lock files under /run/lock/ Restart Service tedge-agent Restart Service tedge-mapper-c8y - ${pid_agent2}= Execute Command pgrep -f 'tedge-agent' strip=True - ${pid_mapper2}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True + ${pid_agent2}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=True + ${pid_mapper2}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True} ${pid_agent_lock2}= Execute Command cat /run/lock/tedge-agent.lock ${pid_mapper_lock2}= Execute Command cat /run/lock/tedge-mapper-c8y.lock Should Be Equal ${pid_agent2} ${pid_agent_lock2}