]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: create .netdev file at last
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 18 Sep 2024 23:43:51 +0000 (08:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Sep 2024 05:50:10 +0000 (14:50 +0900)
Previously, when the test ran on mkosi, then networkd was not masked, and
might be already started. In that case, the interface test2 would be created
soon after the .netdev file is created, and the .link file would not be
applied to the interface. Hence, the later test case for
'networkctl cat @test2:link' would fail.

This make networkd always started at the beginning of the test, and
.netdev file created after .link file is created. So, .link file is
always applied to the interface created by the .netdev file.

test/units/TEST-74-AUX-UTILS.networkctl.sh

index 0576d6c055635eec6784b4652f326176d2174af3..3d402a7182f6b7f241e48515d4e673bce180e424 100755 (executable)
@@ -21,6 +21,9 @@ at_exit() {
 
 trap at_exit EXIT
 
+systemctl unmask systemd-networkd.service
+systemctl start systemd-networkd.service
+
 export NETWORK_NAME="10-networkctl-test-$RANDOM.network"
 export NETDEV_NAME="10-networkctl-test-$RANDOM.netdev"
 export LINK_NAME="10-networkctl-test-$RANDOM.link"
@@ -75,15 +78,6 @@ cmp "+4" "/etc/systemd/network/${NETWORK_NAME}.d/test.conf"
 networkctl cat "$NETWORK_NAME" | grep '^# ' |
     cmp - <(printf '%s\n' "# /etc/systemd/network/$NETWORK_NAME" "# /etc/systemd/network/${NETWORK_NAME}.d/test.conf")
 
-networkctl edit --stdin --runtime "$NETDEV_NAME" <<EOF
-[NetDev]
-Name=test2
-Kind=dummy
-EOF
-
-networkctl cat "$NETDEV_NAME" | grep -v '^# ' |
-    cmp - <(printf '%s\n' "[NetDev]" "Name=test2" "Kind=dummy")
-
 cat >"/usr/lib/systemd/network/$LINK_NAME" <<EOF
 [Match]
 OriginalName=test2
@@ -95,13 +89,23 @@ EOF
 SYSTEMD_LOG_LEVEL=debug EDITOR='true' script -ec 'networkctl edit "$LINK_NAME"' /dev/null
 cmp "/usr/lib/systemd/network/$LINK_NAME" "/etc/systemd/network/$LINK_NAME"
 
-# Test links
-systemctl unmask systemd-networkd
-systemctl stop systemd-networkd
+# The interface test2 does not exist, hence the below do not work.
 (! networkctl cat @test2)
 (! networkctl cat @test2:netdev)
+(! networkctl cat @test2:link)
+(! networkctl cat @test2:network)
+
+# create .netdev file at last, otherwise, the .link file will not be applied to the interface.
+networkctl edit --stdin --runtime "$NETDEV_NAME" <<EOF
+[NetDev]
+Name=test2
+Kind=dummy
+EOF
+
+networkctl cat "$NETDEV_NAME" | grep -v '^# ' |
+    cmp - <(printf '%s\n' "[NetDev]" "Name=test2" "Kind=dummy")
 
-systemctl start systemd-networkd
+# wait for the interface being created and configured.
 SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/systemd-networkd-wait-online -i test2:carrier --timeout 20
 
 networkctl cat @test2:network | cmp - <(networkctl cat "$NETWORK_NAME")