From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v5 04/16] parse config: be precise about section type checks
Date: Mon, 27 Jan 2025 12:29:11 +0100 [thread overview]
Message-ID: <20250127112923.31703-5-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250127112923.31703-1-f.ebner@proxmox.com>
There are checks for custom parsing behavior inside certain sections
relying only on the section name. While the name 'pending' cannot be
used by snapshots, the name 'cloudinit' can. Introduce an associated
section type to make the checks precise.
The test was not added in a separate commit, because it would fail
when writing the config before the fix, and failure in writing is
never expected by the test script. So there is no easy way to
highlight just the difference in behavior together with the fix and
the git history should stay bisectable.
Compare with the verify-snapshot.conf testcase without the actual fix
applied to see the difference.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
PVE/QemuServer.pm | 18 ++++----
.../cloudinit-snapshot.conf | 40 ++++++++++++++++++
.../cloudinit-snapshot.conf.strict.error | 1 +
.../cloudinit-snapshot.conf | 41 +++++++++++++++++++
test/run_parse_config_tests.pl | 2 +-
5 files changed, 92 insertions(+), 10 deletions(-)
create mode 100644 test/parse-config-expected/cloudinit-snapshot.conf
create mode 100644 test/parse-config-expected/cloudinit-snapshot.conf.strict.error
create mode 100644 test/parse-config-input/cloudinit-snapshot.conf
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 808c0e1c..d8bb21d6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2229,27 +2229,27 @@ sub parse_vm_config {
}
$descr = undef;
};
- my $section = '';
+ my $section = { name => '', type => 'main' };
my @lines = split(/\n/, $raw);
foreach my $line (@lines) {
next if $line =~ m/^\s*$/;
if ($line =~ m/^\[PENDING\]\s*$/i) {
- $section = 'pending';
+ $section = { name => 'pending', type => 'pending' };
$finish_description->();
- $conf = $res->{$section} = {};
+ $conf = $res->{$section->{name}} = {};
next;
} elsif ($line =~ m/^\[special:cloudinit\]\s*$/i) {
- $section = 'cloudinit';
+ $section = { name => 'cloudinit', type => 'special' };
$finish_description->();
- $conf = $res->{$section} = {};
+ $conf = $res->{$section->{name}} = {};
next;
} elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
- $section = $1;
+ $section = { name => $1, type => 'snapshot' };
$finish_description->();
- $conf = $res->{snapshots}->{$section} = {};
+ $conf = $res->{snapshots}->{$section->{name}} = {};
next;
}
@@ -2270,7 +2270,7 @@ sub parse_vm_config {
$conf->{$key} = $value;
} elsif ($line =~ m/^delete:\s*(.*\S)\s*$/) {
my $value = $1;
- if ($section eq 'pending') {
+ if ($section->{name} eq 'pending' && $section->{type} eq 'pending') {
$conf->{delete} = $value; # we parse this later
} else {
$handle_error->("vm $vmid - property 'delete' is only allowed in [PENDING]\n");
@@ -2278,7 +2278,7 @@ sub parse_vm_config {
} elsif ($line =~ m/^([a-z][a-z_\-]*\d*):\s*(.+?)\s*$/) {
my $key = $1;
my $value = $2;
- if ($section eq 'cloudinit') {
+ if ($section->{name} eq 'cloudinit' && $section->{type} eq 'special') {
# ignore validation only used for informative purpose
$conf->{$key} = $value;
next;
diff --git a/test/parse-config-expected/cloudinit-snapshot.conf b/test/parse-config-expected/cloudinit-snapshot.conf
new file mode 100644
index 00000000..bc01f975
--- /dev/null
+++ b/test/parse-config-expected/cloudinit-snapshot.conf
@@ -0,0 +1,40 @@
+boot: order=scsi0
+cores: 2
+cpu: x86-64-v2-AES
+ide2: lvm:vm-120-cloudinit,media=cdrom
+ipconfig0: ip6=dhcp
+memory: 4096
+meta: creation-qemu=9.0.2,ctime=1725975013
+name: deb1223
+net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
+numa: 0
+ostype: l26
+parent: cloudinit
+scsi0: nfs:120/vm-120-disk-0.qcow2,iothread=1,size=4G
+scsihw: virtio-scsi-single
+smbios1: uuid=b3247ab1-1fe6-428e-965b-08a1b64a8746
+sockets: 1
+unused0: rbd:vm-120-disk-0
+vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946
+
+[special:cloudinit]
+ipconfig0: ip=dhcp,ip6=dhcp
+name: deb122
+
+[cloudinit]
+boot: order=scsi0
+cores: 2
+cpu: x86-64-v2-AES
+ide2: lvm:vm-120-cloudinit,media=cdrom
+ipconfig0: ip6=dhcp
+memory: 4096
+meta: creation-qemu=9.0.2,ctime=1725975013
+name: deb1223
+net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
+ostype: l26
+scsi0: nfs:120/vm-120-disk-0.qcow2,iothread=1,size=4G
+scsihw: virtio-scsi-single
+smbios1: uuid=b3247ab1-1fe6-428e-965b-08a1b64a8746
+snaptime: 1737549549
+sockets: 1
+vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946
diff --git a/test/parse-config-expected/cloudinit-snapshot.conf.strict.error b/test/parse-config-expected/cloudinit-snapshot.conf.strict.error
new file mode 100644
index 00000000..1a77d4a5
--- /dev/null
+++ b/test/parse-config-expected/cloudinit-snapshot.conf.strict.error
@@ -0,0 +1 @@
+vm 8006 - unable to parse value of 'numa' - type check ('boolean') failed - got 'verify meee~ :)'
diff --git a/test/parse-config-input/cloudinit-snapshot.conf b/test/parse-config-input/cloudinit-snapshot.conf
new file mode 100644
index 00000000..9be05b1c
--- /dev/null
+++ b/test/parse-config-input/cloudinit-snapshot.conf
@@ -0,0 +1,41 @@
+boot: order=scsi0
+cores: 2
+cpu: x86-64-v2-AES
+ide2: lvm:vm-120-cloudinit,media=cdrom
+ipconfig0: ip6=dhcp
+memory: 4096
+meta: creation-qemu=9.0.2,ctime=1725975013
+name: deb1223
+net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
+numa: 0
+ostype: l26
+parent: cloudinit
+scsi0: nfs:120/vm-120-disk-0.qcow2,iothread=1,size=4G
+scsihw: virtio-scsi-single
+smbios1: uuid=b3247ab1-1fe6-428e-965b-08a1b64a8746
+sockets: 1
+unused0: rbd:vm-120-disk-0
+vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946
+
+[special:cloudinit]
+ipconfig0: ip=dhcp,ip6=dhcp
+name: deb122
+
+[cloudinit]
+boot: order=scsi0
+cores: 2
+cpu: x86-64-v2-AES
+ide2: lvm:vm-120-cloudinit,media=cdrom
+ipconfig0: ip6=dhcp
+memory: 4096
+meta: creation-qemu=9.0.2,ctime=1725975013
+name: deb1223
+net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
+numa: verify meee~ :)
+ostype: l26
+scsi0: nfs:120/vm-120-disk-0.qcow2,iothread=1,size=4G
+scsihw: virtio-scsi-single
+smbios1: uuid=b3247ab1-1fe6-428e-965b-08a1b64a8746
+snaptime: 1737549549
+sockets: 1
+vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946
diff --git a/test/run_parse_config_tests.pl b/test/run_parse_config_tests.pl
index d071f355..51f87ae5 100755
--- a/test/run_parse_config_tests.pl
+++ b/test/run_parse_config_tests.pl
@@ -26,7 +26,7 @@ my $OUTPUT_DIR = './parse-config-output';
my $EXPECTED_DIR = './parse-config-expected';
# NOTE update when you add/remove tests
-plan tests => 2 * 6;
+plan tests => 2 * 7;
sub run_tests {
my ($strict) = @_;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-01-27 11:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-27 11:29 [pve-devel] [PATCH-SERIES qemu-server v5 00/16] more robust handling of fleecing images Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 01/16] migration: remove unused variable Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 02/16] test: avoid duplicate mock module in restore config test Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 03/16] test: add parse config tests Fiona Ebner
2025-01-27 11:29 ` Fiona Ebner [this message]
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 05/16] test: add test case exposing issue with unknown sections Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 06/16] parse config: skip unknown sections and warn about their presence Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 07/16] vzdump: anchor matches for pending and special sections Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 08/16] vzdump: skip all " Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 09/16] config: make special section handling generic Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 10/16] test: parse config: test config with duplicate sections Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 11/16] parse config: warn about " Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 12/16] check type: require schema as an argument Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 13/16] config: add fleecing section Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 14/16] fix #5440: vzdump: better cleanup fleecing images after hard errors Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 15/16] migration: attempt to clean up potential left-over fleecing images Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 16/16] destroy vm: " Fiona Ebner
2025-03-07 10:45 ` [pve-devel] [PATCH-SERIES qemu-server v5 00/16] more robust handling of " Fiona Ebner
2025-04-07 13:11 ` [pve-devel] 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=20250127112923.31703-5-f.ebner@proxmox.com \
--to=f.ebner@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal