public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-container 3/6] restore: add missing MAC addresses of the backup config
Date: Tue, 24 Nov 2026 15:56:47 +0100	[thread overview]
Message-ID: <20261124145651.335234-4-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261124145651.335234-1-s.hanreich@proxmox.com>

A restore without 'unique' takes over the network devices of the backup
config as they are, so a device without 'hwaddr' stays without one
until the container is started.

Add the missing MAC addresses when merging the backup config, so that
the restored config is complete right away. Existing ones are kept, as
without 'unique' the restored container should have the same addresses
as the backed up one.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/PVE/LXC/Create.pm    |  3 +++
 src/test/config_tests.pl | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index c39e8ca..4a62a37 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -607,6 +607,9 @@ sub sanitize_and_merge_config {
         }
         $conf->{$key} = $oldconf->{$key} if !defined($conf->{$key});
     }
+
+    # a backup can have network devices without a MAC address
+    PVE::LXC::Config->add_missing_hwaddrs($conf);
 }
 
 sub restore_configuration_from_etc_vzdump {
diff --git a/src/test/config_tests.pl b/src/test/config_tests.pl
index 182c4bf..868ea84 100755
--- a/src/test/config_tests.pl
+++ b/src/test/config_tests.pl
@@ -191,6 +191,29 @@ subtest 'restore does not take over pending changes of the backup' => sub {
     }
 };
 
+subtest 'restore adds missing MAC addresses of the backup' => sub {
+    PVE::RPCEnvironment::get()->set_user('root@pam');
+
+    my $cluster_module = Test::MockModule->new('PVE::Cluster');
+    $cluster_module->mock(
+        cfs_read_file => sub {
+            my ($filename) = @_;
+            die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
+            return { mac_prefix => 'BC:24:11' };
+        },
+    );
+
+    my $with_hwaddr = 'name=eth0,bridge=vmbr0,hwaddr=BC:24:11:00:00:01,type=veth';
+    my $raw = "hostname: ct100\nnet0: $with_hwaddr\nnet1: name=eth1,bridge=vmbr0,type=veth\n";
+    my $backup = PVE::LXC::Config::parse_pct_config('/lxc/100.conf', $raw);
+
+    my $conf = {};
+    PVE::LXC::Create::sanitize_and_merge_config($conf, $backup, 0, 0);
+    is($conf->{net0}, $with_hwaddr, 'MAC address of the backup is kept');
+    my $net1 = PVE::LXC::Config->parse_lxc_network($conf->{net1}, 1);
+    like($net1->{hwaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'missing MAC address is added');
+};
+
 subtest 'meta property' => sub {
     like(PVE::LXC::Config->new_meta_info_string(), qr/^ctime=\d+$/, 'creation time is set');
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-24 14:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-container 2/6] start: persist a MAC address for network devices without one Stefan Hanreich
2026-11-24 18:06   ` Dominik Csapak
2026-11-24 14:56 ` Stefan Hanreich [this message]
2026-11-24 14:56 ` [PATCH qemu-server 4/6] " Stefan Hanreich
2026-11-24 18:06   ` Dominik Csapak
2026-11-24 14:56 ` [PATCH qemu-server 5/6] restore: add missing MAC addresses of the backup config Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-manager 6/6] ui: lxc: network: handle network devices without a MAC address Stefan Hanreich
2026-11-24 18:06 ` [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Dominik Csapak
2026-11-24 18:38   ` Dominik Csapak
2026-11-24 19:09   ` Stefan Hanreich
2026-11-24 23:45 ` applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124145651.335234-4-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal