From df2999295113a680dc8214ee26f616780dd24037 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Fri, 23 Feb 2024 10:19:18 +0000 Subject: [PATCH 1/2] client/lxd/instances: Adds API extension check for device override on import Signed-off-by: Thomas Parrott --- client/lxd_instances.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/lxd_instances.go b/client/lxd_instances.go index 0c0df9174caa..92e00124d95d 100644 --- a/client/lxd_instances.go +++ b/client/lxd_instances.go @@ -613,6 +613,13 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati } } + if len(args.Devices) > 0 { + err = r.CheckExtension("import_instance_devices") + if err != nil { + return nil, fmt.Errorf("Cannot use device override: %w", err) + } + } + // Prepare the HTTP request reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path)) if err != nil { From 471536d030ef7f089f157022a48a78efe395ec15 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Fri, 23 Feb 2024 10:19:41 +0000 Subject: [PATCH 2/2] test: Updates container devices nic bridged tests with import time device override Signed-off-by: Thomas Parrott --- test/suites/container_devices_nic_bridged.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/suites/container_devices_nic_bridged.sh b/test/suites/container_devices_nic_bridged.sh index dc184153cda8..e6bf8dd6fb8c 100644 --- a/test/suites/container_devices_nic_bridged.sh +++ b/test/suites/container_devices_nic_bridged.sh @@ -633,7 +633,7 @@ test_container_devices_nic_bridged() { lxc copy "${ctName}" foo # Gets new MAC address but IPs still conflict. ! stat "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/foo.eth0" || false lxc snapshot foo - lxc export foo foo.tar.gz + lxc export foo foo.tar.gz # Export in pristine state for import tests below. ! lxc start foo || false lxc config device set foo eth0 \ ipv4.address=192.0.2.233 \ @@ -682,9 +682,16 @@ test_container_devices_nic_bridged() { # Check MAC conflict detection: ! lxc config device set "${ctName}" eth0 hwaddr="0a:92:a7:0d:b7:c9" || false + lxc delete -f foo - # Test container with conflicting addresses rebuilds DHCP lease if original conflicting instance is removed. + # Test container can be imported with device override to fix conflict. + lxc import foo.tar.gz --device eth0,ipv4.address=192.0.2.233 --device eth0,ipv6.address=2001:db8::3 + lxc config device get foo eth0 ipv4.address | grep -Fx '192.0.2.233' + lxc config device get foo eth0 ipv6.address | grep -Fx '2001:db8::3' + lxc start foo lxc delete -f foo + + # Test container with conflicting addresses rebuilds DHCP lease if original conflicting instance is removed. ! stat "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/foo.eth0" || false lxc import foo.tar.gz rm foo.tar.gz