Files
snapd/tests/lib/tools/network-state
Sergio Cazzolato 6d34193eee tests: new store-state tool (#12575)
* New store-state tool

This is the new store tool inclusing a new test. Also it is included a
network-state tool

Still missing some parts of the test and a new test for the network
state tool. This can be added in a following pr including the migration
from the network-state helper to the new tool in all the tests

* Fix wording in comment

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 49f30b6a47..92bb6a0664

92bb6a0664 Include snap-sufix in the snaps.name tool
1c8efb77e1 Update default values for wait-for reboot

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: 92bb6a066478a46018297e23a409ec01fb682b37

* update tools using lower case vars and scoped vars

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 92bb6a0664..89b9eb5301

89b9eb5301 Update systems supported

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: 89b9eb5301b6b8021e42d71162a7d4860279ad0b

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 89b9eb5301..a7164fba07

a7164fba07 remove fedora 35 support, add fedora 37 support

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: a7164fba070cb36fce40714b9a5c84f35867495b

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from a7164fba07..3232c5dba7

3232c5dba7 Add support for ubuntu 23.04

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: 3232c5dba768f226213bfaec56bced7c384f140f

* new lines

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 3232c5dba7..d90935d2a4

d90935d2a4 A comment explaining about the default values for wait-for

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: d90935d2a4000bd17c7a8a2754adb66f8234bb9b

* skip ubuntu trusty for store-state test because systemd-run is not supported

* Fix systems for store-state test
2023-03-14 10:35:13 -03:00

68 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
show_help() {
echo "usage: network-state get-default-iface"
echo " network-state wait-listen-port <PORT>"
echo " network-state make-network-service <SERVICE_NAME> <PORT>"
}
get_default_iface(){
ip route get 8.8.8.8 | awk '{ print $5; exit }'
}
wait_listen_port(){
local port="$1"
for _ in $(seq 120); do
if ss -lnt | grep -Pq "LISTEN.*?:$port +.*?\\n*"; then
break
fi
sleep 0.5
done
# Ensure we really have the listen port, this will fail with an
# exit code if the port is not available.
ss -lnt | grep -Pq "LISTEN.*?:$port +.*?\\n*"
}
make_network_service() {
local service_name="$1"
local port="$2"
systemd-run --unit "$service_name" sh -c "while true; do printf 'HTTP/1.1 200 OK\\n\\nok\\n' | nc -l -p $port -w 1; done"
wait_listen_port "$port"
}
main() {
if [ $# -eq 0 ]; then
show_help
exit 0
fi
local subcommand=$1
local action=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
*)
action=$(echo "$subcommand" | tr '-' '_')
shift
break
;;
esac
done
if [ -z "$(declare -f "$action")" ]; then
echo "network-state: no such command $subcommand" >&2
show_help
exit 1
fi
"$action" "$@"
}
main "$@"