This is a test set to make sure the collecting outputs of a command
works correctly for processes running both on foreground and background.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
regression-tests/tests/28/desc | 6 ++++++
regression-tests/tests/28/recipe1.py | 20 ++++++++++++++++++++
regression-tests/tests/28/recipe1.xml | 16 ++++++++++++++++
regression-tests/tests/28/recipe2.py | 18 ++++++++++++++++++
regression-tests/tests/28/recipe2.xml | 16 ++++++++++++++++
regression-tests/tests/28/recipe3.py | 12 ++++++++++++
regression-tests/tests/28/recipe3.xml | 16 ++++++++++++++++
regression-tests/tests/28/recipe4.py | 15 +++++++++++++++
regression-tests/tests/28/recipe4.xml | 16 ++++++++++++++++
regression-tests/tests/28/run.sh | 34 ++++++++++++++++++++++++++++++++++
10 files changed, 169 insertions(+)
create mode 100644 regression-tests/tests/28/desc
create mode 100644 regression-tests/tests/28/recipe1.py
create mode 100644 regression-tests/tests/28/recipe1.xml
create mode 100644 regression-tests/tests/28/recipe2.py
create mode 100644 regression-tests/tests/28/recipe2.xml
create mode 100644 regression-tests/tests/28/recipe3.py
create mode 100644 regression-tests/tests/28/recipe3.xml
create mode 100644 regression-tests/tests/28/recipe4.py
create mode 100644 regression-tests/tests/28/recipe4.xml
create mode 100755 regression-tests/tests/28/run.sh
diff --git a/regression-tests/tests/28/desc b/regression-tests/tests/28/desc
new file mode 100644
index 0000000..8d4477b
--- /dev/null
+++ b/regression-tests/tests/28/desc
@@ -0,0 +1,6 @@
+Check if a user can get result data especially stdout of a background process.
+
+1. by calling intr()
+2. by calling wait()
+3. by calling kill()
+4. when process is not run on background
diff --git a/regression-tests/tests/28/recipe1.py b/regression-tests/tests/28/recipe1.py
new file mode 100644
index 0000000..a0834e9
--- /dev/null
+++ b/regression-tests/tests/28/recipe1.py
@@ -0,0 +1,20 @@
+from lnst.Controller.Task import ctl
+
+m1 = ctl.get_host("testmachine1")
+
+m1.sync_resources(modules=["Custom"], tools=[])
+
+test = m1.run("while true; do echo test; sleep 1; done", bg=True,
save_output="yes")
+
+ctl.wait(5)
+
+test.intr()
+
+output = test.get_result()["res_data"]["stdout"]
+
+custom = ctl.get_module("Custom", options={ "fail": True })
+
+if output.find("test") != -1:
+ custom.update_options({ "fail": False})
+
+m1.run(custom)
diff --git a/regression-tests/tests/28/recipe1.xml
b/regression-tests/tests/28/recipe1.xml
new file mode 100644
index 0000000..cf6bee0
--- /dev/null
+++ b/regression-tests/tests/28/recipe1.xml
@@ -0,0 +1,16 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="recipe1.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/28/recipe2.py b/regression-tests/tests/28/recipe2.py
new file mode 100644
index 0000000..b47ff5a
--- /dev/null
+++ b/regression-tests/tests/28/recipe2.py
@@ -0,0 +1,18 @@
+from lnst.Controller.Task import ctl
+
+m1 = ctl.get_host("testmachine1")
+
+m1.sync_resources(modules=["Custom"], tools=[])
+
+test = m1.run("for i in `seq 5`; do echo test; sleep 1; done", bg=True,
save_output="yes")
+
+test.wait()
+
+output = test.get_result()["res_data"]["stdout"]
+
+custom = ctl.get_module("Custom", options={ "fail": True })
+
+if output.find("test") != -1:
+ custom.update_options({ "fail": False})
+
+m1.run(custom)
diff --git a/regression-tests/tests/28/recipe2.xml
b/regression-tests/tests/28/recipe2.xml
new file mode 100644
index 0000000..1cd8070
--- /dev/null
+++ b/regression-tests/tests/28/recipe2.xml
@@ -0,0 +1,16 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="recipe2.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/28/recipe3.py b/regression-tests/tests/28/recipe3.py
new file mode 100644
index 0000000..96c5318
--- /dev/null
+++ b/regression-tests/tests/28/recipe3.py
@@ -0,0 +1,12 @@
+from lnst.Controller.Task import ctl
+
+m1 = ctl.get_host("testmachine1")
+
+m1.sync_resources(modules=["Custom"], tools=[])
+
+test = m1.run("while true; do echo test; sleep 1; done", bg=True,
save_output="yes")
+
+ctl.wait(5)
+
+test.kill()
+
diff --git a/regression-tests/tests/28/recipe3.xml
b/regression-tests/tests/28/recipe3.xml
new file mode 100644
index 0000000..2602c68
--- /dev/null
+++ b/regression-tests/tests/28/recipe3.xml
@@ -0,0 +1,16 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="recipe3.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/28/recipe4.py b/regression-tests/tests/28/recipe4.py
new file mode 100644
index 0000000..e8e8f99
--- /dev/null
+++ b/regression-tests/tests/28/recipe4.py
@@ -0,0 +1,15 @@
+from lnst.Controller.Task import ctl
+
+m1 = ctl.get_host("testmachine1")
+
+m1.sync_resources(modules=["Custom"], tools=[])
+
+test = m1.run("echo test", save_output="yes")
+output = test.get_result()["res_data"]["stdout"]
+
+custom = ctl.get_module("Custom", options={ "fail": True })
+
+if output.find("test") != -1:
+ custom.update_options({ "fail": False})
+
+m1.run(custom)
diff --git a/regression-tests/tests/28/recipe4.xml
b/regression-tests/tests/28/recipe4.xml
new file mode 100644
index 0000000..fd2452c
--- /dev/null
+++ b/regression-tests/tests/28/recipe4.xml
@@ -0,0 +1,16 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="recipe4.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/28/run.sh b/regression-tests/tests/28/run.sh
new file mode 100755
index 0000000..9901282
--- /dev/null
+++ b/regression-tests/tests/28/run.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+. ../lib.sh
+
+init_test
+
+lnst-ctl -d run recipe1.xml | tee test.log
+rv1=${PIPESTATUS[0]}
+log1=`cat test.log`
+
+lnst-ctl -d run recipe2.xml | tee test.log
+rv2=${PIPESTATUS[0]}
+log2=`cat test.log`
+
+lnst-ctl -d run recipe3.xml | tee test.log
+rv3=${PIPESTATUS[0]}
+log3=`cat test.log`
+
+lnst-ctl -d run recipe4.xml | tee test.log
+rv4=${PIPESTATUS[0]}
+log4=`cat test.log`
+
+print_separator
+assert_status "pass" "$rv1"
+assert_status "pass" "$rv2"
+assert_status "pass" "$rv3"
+assert_status "pass" "$rv4"
+assert_log "INFO" "stdout:.*test" "$log1"
+assert_log "INFO" "stdout:.*test" "$log2"
+assert_log "INFO" "stdout:.*test" "$log4"
+
+rm -f test.log
+
+end_test
--
2.4.3