fix #7173: write config: drop empty tag list
When the last tag of a VM gets removed, for example in the web UI, the API gets an empty 'tags' value, which then ends up as an empty 'tags:' line in the config and in the output of 'qm config'. As the config parser reads that line back as a single space, it also gets written out again on every following config change. Skip a tag list without any tag when writing the config, which also cleans up existing configs with such a line on their next change. The pending section still needs to keep it, otherwise the removal of all tags would get lost between writing the pending change and applying it. Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
1 parent
91f98b77f4
commit
b8ae251afe
4 files changed
+20
-1
No files matched your search
@@ -2167,6 +2167,8 @@ sub write_vm_config {
|
|||||||
|
|
||||||
foreach my $key (sort keys %$conf) {
|
foreach my $key (sort keys %$conf) {
|
||||||
next if $key =~ /^(digest|description|pending|snapshots|special-sections)$/;
|
next if $key =~ /^(digest|description|pending|snapshots|special-sections)$/;
|
||||||
|
# an empty tag list is only needed as pending change for removing all tags
|
||||||
|
next if $key eq 'tags' && !$pending && $conf->{$key} =~ m/^\s*$/;
|
||||||
$raw .= "$key: $conf->{$key}\n";
|
$raw .= "$key: $conf->{$key}\n";
|
||||||
}
|
}
|
||||||
return $raw;
|
return $raw;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# empty tag list
|
||||||
|
boot: order=scsi0
|
||||||
|
cores: 1
|
||||||
|
memory: 512
|
||||||
|
name: notags
|
||||||
|
ostype: l26
|
||||||
|
scsi0: local-lvm:vm-100-disk-0,size=4G
|
||||||
|
scsihw: virtio-scsi-single
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# empty tag list
|
||||||
|
boot: order=scsi0
|
||||||
|
cores: 1
|
||||||
|
memory: 512
|
||||||
|
name: notags
|
||||||
|
ostype: l26
|
||||||
|
scsi0: local-lvm:vm-100-disk-0,size=4G
|
||||||
|
scsihw: virtio-scsi-single
|
||||||
|
tags:
|
||||||
@@ -26,7 +26,7 @@ my $OUTPUT_DIR = './parse-config-output';
|
|||||||
my $EXPECTED_DIR = './parse-config-expected';
|
my $EXPECTED_DIR = './parse-config-expected';
|
||||||
|
|
||||||
# NOTE update when you add/remove tests
|
# NOTE update when you add/remove tests
|
||||||
plan tests => 2 * 10;
|
plan tests => 2 * 11;
|
||||||
|
|
||||||
sub run_tests {
|
sub run_tests {
|
||||||
my ($strict) = @_;
|
my ($strict) = @_;
|
||||||
|
|||||||
Reference in new issue
Block a user