libnetwork/iptables: Use UsingFirewalld in remaining firewalld paths
AddInterfaceFirewalld and DelInterfaceFirewalld read firewalldRunning directly, so they silently no-oped when called before any iptables operation had triggered firewalld initialization. Now they call UsingFirewalld, which initializes firewalld on first use. The firewalld tests called firewalldInit directly and then ran the same initialization again through the once guard, creating a second D-Bus connection and signal-handler goroutine. Now they assert UsingFirewalld instead. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
2 files changed
+8
-11
No files matched your search
@@ -313,7 +313,7 @@ func setupDockerForwardingPolicy() (bool, error) {
|
||||
// AddInterfaceFirewalld adds the interface to the trusted zone. It is a
|
||||
// no-op if firewalld is not running.
|
||||
func AddInterfaceFirewalld(intf string) error {
|
||||
if !firewalldRunning.Load() {
|
||||
if !UsingFirewalld() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ func AddInterfaceFirewalld(intf string) error {
|
||||
// DelInterfaceFirewalld removes the interface from the trusted zone It is a
|
||||
// no-op if firewalld is not running.
|
||||
func DelInterfaceFirewalld(intf string) error {
|
||||
if !firewalldRunning.Load() {
|
||||
if !UsingFirewalld() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ func skipIfNoFirewalld(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Skipf("cannot connect to D-bus system bus: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
var zone string
|
||||
err = conn.Object(dbusInterface, dbusPath).Call(dbusInterface+".getDefaultZone", 0).Store(&zone)
|
||||
if err != nil {
|
||||
@@ -25,10 +23,10 @@ func skipIfNoFirewalld(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirewalldInit(t *testing.T) {
|
||||
func TestUsingFirewalld(t *testing.T) {
|
||||
skipIfNoFirewalld(t)
|
||||
if err := firewalldInit(); err != nil {
|
||||
t.Fatal(err)
|
||||
if !UsingFirewalld() {
|
||||
t.Fatal("firewalld is running, but UsingFirewalld() is false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +95,10 @@ func TestPassthrough(t *testing.T) {
|
||||
"-j", "ACCEPT",
|
||||
}
|
||||
|
||||
err := firewalldInit()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if !UsingFirewalld() {
|
||||
t.Fatal("firewalld is running, but UsingFirewalld() is false")
|
||||
}
|
||||
_, err = passthrough(IPv4, rule1...)
|
||||
_, err := passthrough(IPv4, rule1...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user