diff options
author | PradeepKiruvale <PRADEEPKIRUVALE@gmail.com> | 2022-01-28 15:39:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 15:39:47 +0530 |
commit | f1ff28ccd4fc9c2b7cb472527302d8aa9e992ea0 (patch) | |
tree | f599f8c22a17a3fc0e8a22c866355165bf5957e5 /tests | |
parent | cd15f10bb6f893a18e63c54ad41a677a1e5ec1bb (diff) |
System test for tedge mqtt pub retain (#785)
* mqtt retain system test
* update description
* address review comments
* refactor test
* add clear flag test as well
* run tests as non sudo user
Co-authored-by: Pradeep Kumar K J <pradeepkumar.kj@sofwareag.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_fail_noqos/run.py | 3 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_fail_qos0/run.py | 7 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_fail_qos1/run.py | 6 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_fail_qos2/run.py | 7 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_sub/run.py | 23 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/pysystest.xml | 25 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/run.py | 107 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/pysystest.xml (renamed from tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/pysystest.xml) | 1 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/run.py (renamed from tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/run.py) | 39 | ||||
-rw-r--r-- | tests/PySys/local_mqtt/local_mqtt_sub_fail/run.py | 7 |
10 files changed, 190 insertions, 35 deletions
diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_fail_noqos/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_fail_noqos/run.py index 6fd71482..16e9d33c 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_fail_noqos/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_fail_noqos/run.py @@ -1,4 +1,5 @@ from pysys.basetest import BaseTest +import os """ Validate local publishing while no mosquitto is running @@ -16,6 +17,7 @@ class PySysTest(BaseTest): self.tedge = "/usr/bin/tedge" self.sudo = "/usr/bin/sudo" self.systemctl = "/usr/bin/systemctl" + self.environ = { 'HOME':os.environ.get('HOME')} self.startProcess( command=self.sudo, @@ -32,6 +34,7 @@ class PySysTest(BaseTest): arguments=[self.tedge, "mqtt", "pub", "atopic", "amessage"], stdouterr="tedge_pub_fail", expectedExitStatus="==1", + environs=self.environ ) # validate exit status with the expected status from calling startProcess diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos0/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos0/run.py index 1d732b4a..ca0f8273 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos0/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos0/run.py @@ -1,4 +1,5 @@ from pysys.basetest import BaseTest +import os """ Validate local publishing while no mosquitto is running @@ -16,6 +17,7 @@ class PySysTest(BaseTest): self.tedge = "/usr/bin/tedge" self.sudo = "/usr/bin/sudo" self.systemctl = "/usr/bin/systemctl" + self.environ = { 'HOME':os.environ.get('HOME')} self.startProcess( command=self.sudo, @@ -28,10 +30,11 @@ class PySysTest(BaseTest): def execute(self): pub = self.startProcess( - command=self.sudo, - arguments=[self.tedge, "mqtt", "pub", "--qos", "0", "atopic", "amessage"], + command=self.tedge, + arguments=["mqtt", "pub", "--qos", "0", "atopic", "amessage"], stdouterr="tedge_pub_fail", expectedExitStatus="==1", + environs=self.environ ) # validate exit status with the expected status from calling startProcess diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos1/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos1/run.py index be8a1961..4bd9c8ad 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos1/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos1/run.py @@ -1,4 +1,5 @@ from pysys.basetest import BaseTest +import os """ Validate local publishing while no mosquitto is running @@ -16,6 +17,7 @@ class PySysTest(BaseTest): self.tedge = "/usr/bin/tedge" self.sudo = "/usr/bin/sudo" self.systemctl = "/usr/bin/systemctl" + self.environ = { 'HOME':os.environ.get('HOME')} self.startProcess( command=self.sudo, @@ -28,8 +30,8 @@ class PySysTest(BaseTest): def execute(self): pub = self.startProcess( - command=self.sudo, - arguments=[self.tedge, "mqtt", "pub", "--qos", "1", "atopic", "amessage"], + command=self.tedge, + arguments=["mqtt", "pub", "--qos", "1", "atopic", "amessage"], stdouterr="tedge_pub_fail", expectedExitStatus="==1", ) diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos2/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos2/run.py index de8f9f3a..3f76cedd 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos2/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_fail_qos2/run.py @@ -1,4 +1,5 @@ from pysys.basetest import BaseTest +import os """ Validate local publishing while no mosquitto is running @@ -16,6 +17,7 @@ class PySysTest(BaseTest): self.tedge = "/usr/bin/tedge" self.sudo = "/usr/bin/sudo" self.systemctl = "/usr/bin/systemctl" + self.environ = { 'HOME':os.environ.get('HOME')} self.startProcess( command=self.sudo, @@ -28,10 +30,11 @@ class PySysTest(BaseTest): def execute(self): pub = self.startProcess( - command=self.sudo, - arguments=[self.tedge, "mqtt", "pub", "--qos", "2", "atopic", "amessage"], + command=self.tedge, + arguments=["mqtt", "pub", "--qos", "2", "atopic", "amessage"], stdouterr="tedge_pub_fail", expectedExitStatus="==1", + environs=self.environ ) # validate exit status with the expected status from calling startProcess diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_sub/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_sub/run.py index f4b106eb..4335b690 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_sub/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_sub/run.py @@ -1,6 +1,7 @@ from pysys.basetest import BaseTest import time +import os """ Validate local publishing and subscribing: @@ -18,19 +19,23 @@ class PySysTest(BaseTest): def execute(self): tedge = "/usr/bin/tedge" sudo = "/usr/bin/sudo" + environ = { 'HOME':os.environ.get('HOME')} sub1 = self.startProcess( - command=sudo, - arguments=[tedge, "mqtt", "sub", "atopic"], + command=tedge, + arguments=["mqtt", "sub", "atopic"], stdouterr="tedge_sub", background=True, + environs=environ + ) sub2 = self.startProcess( - command=sudo, - arguments=[tedge, "mqtt", "sub", "--no-topic", "atopic"], + command=tedge, + arguments=["mqtt", "sub", "--no-topic", "atopic"], stdouterr="tedge_sub_no_topic", background=True, + environs=environ ) # Wait for a small amount of time to give tedge sub time @@ -40,15 +45,17 @@ class PySysTest(BaseTest): time.sleep(0.1) pub = self.startProcess( - command=sudo, - arguments=[tedge, "mqtt", "pub", "atopic", "amessage"], + command=tedge, + arguments=["mqtt", "pub", "atopic", "amessage"], stdouterr="tedge_pub2", + environs=environ ) pub = self.startProcess( - command=sudo, - arguments=[tedge, "mqtt", "pub", "atopic", "the message"], + command=tedge, + arguments=["mqtt", "pub", "atopic", "the message"], stdouterr="tedge_pub3", + environs=environ ) # Kill the subscriber process explicitly with sudo as PySys does diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/pysystest.xml b/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/pysystest.xml new file mode 100644 index 00000000..bffc94d2 --- /dev/null +++ b/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/pysystest.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<pysystest type="auto"> + + <description> + <title>Validate local publishing with retain flag</title> + <purpose><![CDATA[ +]]> + </purpose> + </description> + <classification> + <groups inherit="true"> + <group></group> + </groups> + <modes inherit="true"> + </modes> + </classification> + <data> + <class name="MqttPublishWithRetain" module="run"/> + </data> + <traceability> + <requirements> + <requirement id=""/> + </requirements> + </traceability> +</pysystest> diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/run.py new file mode 100644 index 00000000..d2ca2cb1 --- /dev/null +++ b/tests/PySys/local_mqtt/local_mqtt_pub_sub_retain/run.py @@ -0,0 +1,107 @@ +from pysys.basetest import BaseTest + +import time +import os + +""" +Validate local publishing with retain flag and subscribing: + +Given a configured system +When we publish two messages with retain flag on to test/alarms/temp_sensor +When we start tedge sub in the background that subscribes to test/alarms/temp_sensor topic +When we publish an empty message with retain flag on to test/alarms/temp_sensor +Then we kill the subscriber +Now publish an empty message with retain flag on to test/alarms/temp_sensor +Start tedge sub in the background that subscribes to test/alarms/temp_sensor topic +Then we kill the subscriber +Then verify that there are retained message in the output of the first subscriber log +No empty message is present in the second subscriber log +""" + + +class MqttPublishWithRetain(BaseTest): + def setup(self): + self.tedge = "/usr/bin/tedge" + self.sudo = "/usr/bin/sudo" + self.environ = { 'HOME':os.environ.get('HOME')} + + def execute(self): + + pub_to_set_alarm = self.startProcess( + command=self.tedge, + arguments=["mqtt", "pub", "--retain", "--qos", "1", "test/alarms/temp_sensor", "alarm msg 1"], + stdouterr="pub_to_set_alarm", + environs=self.environ + ) + + pub_to_set_alarm = self.startProcess( + command=self.tedge, + arguments=["mqtt", "pub", "--retain", "--qos", "1", "test/alarms/temp_sensor", "alarm msg 2"], + stdouterr="pub_to_set_alarm", + environs=self.environ + ) + + # wait some time before starting subscribers + time.sleep(1) + + temp_sensor_sub = self.startProcess( + command=self.tedge, + arguments=["mqtt", "sub", "test/alarms/#"], + stdouterr="temp_sensor_sub", + background=True, + environs=self.environ + ) + + pub_to_clear_alarm = self.startProcess( + command=self.tedge, + arguments=["mqtt", "pub", "--retain", "--qos", "1", "test/alarms/temp_sensor", ""], + stdouterr="pub_to_clear_alarm", + environs=self.environ + ) + + # wait for a while before killing the subscribers + time.sleep(1) + + # Kill the subscriber process explicitly with sudo as PySys does + # not have the rights to do it + kill = self.startProcess( + command=self.sudo, + arguments=["killall", "tedge"], + stdouterr="kill_out", + ) + + # Publish an empty message and start the subscriber, Now the subscriber will not receive any + # message since it is an empty message. + + pub_to_clear_alarm = self.startProcess( + command=self.tedge, + arguments=["mqtt", "pub", "--retain", "--qos", "1", "test/alarms/temp_sensor", ""], + stdouterr="pub_to_clear_alarm", + environs=self.environ + ) + + temp_sensor_empty_message = self.startProcess( + command=self.tedge, + arguments=["mqtt", "sub", "test/alarms/#"], + stdouterr="temp_sensor_empty_message", + background=True, + environs=self.environ + ) + + # wait for a while before killing the subscribers + time.sleep(1) + + # Kill the subscriber process explicitly with sudo as PySys does + # not have the rights to do it + kill = self.startProcess( + command=self.sudo, + arguments=["killall", "tedge"], + stdouterr="kill_out", + environs=self.environ + ) + + def validate(self): + self.assertGrep("temp_sensor_sub.out", "\[test/alarms/temp_sensor\] alarm msg 2", contains=True) + self.assertGrep("temp_sensor_sub.out", "\[test/alarms/temp_sensor\] ", contains=True) + self.assertGrep("temp_sensor_empty_message.out", "\[test/alarms/temp_sensor\] ", contains=False) + diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/pysystest.xml b/tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/pysystest.xml index 45f31f4a..045d3015 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/pysystest.xml +++ b/tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/pysystest.xml @@ -22,5 +22,4 @@ <requirement id=""/> </requirements> </traceability> - <skipped reason="Issue with tedge and pysys: User's Home Directory not found."/> </pysystest> diff --git a/tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/run.py b/tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/run.py index b743c8c5..fe7e9633 100644 --- a/tests/PySys/local_mqtt/local_mqtt_pub_sub_nosudo/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_pub_sub_with_sudo/run.py @@ -2,24 +2,16 @@ import pysys from pysys.basetest import BaseTest import time - +import os """ Validate local publishing and subscribing: Given a configured system When we start the bridge and the mapper -When we start tedge sub in the background -When we start tedge pub to publish a message -When we start tedge pub to publish another message +When we start sudo tedge sub in the background +When we start sudo tedge pub to publish a message +When we start sudo tedge pub to publish another message Then we find the messages in the output of tedge sub - - -Disabled due to this issue: - -12:45:27 INFO Contents of tedge_pub2.err: -12:45:27 INFO Error: failed to read the tedge configuration -12:45:27 INFO Caused by: -12:45:27 INFO User's Home Directory not found. """ @@ -29,8 +21,8 @@ class PySysTest(BaseTest): sudo = "/usr/bin/sudo" sub = self.startProcess( - command=tedge, - arguments=["mqtt", "sub", "atopic"], + command=sudo, + arguments=[tedge, "mqtt", "sub", "atopic"], stdouterr="tedge_sub", background=True, ) @@ -42,17 +34,28 @@ class PySysTest(BaseTest): time.sleep(0.1) pub = self.startProcess( - command=tedge, - arguments=["mqtt", "pub", "atopic", "amessage"], + command=sudo, + arguments=[tedge, "mqtt", "pub", "atopic", "amessage"], stdouterr="tedge_pub2", ) pub = self.startProcess( - command=tedge, - arguments=["mqtt", "pub", "atopic", "the message"], + command=sudo, + arguments=[tedge, "mqtt", "pub", "atopic", "the message"], stdouterr="tedge_pub3", ) + # wait for a while before killing the subscribers + time.sleep(1) + + # Kill the subscriber process explicitly with sudo as PySys does + # not have the rights to do it + kill = self.startProcess( + command=sudo, + arguments=["killall", "tedge"], + stdouterr="kill_out", + ) + def validate(self): self.assertGrep("tedge_sub.out", "amessage", contains=True) self.assertGrep("tedge_sub.out", "the message", contains=True) diff --git a/tests/PySys/local_mqtt/local_mqtt_sub_fail/run.py b/tests/PySys/local_mqtt/local_mqtt_sub_fail/run.py index bb69d55c..693d1a9a 100644 --- a/tests/PySys/local_mqtt/local_mqtt_sub_fail/run.py +++ b/tests/PySys/local_mqtt/local_mqtt_sub_fail/run.py @@ -1,6 +1,7 @@ from pysys.basetest import BaseTest import time +import os """ Validate local subscribing while no mosquitto is running @@ -17,6 +18,7 @@ class PySysTest(BaseTest): self.tedge = "/usr/bin/tedge" self.sudo = "/usr/bin/sudo" self.systemctl = "/usr/bin/systemctl" + self.environ = { 'HOME':os.environ.get('HOME')} self.startProcess( command=self.sudo, @@ -29,10 +31,11 @@ class PySysTest(BaseTest): def execute(self): pub = self.startProcess( - command=self.sudo, - arguments=[self.tedge, "mqtt", "sub", "atopic"], + command=self.tedge, + arguments=["mqtt", "sub", "atopic"], stdouterr="tedge_sub_fail", expectedExitStatus="==1", + environs=self.environ ) # validate exit status with the expected status from calling startProcess |