hwdb: fix screen rotation for EXO Wings 2in1 w1125 (#36283)
[systemd.io.git] / test / units / TEST-13-NSPAWN.nss-mymachines.sh
blob817431b449ad38ae2cc43bddec4e557b0d3288e2
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # shellcheck disable=SC2016
4 set -eux
5 set -o pipefail
7 # shellcheck source=test/units/util.sh
8 . "$(dirname "$0")"/util.sh
10 at_exit() {
11 set +e
13 machinectl kill --signal=KILL nss-mymachines-{noip,singleip,manyips}
14 mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done"
15 rm -f /run/systemd/nspawn/*.nspawn
18 trap at_exit EXIT
20 # Mount temporary directory over /var/lib/machines to not pollute the image
21 mkdir -p /var/lib/machines
22 mount --bind "$(mktemp --tmpdir=/var/tmp -d)" /var/lib/machines
24 # Create a bunch of containers that:
25 # 1) Have no IP addresses assigned
26 create_dummy_container /var/lib/machines/nss-mymachines-noip
27 cat >/var/lib/machines/nss-mymachines-noip/sbin/init <<\EOF
28 #!/usr/bin/bash -ex
30 ip addr show dev ve-noip
31 touch /initialized
32 sleep infinity &
33 # Run the sleep command asynchronously, so bash is able to process signals
34 while :; do
35 wait || :
36 done
37 EOF
38 # 2) Have one IP address assigned (IPv4 only)
39 create_dummy_container /var/lib/machines/nss-mymachines-singleip
40 cat >/var/lib/machines/nss-mymachines-singleip/sbin/init <<\EOF
41 #!/usr/bin/bash -ex
43 ip addr add 10.1.0.2/24 dev ve-singleip
44 ip addr show dev ve-singleip
45 touch /initialized
46 sleep infinity &
47 while :; do
48 wait || :
49 done
50 EOF
51 # 3) Have bunch of IP addresses assigned (both IPv4 and IPv6)
52 create_dummy_container /var/lib/machines/nss-mymachines-manyips
53 cat >/var/lib/machines/nss-mymachines-manyips/sbin/init <<\EOF
54 #!/usr/bin/bash -ex
56 ip addr add 10.2.0.2/24 dev ve-manyips
57 for i in {100..120}; do
58 ip addr add 10.2.0.$i/24 dev ve-manyips
59 done
60 ip addr add fd00:dead:beef:cafe::2/64 dev ve-manyips nodad
61 ip addr show dev ve-manyips
62 touch /initialized
63 sleep infinity
64 while :; do
65 wait || :
66 done
67 EOF
68 # Create the respective .nspawn config files
69 mkdir -p /run/systemd/nspawn
70 for container in noip singleip manyips; do
71 cat >"/run/systemd/nspawn/nss-mymachines-$container.nspawn" <<EOF
72 [Exec]
73 Boot=yes
75 [Network]
76 VirtualEthernetExtra=ve-$container
77 EOF
78 done
80 # Start the containers and wait until all of them are initialized
81 machinectl start nss-mymachines-{noip,singleip,manyips}
82 for container in nss-mymachines-{noip,singleip,manyips}; do
83 timeout 30 bash -xec "while [[ ! -e /var/lib/machines/$container/initialized ]]; do sleep .5; done"
84 done
86 # We need to configure the dummy interfaces on the "outside" as well for `getent {ahosts4,ahosts6}` to work
87 # properly. This is caused by getaddrinfo() calling _check_pf() that iterates through all interfaces and
88 # notes if any of them has an IPv4/IPv6 - this is then used together with AF_INET/AF_INET6 to determine if we
89 # can ever return a valid answer, and if we configured the container interfaces only in the container, we
90 # would have no valid IPv4/IPv6 on the "outside" (as we don't set up any other netdev) which would make
91 # getaddrinfo() return EAI_NONAME without ever asking nss-mymachines.
92 ip addr add 10.1.0.1/24 dev ve-singleip
93 ip addr add 10.2.0.1/24 dev ve-manyips
94 ip addr add fd00:dead:beef:cafe::1/64 dev ve-manyips nodad
96 getent hosts -s mymachines
97 getent ahosts -s mymachines
99 # And finally check if we can resolve the containers via nss-mymachines
100 for database in hosts ahosts{,v4,v6}; do
101 (! getent "$database" -s mymachines nss-mymachines-noip)
102 done
104 run_and_grep "^10\.1\.0\.2\s+nss-mymachines-singleip$" getent hosts -s mymachines nss-mymachines-singleip
105 run_and_grep "^10\.1\.0\.2\s+STREAM" getent ahosts -s mymachines nss-mymachines-singleip
106 run_and_grep "^10\.1\.0\.2\s+STREAM" getent ahostsv4 -s mymachines nss-mymachines-singleip
107 run_and_grep "^::ffff:10\.1\.0\.2\s+STREAM" getent ahostsv6 -s mymachines nss-mymachines-singleip
109 run_and_grep "^fd00:dead:beef:cafe::2\s+nss-mymachines-manyips$" getent hosts -s mymachines nss-mymachines-manyips
110 run_and_grep "^fd00:dead:beef:cafe::2\s+STREAM" getent ahosts -s mymachines nss-mymachines-manyips
111 run_and_grep "^10\.2\.0\.2\s+STREAM" getent ahosts -s mymachines nss-mymachines-manyips
112 for i in {100..120}; do
113 run_and_grep "^10\.2\.0\.$i\s+STREAM" getent ahosts -s mymachines nss-mymachines-manyips
114 run_and_grep "^10\.2\.0\.$i\s+STREAM" getent ahostsv4 -s mymachines nss-mymachines-manyips
115 done
116 run_and_grep "^fd00:dead:beef:cafe::2\s+STREAM" getent ahostsv6 -s mymachines nss-mymachines-manyips
117 (! run_and_grep "^fd00:" getent ahostsv4 -s mymachines nss-mymachines-manyips)
118 (! run_and_grep "^10\.2:" getent ahostsv6 -s mymachines nss-mymachines-manyips)
120 # Multiple machines at once
121 run_and_grep "^10\.1\.0\.2\s+nss-mymachines-singleip$" getent hosts -s mymachines nss-mymachines-{singleip,manyips}
122 run_and_grep "^fd00:dead:beef:cafe::2\s+nss-mymachines-manyips$" getent hosts -s mymachines nss-mymachines-{singleip,manyips}
123 run_and_grep "^10\.1\.0\.2\s+STREAM" getent ahosts -s mymachines nss-mymachines-{singleip,manyips}
124 run_and_grep "^10\.2\.0\.2\s+STREAM" getent ahosts -s mymachines nss-mymachines-{singleip,manyips}
125 run_and_grep "^fd00:dead:beef:cafe::2\s+STREAM" getent ahosts -s mymachines nss-mymachines-{singleip,manyips}
127 for database in hosts ahosts ahostsv4 ahostsv6; do
128 (! getent "$database" -s mymachines foo-bar-baz)
129 done
131 # getgrid(), getgrnam(), getpwuid(), and getpwnam() are explicitly handled by nss-mymachines, so probe them
132 # as well
133 (! getent group -s mymachines foo 11)
134 (! getent passwd -s mymachines foo 11)
136 machinectl stop nss-mymachines-{noip,singleip,manyips}