public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lucas Barros <lucasbarros.kam@gmail.com>
To: pve-devel@lists.proxmox.com
Cc: Lucas Barros <lucasbarros.kam@gmail.com>
Subject: [PATCH container v2 4/5] config: ignore an empty tag list when parsing
Date: Sun, 15 Nov 2026 22:00:39 -0300	[thread overview]
Message-ID: <20261116010040.90964-5-lucasbarros.kam@gmail.com> (raw)
In-Reply-To: <20261116010040.90964-1-lucasbarros.kam@gmail.com>

Configs of containers whose last tag was removed before the previous
commit still contain a 'tags: ' line. It is read as a tag list
consisting of a single space and shows up as such in the API, while a
'tags:' line without the trailing space is reported as a line that
cannot be parsed.

An empty tag list is the same as having no tags, so skip such a line
when parsing, like an unset option. Use split_list() to decide whether
the list is empty, so a value consisting only of delimiters is handled
the same way. Configs that contain such a line lose it on the next
write.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
---
changes since v1:
* new patch, replaces the writer change of v1

The new subtest builds the config in a string, so the 'tags: ' case
with the trailing space is covered without trailing whitespace in the
test file.

This patch was prepared with the help of an LLM based coding assistant;
I reviewed the change and ran the tests mentioned in the cover letter
myself.

 src/PVE/LXC/Config.pm    |  3 +++
 src/test/config_tests.pl | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 7052509..2d47228 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1199,6 +1199,9 @@ sub parse_pct_config {
             } else {
                 $handle_error->("vm $vmid - property 'delete' is only allowed in [pve:pending]\n");
             }
+        } elsif ($line =~ m/^tags:\s*(.*?)\s*$/ && !PVE::Tools::split_list($1)) {
+            # an empty tag list is the same as no tags
+            next;
         } elsif ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) {
             my $key = $1;
             my $value = $2;
diff --git a/src/test/config_tests.pl b/src/test/config_tests.pl
index fbf1771..855681e 100755
--- a/src/test/config_tests.pl
+++ b/src/test/config_tests.pl
@@ -151,4 +151,25 @@ subtest 'parsing drops keys outside of the schema' => sub {
     is($conf->{memory}, 'invalid', 'invalid value of a known key is kept');
 };
 
+subtest 'parsing ignores an empty tag list' => sub {
+    # 'tags: ' with the trailing space is what got written after removing the last tag
+    for my $tags ('', ' ', ' ;, ') {
+        my $raw = "hostname: ct100\ntags:$tags\n";
+
+        my $conf;
+        {
+            my $warnings = '';
+            local $SIG{__WARN__} = sub { $warnings .= $_[0] };
+            $conf = PVE::LXC::Config::parse_pct_config('/lxc/100.conf', $raw);
+            is($warnings, '', "no warning for 'tags:$tags'");
+        }
+
+        is($conf->{hostname}, 'ct100', 'valid key is kept');
+        ok(!exists($conf->{tags}), "'tags:$tags' is dropped");
+    }
+
+    my $conf = PVE::LXC::Config::parse_pct_config('/lxc/100.conf', "tags: a;b\n");
+    is($conf->{tags}, 'a;b', 'non-empty tag list is kept');
+};
+
 done_testing();
-- 
2.50.1 (Apple Git-155)




  parent reply	other threads:[~2026-11-16  1:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 13:56 [PATCH qemu-server] fix #7173: config: do not write out an empty tag list Lucas Barros
2026-11-11  9:53 ` Fabian Grünbichler
2026-11-16  1:00   ` [PATCH qemu-server/container/manager v2 0/5] fix #7173: do not keep an empty tag list in guest configs Lucas Barros
2026-11-16  1:00     ` [PATCH qemu-server v2 1/5] fix #7173: api: update: delete tags when an empty tag list is set Lucas Barros
2026-11-16  1:00     ` [PATCH qemu-server v2 2/5] config: ignore an empty tag list when parsing Lucas Barros
2026-11-16  1:00     ` [PATCH container v2 3/5] fix #7173: api: update: delete tags when an empty tag list is set Lucas Barros
2026-11-16  1:00     ` Lucas Barros [this message]
2026-11-16  1:00     ` [PATCH manager v2 5/5] fix #7173: ui: guest: delete tags when removing the last tag Lucas Barros

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=20261116010040.90964-5-lucasbarros.kam@gmail.com \
    --to=lucasbarros.kam@gmail.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