summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPradeepKiruvale <PRADEEPKIRUVALE@gmail.com>2022-02-04 19:57:56 +0530
committerGitHub <noreply@github.com>2022-02-04 19:57:56 +0530
commit43bf45a3bd868586afe83a645be67f5042d9ac5d (patch)
tree41d607b64c65750e8e7f7e65fd308f9617b351a2 /tests
parent89f554fbb724cb4b9fe09336d58558cfa76638a1 (diff)
[699] init/clear agent and mapper sessions (#797)
* add init to tedge_agent * init mapper * init mapper and agent postinst * separate init and clear session functions * use tokio::mutex instead of std::mutex * pysys test for agent init * system test for mapper init session * use mqtt_channel init/clear session apis Co-authored-by: Pradeep Kumar K J <pradeepkumar.kj@sofwareag.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/PySys/tedge_agent/agent_init_session/pysystest.xml25
-rw-r--r--tests/PySys/tedge_agent/agent_init_session/run.py79
-rw-r--r--tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/pysystest.xml25
-rw-r--r--tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/run.py90
4 files changed, 219 insertions, 0 deletions
diff --git a/tests/PySys/tedge_agent/agent_init_session/pysystest.xml b/tests/PySys/tedge_agent/agent_init_session/pysystest.xml
new file mode 100644
index 00000000..150fc444
--- /dev/null
+++ b/tests/PySys/tedge_agent/agent_init_session/pysystest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pysystest type="auto">
+
+ <description>
+ <title>Validate tedge agent init session feature.</title>
+ <purpose><![CDATA[
+]]>
+ </purpose>
+ </description>
+ <classification>
+ <groups inherit="true">
+ <group></group>
+ </groups>
+ <modes inherit="true">
+ </modes>
+ </classification>
+ <data>
+ <class name="AgentInitSession" module="run"/>
+ </data>
+ <traceability>
+ <requirements>
+ <requirement id=""/>
+ </requirements>
+ </traceability>
+</pysystest>
diff --git a/tests/PySys/tedge_agent/agent_init_session/run.py b/tests/PySys/tedge_agent/agent_init_session/run.py
new file mode 100644
index 00000000..2581f072
--- /dev/null
+++ b/tests/PySys/tedge_agent/agent_init_session/run.py
@@ -0,0 +1,79 @@
+from pysys.basetest import BaseTest
+from datetime import datetime, timedelta
+
+"""
+Validate tedge agent init session feature.
+
+
+Given unconnected system
+
+When we start tedge_agent to initialize session and exit
+When we start publish the software list request
+When we start a subsciber to get the response for the request
+When we start the tedge_agent, it gets the previous response and responds
+Then stop the agent and the subscriber
+Then validate the output of the subscriber for response
+"""
+
+class AgentInitSession(BaseTest):
+ def setup(self):
+ self.sudo = "/usr/bin/sudo"
+ self.tedge_agent = "/usr/bin/tedge_agent"
+ self.tedge = "/usr/bin/tedge"
+ self.systemctl = "/usr/bin/systemctl"
+
+ remove_lock = self.startProcess(
+ command=self.sudo,
+ arguments=["rm", "-rf", "/var/lock/tedge_agent.lock"],
+ stdouterr="remove_lock",
+ )
+
+ def execute(self):
+ agent_clear = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge_agent, "--clear"],
+ stdouterr="agent_clear",
+ )
+
+ agent_init = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge_agent, "--init"],
+ stdouterr="agent_init",
+ )
+
+ pub_req = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "mqtt", "pub", "--qos", "1", "tedge/commands/req/software/list", "{\"id\":\"Ld3KgqpcLDlrYH6sfpG7w\"}"],
+ stdouterr="pub_req",
+ )
+
+ sub_resp = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "mqtt", "sub", "tedge/commands/res/software/list"],
+ stdouterr="sub_resp",
+ background=True,
+ )
+
+ agent_start = self.startProcess(
+ command=self.sudo,
+ arguments=[self.systemctl, "start", "tedge-agent"],
+ stdouterr="agent_start",
+ )
+
+ self.wait(2)
+
+ agent_stop = self.startProcess(
+ command=self.sudo,
+ arguments=[self.systemctl, "stop", "tedge-agent"],
+ stdouterr="agent_stop",
+ )
+
+ sub_stop = self.startProcess(
+ command=self.sudo,
+ arguments=["killall", "tedge"],
+ stdouterr="sub_stop",
+ )
+
+ def validate(self):
+ self.assertGrep("sub_resp.out", "Ld3KgqpcLDlrYH6sfpG7w", contains=True)
+ \ No newline at end of file
diff --git a/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/pysystest.xml b/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/pysystest.xml
new file mode 100644
index 00000000..cab67af1
--- /dev/null
+++ b/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/pysystest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pysystest type="auto">
+
+ <description>
+ <title>Validate tedge_mapper_sm_c8y init session feature</title>
+ <purpose><![CDATA[
+]]>
+ </purpose>
+ </description>
+ <classification>
+ <groups inherit="true">
+ <group></group>
+ </groups>
+ <modes inherit="true">
+ </modes>
+ </classification>
+ <data>
+ <class name="TedgeSMMapperInitSession" module="run"/>
+ </data>
+ <traceability>
+ <requirements>
+ <requirement id=""/>
+ </requirements>
+ </traceability>
+</pysystest>
diff --git a/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/run.py b/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/run.py
new file mode 100644
index 00000000..64d1cf80
--- /dev/null
+++ b/tests/PySys/tedge_mapper_c8y/sm_tedge_mapper_init_session/run.py
@@ -0,0 +1,90 @@
+from pysys.basetest import BaseTest
+
+
+"""
+Validate tedge_mapper sm-c8y init session feature.
+
+Given unconnected system
+
+When the system is connected to cumulocity cloud
+Then stop the tedge-mapper-sm-c8y
+Then clean the tedge-mapper-sm-c8y session that is present in the broker
+Then initialize the tedge-mapper-sm-c8y session and subscribing to the topics
+Then publish a software list request onto c8y/s/us
+Then start a subscriber to get the request 'tedge/commands/res/software/list'
+Then start the tedge-mapper-sm-c8y
+Now the mapper should receive the request that was receive the previous request
+ and forward the request to agent on 'tedge/commands/res/software/list'
+Now stop the subscriber and validate the message received on 'tedge/commands/res/software/list'
+Validate the response for that contains id.
+
+"""
+from environment_c8y import EnvironmentC8y
+
+class TedgeSMMapperInitSession(EnvironmentC8y):
+ def setup(self):
+ super().setup()
+ self.sudo = "/usr/bin/sudo"
+ self.tedge = "/usr/bin/tedge"
+ self.systemctl = "/usr/bin/systemctl"
+ self.tedge_mapper = "/usr/bin/tedge_mapper"
+
+ self.addCleanupFunction(self.init_cleanup)
+
+ def execute(self):
+
+ stop_tedge_mapper = self.startProcess(
+ command=self.sudo,
+ arguments=["systemctl", "stop", "tedge-mapper-sm-c8y"],
+ stdouterr="stop_tedge_mapper",
+ )
+
+ remove_lock = self.startProcess(
+ command=self.sudo,
+ arguments=["rm", "-rf", "/var/lock/sm-c8y-mapper.lock"],
+ stdouterr="remove_lock",
+ )
+ mapper_drop = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge_mapper, "--clear", "sm-c8y"],
+ stdouterr="mapper_drop",
+ )
+
+ mapper_init = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge_mapper, "--init", "sm-c8y"],
+ stdouterr="mapper_init",
+ )
+
+ pub_req = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "mqtt", "pub", "--qos", "1", "c8y/s/us", "118,software-management"],
+ stdouterr="pub_req",
+ )
+
+ sub_resp = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "mqtt", "sub", "tedge/commands/req/software/list"],
+ stdouterr="sub_resp",
+ background=True,
+ )
+
+ start_mapper = self.startProcess(
+ command=self.sudo,
+ arguments=[self.systemctl, "start", "tedge-mapper-sm-c8y"],
+ stdouterr="start_mapper",
+ )
+
+ self.wait(2)
+
+ sub_stop = self.startProcess(
+ command=self.sudo,
+ arguments=["killall", "tedge"],
+ stdouterr="sub_stop",
+ )
+
+ def validate(self):
+ self.assertGrep("sub_resp.out", "id", contains=True)
+
+ def init_cleanup(self):
+ super().myenvcleanup()