Browse code

Merge pull request #50819 from akerouanton/firewalld-ci

hack/make/test-integration: disable firewalld integration

Albin Kerouanton authored on 2025/08/28 17:44:07
Showing 4 changed files
... ...
@@ -5,6 +5,7 @@ package iptables
5 5
 import (
6 6
 	"context"
7 7
 	"fmt"
8
+	"os"
8 9
 	"strings"
9 10
 	"sync"
10 11
 	"sync/atomic"
... ...
@@ -64,6 +65,14 @@ func FirewalldReloadedAt() time.Time {
64 64
 func firewalldInit() error {
65 65
 	var err error
66 66
 
67
+	// DOCKER_TEST_NO_FIREWALLD is used by integration tests to disable firewalld integration to make sure that the
68
+	// daemon started by the 'test-integration' script won't recreate iptables / nftables rules upon receiving the
69
+	// firewalld reload signal, otherwise it'll race against the daemon-under-test started by networking integration
70
+	// tests. This is an internal implementation detail and users shall never rely on this.
71
+	if disable := os.Getenv("DOCKER_TEST_NO_FIREWALLD"); disable != "" {
72
+		return nil
73
+	}
74
+
67 75
 	if connection, err = newConnection(); err != nil {
68 76
 		return fmt.Errorf("Failed to connect to D-Bus system bus: %v", err)
69 77
 	}
... ...
@@ -119,6 +119,14 @@ if [ -z "$DOCKER_TEST_HOST" ]; then
119 119
 	(
120 120
 		echo "Starting dockerd"
121 121
 		[ -n "$TESTDEBUG" ] && set -x
122
+		if [ -n "${FIREWALLD:-}" ] && [ "${DOCKER_FIREWALL_BACKEND:-}" == "iptables" ]; then
123
+			# Networking integration tests start their own daemon to have fine control over the configuration of the
124
+			# daemon-under-test. Two daemons running with firewalld integration enabled would race against each other
125
+			# when the firewalld reload signal is dispatched, and would result in iptables disappearing unexpectedly
126
+			# from the point of view of the daemon-under-test. So, disable firewalld integration on this daemon, as it's
127
+			# only used to load frozen images.
128
+			export DOCKER_TEST_NO_FIREWALLD="true"
129
+		fi
122 130
 		exec \
123 131
 			${dockerd} --debug \
124 132
 			--host "$DOCKER_HOST" \
... ...
@@ -369,7 +369,13 @@ func TestFilterForwardPolicy(t *testing.T) {
369 369
 // address is reserved for a gateway, because it won't be used).
370 370
 func TestPointToPoint(t *testing.T) {
371 371
 	ctx := setupTest(t)
372
-	apiClient := testEnv.APIClient()
372
+
373
+	d := daemon.New(t)
374
+	d.StartWithBusybox(ctx, t)
375
+	t.Cleanup(func() { d.Stop(t) })
376
+
377
+	apiClient := d.NewClientT(t)
378
+	t.Cleanup(func() { apiClient.Close() })
373 379
 
374 380
 	testcases := []struct {
375 381
 		name   string
... ...
@@ -423,7 +429,13 @@ func TestIsolated(t *testing.T) {
423 423
 	skip.If(t, testEnv.IsRootless, "can't inspect bridge addrs in rootless netns")
424 424
 
425 425
 	ctx := setupTest(t)
426
-	apiClient := testEnv.APIClient()
426
+
427
+	d := daemon.New(t)
428
+	d.StartWithBusybox(ctx, t)
429
+	t.Cleanup(func() { d.Stop(t) })
430
+
431
+	apiClient := d.NewClientT(t)
432
+	t.Cleanup(func() { apiClient.Close() })
427 433
 
428 434
 	const netName = "testisol"
429 435
 	const bridgeName = "br-" + netName
... ...
@@ -6,6 +6,7 @@ import (
6 6
 
7 7
 	"github.com/moby/moby/client"
8 8
 	"github.com/moby/moby/v2/integration/internal/testutils/networking"
9
+	"github.com/moby/moby/v2/testutil/daemon"
9 10
 	"github.com/moby/moby/v2/testutil/request"
10 11
 	"gotest.tools/v3/assert"
11 12
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -15,7 +16,13 @@ const defaultFirewallBackend = "iptables"
15 15
 
16 16
 func TestInfoFirewallBackend(t *testing.T) {
17 17
 	ctx := setupTest(t)
18
-	c := testEnv.APIClient()
18
+
19
+	d := daemon.New(t)
20
+	d.StartWithBusybox(ctx, t)
21
+	t.Cleanup(func() { d.Stop(t) })
22
+
23
+	c := d.NewClientT(t)
24
+	t.Cleanup(func() { c.Close() })
19 25
 
20 26
 	expDriver := defaultFirewallBackend
21 27
 	if val := os.Getenv("DOCKER_FIREWALL_BACKEND"); val != "" {