[lxc-devel] [lxd/master] Refreshes dnsmasq config on NIC add/remove

tomponline on Github lxc-bot at linuxcontainers.org
Fri Jun 28 09:34:48 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 439 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190628/a6193b18/attachment-0001.bin>
-------------- next part --------------
From 4379345109129fc6eba78150bf9059154d3fbbad Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 27 Jun 2019 16:33:18 +0100
Subject: [PATCH 1/2] container/lxc: Ensure if bridge nic added/removed that
 dnsmasq config is refreshed

Fixes #5892

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/container_lxc.go | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index c9ed8937e8..3f9cc3b59e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -5786,12 +5786,15 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 		}
 	}
 
-	// Update network leases
+	// Update network leases if a bridged device has changed.
 	needsUpdate := false
-	for _, m := range updateDevices {
-		if m["type"] == "nic" && m["nictype"] == "bridged" {
-			needsUpdate = true
-			break
+	deviceLists := []map[string]types.Device{removeDevices, addDevices, updateDevices}
+	for _, deviceList := range deviceLists {
+		for _, m := range deviceList {
+			if m["type"] == "nic" && m["nictype"] == "bridged" {
+				needsUpdate = true
+				break
+			}
 		}
 	}
 

From 1a72c26893b5aa83e432a7373c1de98219a92422 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 28 Jun 2019 10:30:42 +0100
Subject: [PATCH 2/2] test: Adds test for checking dnsmasq host config is
 refreshed when nic added/removed

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 test/suites/container_devices_nic_bridged.sh | 29 ++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/test/suites/container_devices_nic_bridged.sh b/test/suites/container_devices_nic_bridged.sh
index c29ff68c36..2a4fc66428 100644
--- a/test/suites/container_devices_nic_bridged.sh
+++ b/test/suites/container_devices_nic_bridged.sh
@@ -282,7 +282,36 @@ test_container_devices_nic_bridged() {
     false
   fi
 
+  # Check dnsmasq host file is updated on new device.
+  lxc init testimage "${ctName}" -p "${ctName}"
+  lxc config device add "${ctName}" eth0 nic nictype=bridged parent="${brName}" name=eth0 ipv4.address=192.0.2.200 ipv6.address=2001:db8::200
+
+  ls -lR "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/"
+
+  if ! grep "192.0.2.200" "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/${ctName}" ; then
+    echo "dnsmasq host config not updated with IPv4 address"
+    false
+  fi
+
+  if ! grep "2001:db8::200" "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/${ctName}" ; then
+    echo "dnsmasq host config not updated with IPv6 address"
+    false
+  fi
+
+  lxc config device remove "${ctName}" eth0
+
+  if grep "192.0.2.200" "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/${ctName}" ; then
+    echo "dnsmasq host config still has old IPv4 address"
+    false
+  fi
+
+  if grep "2001:db8::200" "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/${ctName}" ; then
+    echo "dnsmasq host config still has old IPv6 address"
+    false
+  fi
+
   # Cleanup.
+  lxc delete "${ctName}" -f
   lxc network delete "${brName}"
   lxc profile delete "${ctName}"
 }


More information about the lxc-devel mailing list