summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorinitard <alex.solomes@softwareag.com>2022-01-12 12:18:21 +0100
committerGitHub <noreply@github.com>2022-01-12 12:18:21 +0100
commit735f39337f41362003d60a482542c0fecd603b58 (patch)
tree72c245961b70481e93d48ec6a77aaad5baddbe08 /tests
parent141e93c03c8f9d9a9dd7076830445b3fd9cd5154 (diff)
Feature/651/configurable temp path (#732)
* configurable download path (WIP) (#651) Signed-off-by: initard <solo@softwareag.com> * download path test (WIP) (#651) Signed-off-by: initard <solo@softwareag.com> * default download path #651 Signed-off-by: initard <solo@softwareag.com> * install to download.path test (#651) Signed-off-by: initard <solo@softwareag.com> * formatting issues (#651) Signed-off-by: initard <solo@softwareag.com> * formatting issues (#651) Signed-off-by: initard <solo@softwareag.com> * rename download path to tmp path & test fix (#651) Signed-off-by: initard <solo@softwareag.com> * cargo fmt Signed-off-by: initard <solo@softwareag.com> * download path integration test (#651) Signed-off-by: initard <solo@softwareag.com> * adding doc detailing how to set temp path (#651) Signed-off-by: initard <solo@softwareag.com> * test fix (#651) Signed-off-by: initard <solo@softwareag.com> * adding sudo to doc (#651) Signed-off-by: initard <solo@softwareag.com> * removing unused test (#651) Signed-off-by: initard <solo@softwareag.com> * renaming, refactoring and extra documentation (#651) Signed-off-by: initard <solo@softwareag.com> * fixing naming of tmp.path (#651) Signed-off-by: initard <solo@softwareag.com> * changes to tmp dto #651 Signed-off-by: initard <solo@softwareag.com> Co-authored-by: initard <solo@softwareag.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/PySys/software_management_end_to_end/sm_apt_install_download_path/pysystest.xml26
-rw-r--r--tests/PySys/software_management_end_to_end/sm_apt_install_download_path/run.py113
-rw-r--r--tests/PySys/tedge/tedge_software_update/pysystest.xml25
-rw-r--r--tests/PySys/tedge/tedge_software_update/run.py113
4 files changed, 277 insertions, 0 deletions
diff --git a/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/pysystest.xml b/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/pysystest.xml
new file mode 100644
index 00000000..fe004435
--- /dev/null
+++ b/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/pysystest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pysystest type="auto">
+
+ <description>
+ <title>Install package to directory specified in tedge config set tmp.path
+</title>
+ <purpose><![CDATA[
+]]>
+ </purpose>
+ </description>
+ <classification>
+ <groups inherit="true">
+ <group></group>
+ </groups>
+ <modes inherit="true">
+ </modes>
+ </classification>
+ <data>
+ <class name="AptInstallWithDownloadPath" module="run"/>
+ </data>
+ <traceability>
+ <requirements>
+ <requirement id=""/>
+ </requirements>
+ </traceability>
+</pysystest>
diff --git a/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/run.py b/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/run.py
new file mode 100644
index 00000000..3328c61c
--- /dev/null
+++ b/tests/PySys/software_management_end_to_end/sm_apt_install_download_path/run.py
@@ -0,0 +1,113 @@
+import os
+import subprocess
+from pysys.basetest import BaseTest
+from environment_sm_management import SoftwareManagement
+from retry import retry
+
+"""
+This test checks that the install action downloads the package (rolldice.deb) to the location
+specified by tedge config set tmp.path <some value>
+
+steps:
+
+ 1. set tmp.path to /tedge_download_path_test
+ 2. reconnect c8y
+ 3. trigger donload
+ 4. assert package downloads in /tedge_download_path_test
+ 5. remove package
+ 6. reset tmp.path to inital value
+"""
+
+
+@retry(Exception, tries=10, delay=.5)
+def assert_install_in_download_path(install_directory):
+ """
+ assert rolldice is installed in correct path
+ """
+ assert "rolldice" in os.listdir(f"{install_directory}")
+
+
+
+class AptInstallWithDownloadPath(SoftwareManagement, BaseTest):
+ SUDO = "/usr/bin/sudo"
+ TEDGE = "/usr/bin/tedge"
+ DOWNLOAD_DIR = "/tedge_download_path_test"
+ CURRENT_DOWNLOAD_PATH = None
+
+ def reconnect_c8y(self):
+ self.startProcess(
+ command=self.SUDO,
+ arguments=[self.TEDGE, "disconnect", "c8y"]
+ )
+
+ self.startProcess(
+ command=self.SUDO,
+ arguments=[self.TEDGE, "connect", "c8y"]
+ )
+
+ def set_download_path(self, download_path):
+ self.startProcess(
+ command=self.SUDO,
+ arguments=[self.TEDGE, "config", "set", "download.path", f"{download_path}"]
+ )
+
+ def setup(self):
+ super().setup()
+ self.assertThat("False == value", value=self.check_is_installed("rolldice"))
+
+ # creating directory
+ self.startProcess(command=self.SUDO, arguments=["mkdir", f"{self.DOWNLOAD_DIR}"])
+ self.startProcess(command=self.SUDO, arguments=["chmod", "a+rwx", f"{self.DOWNLOAD_DIR}"])
+
+ self.CURRENT_DOWNLOAD_PATH = subprocess.check_output(f"{self.SUDO} {self.TEDGE} config get download.path", shell=True).decode("utf8").strip()
+
+ # setting download.path
+ self.set_download_path(self.DOWNLOAD_DIR)
+
+ self.reconnect_c8y()
+
+
+
+ def execute(self):
+
+ self.trigger_action(
+ package_name="rolldice",
+ package_id=self.get_pkgid("rolldice"),
+ version="::apt",
+ url="https://thin-edge-io.eu-latest.cumulocity.com/inventory/binaries/12435463",
+ action="install"
+ )
+
+ # download path validation
+ assert_install_in_download_path(install_directory=self.DOWNLOAD_DIR)
+
+ self.wait_until_succcess()
+
+ self.assertThat("True == value", value=self.check_is_installed("rolldice"))
+
+ self.trigger_action(
+ package_name="rolldice",
+ package_id=self.get_pkgid("rolldice"),
+ version="",
+ url="",
+ action="delete"
+ )
+
+ self.wait_until_succcess()
+
+ def validate(self):
+ self.assertThat("False == value", value=self.check_is_installed("rolldice"))
+
+
+ def mysmcleanup(self):
+
+ self.startProcess(
+ command=self.SUDO,
+ arguments=["rm", "-rf", f"{self.DOWNLOAD_DIR}"]
+ )
+
+ self.set_download_path(self.CURRENT_DOWNLOAD_PATH)
+
+ # reconnect is required to revert back to initial download config
+ self.reconnect_c8y()
+
diff --git a/tests/PySys/tedge/tedge_software_update/pysystest.xml b/tests/PySys/tedge/tedge_software_update/pysystest.xml
new file mode 100644
index 00000000..5e927beb
--- /dev/null
+++ b/tests/PySys/tedge/tedge_software_update/pysystest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pysystest type="auto">
+
+ <description>
+ <title>Software install from download path</title>
+ <purpose><![CDATA[
+]]>
+ </purpose>
+ </description>
+ <classification>
+ <groups inherit="true">
+ <group></group>
+ </groups>
+ <modes inherit="true">
+ </modes>
+ </classification>
+ <data>
+ <class name="PySysTest" module="run"/>
+ </data>
+ <traceability>
+ <requirements>
+ <requirement id=""/>
+ </requirements>
+ </traceability>
+</pysystest>
diff --git a/tests/PySys/tedge/tedge_software_update/run.py b/tests/PySys/tedge/tedge_software_update/run.py
new file mode 100644
index 00000000..f84abb85
--- /dev/null
+++ b/tests/PySys/tedge/tedge_software_update/run.py
@@ -0,0 +1,113 @@
+from .environments.environment_c8y import EnvironmentC8y
+
+"""
+Validate command line option help
+
+Given a running system
+When we call tedge help
+Then we find the string USAGE: in the output
+Then we find the string FLAGS: in the output
+Then we find the string SUBCOMMANDS: in the output
+"""
+
+TEDGE_DOWNLOAD_DIR = "/tedge_download_dir"
+TEDGE_DOWNLOAD_PATH = "tmp.path"
+TOPIC = 'tedge/commands/req/software/update'
+PAYLOAD = '{"id":"1234","updateList":[{"type":"apt","modules":[{"name":"rolldice","version":"::apt","url":"https://t48415.basic.stage.c8y.io/inventory/binaries/1202","action":"install"}]}]}'
+
+
+class PySysTest(EnvironmentC8y):
+
+ sudo = "/usr/bin/sudo"
+ tedge = "/usr/bin/tedge"
+
+ def tedge_get_config(self, filename: str):
+ """
+ run tedge config get `TEDGE_DOWNLOAD_PATH`
+
+ this is used in validation
+ """
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "config", "get", TEDGE_DOWNLOAD_PATH],
+ stdouterr=filename,
+ expectedExitStatus="==0",
+ )
+
+ def tedge_set_config(self, new_value: str):
+ """
+ run tedge config set `TEDGE_DOWNLOAD_PATH` `new_value`
+ """
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "config", "set", TEDGE_DOWNLOAD_PATH, new_value],
+ expectedExitStatus="==0",
+ )
+
+ def setup(self):
+ super().setup()
+ self.log.info("Setup")
+ self.addCleanupFunction(self.mycleanup)
+
+ def execute(self):
+ """
+ 1. saving existing download path
+ 2. setting download path to `TEDGE_DOWNLOAD_DIR`
+ 3. querying new download path (for validation)
+ 4. running software update
+ """
+
+ # make a new directory `TEDGE_DOWNLOAD_DIR`
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=["mkdir", TEDGE_DOWNLOAD_DIR]
+ )
+
+ # give full permission to `TEDGE_DOWNLOAD_DIR`
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=["chmod", "a+rwx", TEDGE_DOWNLOAD_DIR]
+ )
+
+ # 1. save the current/pre-change setting in /Output
+ self.tedge_get_config(filename="tedge_config_get_original")
+
+ # 2. change tedge download path to `TEDGE_DOWNLOAD_DIR`
+ self.tedge_set_config(new_value=TEDGE_DOWNLOAD_DIR)
+
+ # 3. tedge config get on changed value
+ self.tedge_get_config(filename="tedge_config_get_new_value")
+
+ # NOTE: remove `rolldice` if already there
+ # 4. trigger rolldice download
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=[self.tedge, "mqtt", "pub", TOPIC, PAYLOAD],
+ stdouterr="rolldice_download",
+ expectedExitStatus="==0",
+ )
+
+ def validate(self):
+ self.assertGrep("tedge_config_get_new_value.out", f'{TEDGE_DOWNLOAD_DIR}', contains=True)
+
+ def cleanup(self):
+
+ with open("Output/linux/tedge_config_get_original.out", "r") as handle:
+ original_value = handle.read().strip()
+
+ # reverting to original value
+ self.tedge_set_config(new_value=original_value)
+
+ # querying value
+ self.tedge_get_config(filename="tedge_config_get_cleanup")
+
+ # asserting it is the same as `original_value`
+ self.assertGrep("tedge_config_get_cleanup.out", f'{original_value}', contains=True)
+
+ # removing tedge dir
+ _ = self.startProcess(
+ command=self.sudo,
+ arguments=["rmdir", TEDGE_DOWNLOAD_DIR]
+ )
+
+ return super().cleanup()