Cleaning (killing) the spawned process was deferred to restore but spread
waits for execute script to finish completely which causes the test to hang
for the whole time of the process (sleep 5m).
If the test is successful we could speed up the process by popping the
clean command.
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
We are sending a SIGTERM to the test process, and so its handling and test
process termination is asynchronous and there is no guarantee the test process
exits immediately. Retry the check a couple of times to account for this.
The problem was often seen to happen on openSUSE:
Error: 2024-01-17 21:36:40 Error executing google:opensuse-tumbleweed-64:tests/main/interfaces-process-control (jan172104-345478) :
-----
+ echo 'The interface is disconnected by default'
The interface is disconnected by default
+ snap interfaces -i process-control
+ MATCH -- '- +process-control-consumer:process-control'
'snap interfaces' is deprecated; use 'snap connections'.
+ echo 'When the plug is connected'
When the plug is connected
+ snap connect process-control-consumer:process-control
+ echo 'Then the snap is able to kill an existing process'
Then the snap is able to kill an existing process
+ pid=31252
+ sleep 5m
+ kill -s 0 31252
+ process-control-consumer.signal SIGTERM 31252
+ not kill -s 0 31252
-----
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* Improve interface-process-control test
The test is failing in ubuntu lunar doing the pid cleanup, which is not
testing any snapd feature.
This change makes sure the pid is killed during the restare fase, even
when the execute check fails.
* Update tests/main/interfaces-process-control/task.yaml
Co-authored-by: Philip Meulengracht <the_meulengracht@hotmail.com>
* Check if the process is still alive
---------
Co-authored-by: Philip Meulengracht <the_meulengracht@hotmail.com>
Script being used to detect which snaps can be moved to
for snap in $(ls tests/lib/snaps); do
count=0
last=
for test in $(find tests/ -name task.yaml); do
if $(grep -q $snap $test); then
count=$((count+1))
last=$test
fi
done
echo "$snap -> $count times"
if [ $count = 1 ]; then
echo "mv tests/lib/snaps/$snap $(dirname $last)"
fi
done
The change updates the layout of the tests following a proposed order
which should make the test easier to read and understand
The proposed order is:
summary
details
backends
systems
manual
priority
warn-timout
kill-timeout
environment
prepare
restore
debug
execute
Using grep for PIDs is easy to do incorrectly, as we've found out the
hard way when a test searching for pid 2499 found process 24998. Rewrite
that part of the test to use kill with signal zero as a much safer and
less magic way of doing the same thing.
As a drive-by fix a typo in the description and remove useless sleep
loops. One sleep of moderate duration is sufficient.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This patch replaces more complex negated commands, those involving pipes
with the help of the two sed expressions:
find -name 'task.yaml' -exec sed -i -E -e 's/^( *)! *(.?+) +\| *([^|]+[^\]$)/\1\2 | not \3/' {} \;
find -name 'task.yaml' -exec sed -i -E -e 's/^( *)! *(.?+) *\| *([^|]+[^\]$)/\1\2 | not \3/' {} \;
The two commands are almost identical, differing in only the approach
towards white-space before the pipe operator. This was done because sed
doesn't natively support non-greedy expressions and I wanted the output
to have consistent spacing.
It is worth noting that the expression excludes commands that have a
continuation on the following line, since those would not be handled
correctly. As a simple example:
! foo | bar \
| froz
The diff was rather uneventful but one replacement result was manually
left out, because it had matched a command like "! foo || bar". Such
exceptions are not worth encoding in the automation since they occur
very infrequently in our code.
Please see the previous commit for a discussion on why pipes need to be
handled this way.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
This is done in the tests which are checking the interfaces information
in order to make them more robusts, making the test independent of other
plug:slots declared such it is happening in gadgets.
This change includes:
. Remove all the checks that are done after a connection and
disconnection (this is already checked as part of the snap_connect and
snap_disconnect tests).
. install_local function used to pack and install local snaps
. Remove not needed echo
. Change the check of interfaces default behaviour for the
autoconnection to support the scenario when there are other snaps also
connected to the interface (that happens when testing caracalla gadget)
. Add new lines between task tags
There is no way to have "no" confinement as many backends are used
at all times. The names should reflect this.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>