[pve-devel] [PATCH proxmox-ve] apt hook: disable on remove

2024-03-07 Thread Fabian Grünbichler
and (re-)enable on install. adapted from apt-listbugs/apt-listchanges, which
solve the issue of removing (instead of purging) the package keeping the
conffile while removing the hook binary in the same fashion.

Signed-off-by: Fabian Grünbichler 
---
tested with:
- touch /please-remove-proxmox-ve
- remove proxmox-ve (works, hook config moved out of the way)
- purge proxmox-ve (works, disabled config removed)
- reinstall proxmox-ve (works, hook config reappears)

- touch /please-remove-proxmox-ve
- remove (works, hook config moved out of the way)
- reinstall (works, hook config reappears)

- touch /please-remove-proxmox-ve
- purge proxmox-ve (works, hook config removed)
- reinstall (works, hook config reappears)

 debian/proxmox-ve.postrm  | 33 +
 debian/proxmox-ve.preinst | 13 +
 2 files changed, 46 insertions(+)
 create mode 100644 debian/proxmox-ve.postrm
 create mode 100644 debian/proxmox-ve.preinst

diff --git a/debian/proxmox-ve.postrm b/debian/proxmox-ve.postrm
new file mode 100644
index 000..f3eff33
--- /dev/null
+++ b/debian/proxmox-ve.postrm
@@ -0,0 +1,33 @@
+#! /bin/sh
+set -e
+
+hook=/etc/apt/apt.conf.d/10pveapthook
+
+case "$1" in
+purge)
+rm -f $hook.disabled
+;;
+
+remove)
+mv $hook $hook.disabled
+;;
+
+abort-install)
+if test "x$2" != "x" && test -f $hook
+then
+mv $hook $hook.disabled
+fi
+;;
+
+upgrade|failed-upgrade|abort-upgrade|disappear)
+;;
+
+*)
+echo "postrm called with unknown argument \`$1'" >&2
+exit 1
+
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/proxmox-ve.preinst b/debian/proxmox-ve.preinst
new file mode 100644
index 000..e190c3d
--- /dev/null
+++ b/debian/proxmox-ve.preinst
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+hook=/etc/apt/apt.conf.d/10pveapthook
+if test -f $hook.disabled
+then
+mv $hook.disabled $hook
+fi
+
+#DEBHELPER#
+
+exit 0
-- 
2.39.2



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server] mediated devices: fix race condition in vm reboot

2024-03-07 Thread Dominik Csapak
when triggering a vm reboot from the host (via cli/api), the reboot code
is called under a guest lock, which creates a reboot request, shuts down
the vm and calls the regular cleanup code (which includes the mdev
cleanup).

in parallel the qmeventd sees the vanished vm, and starts 'qm cleanup'
which is (among other tasks) used to restart a vm with a pending reboot
request. It does this also under a guest lock, with a default timeout of
10 seconds.

Since we currently wait 10 seconds for the nvidia driver to clean the
mdev, this creates a race condition for the cleanup lock. Iow. when the
call to `qm cleanup` starts before we started to sleep for 10 seconds,
it will not be able to acquire its lock and not start the vm again.

To fix it, do two things:
* increase the timeout in `qm cleanup` to 60 seconds
  (technically this still might run into a timeout, as we can configure
  up to 16 mediated devices with up to 10 seconds sleep each, but
  realistically most users won't configure more than two or three of
  them, if even that)

* change the `sleep 10` to a loop sleeping for 1 second each before
  checking the state again. This shortens the timeout when the driver
  can clean it up in the meantime.

Further, add a bit of logging, so we can properly see in the (task) log
what is happening when.

Fixes: 49c51a60 (pci: workaround nvidia driver issue on mdev cleanup)
Signed-off-by: Dominik Csapak 
---
 PVE/CLI/qm.pm |  3 ++-
 PVE/QemuServer.pm | 16 
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index b17b4fe2..dce6c7a1 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -915,7 +915,8 @@ __PACKAGE__->register_method({
my $storecfg = PVE::Storage::config();
warn "Starting cleanup for $vmid\n";
 
-   PVE::QemuConfig->lock_config($vmid, sub {
+   # mdev cleanup can take a while, so wait up to 60 seconds
+   PVE::QemuConfig->lock_config_full($vmid, 60, sub {
my $conf = PVE::QemuConfig->load_config ($vmid);
my $pid = PVE::QemuServer::check_running ($vmid);
die "vm still running\n" if $pid;
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b45507aa..efe93c62 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6133,12 +6133,20 @@ sub cleanup_pci_devices {
my $dev_sysfs_dir = "/sys/bus/mdev/devices/$uuid";
 
# some nvidia vgpu driver versions want to clean the mdevs up 
themselves, and error
-   # out when we do it first. so wait for 10 seconds and then try it
-   if ($d->{ids}->[0]->[0]->{vendor} =~ m/^(0x)?10de$/) {
-   sleep 10;
+   # out when we do it first. so wait for up to 10 seconds and then 
try it manually
+   if ($d->{ids}->[0]->[0]->{vendor} =~ m/^(0x)?10de$/ && -e 
$dev_sysfs_dir) {
+   my $count = 0;
+   while (-e $dev_sysfs_dir && $count < 10) {
+   sleep 1;
+   $count++;
+   }
+   warn "waited $count seconds for mdev cleanup\n";
}
 
-   PVE::SysFSTools::file_write("$dev_sysfs_dir/remove", "1") if -e 
$dev_sysfs_dir;
+   if (-e $dev_sysfs_dir) {
+   warn "cleaning up mediated device $uuid\n";
+   PVE::SysFSTools::file_write("$dev_sysfs_dir/remove", "1");
+   }
}
 }
 PVE::QemuServer::PCI::remove_pci_reservation($vmid);
-- 
2.39.2



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH proxmox] proxmox-acme: add api-types feature

2024-03-07 Thread Dietmar Maurer
Because AccountData is exposed via our API (currently as type Object).

Signed-off-by: Dietmar Maurer 
---
 proxmox-acme/Cargo.toml | 3 +++
 proxmox-acme/src/account.rs | 7 +++
 proxmox-acme/src/eab.rs | 5 +
 3 files changed, 15 insertions(+)

diff --git a/proxmox-acme/Cargo.toml b/proxmox-acme/Cargo.toml
index 8f8f6e1..857c61d 100644
--- a/proxmox-acme/Cargo.toml
+++ b/proxmox-acme/Cargo.toml
@@ -19,6 +19,8 @@ openssl.workspace = true
 # For the client
 native-tls = { workspace = true, optional = true }
 
+proxmox-schema = { workspace = true, optional = true, features = [ 
"api-macro", "api-types" ] }
+
 [dependencies.ureq]
 optional = true
 version = "2.4"
@@ -27,6 +29,7 @@ features = [ "native-tls", "gzip" ]
 
 [features]
 default = []
+api-types = [ "dep:proxmox-schema" ]
 client = ["ureq", "native-tls"]
 
 [dev-dependencies]
diff --git a/proxmox-acme/src/account.rs b/proxmox-acme/src/account.rs
index 9f3af26..e244c09 100644
--- a/proxmox-acme/src/account.rs
+++ b/proxmox-acme/src/account.rs
@@ -279,6 +279,7 @@ impl CertificateRevocation<'_> {
 }
 
 /// Status of an ACME account.
+#[cfg_attr(feature="api-types", proxmox_schema::api())]
 #[derive(Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub enum AccountStatus {
@@ -309,6 +310,12 @@ impl AccountStatus {
 }
 }
 
+#[cfg_attr(feature="api-types", proxmox_schema::api(
+properties: {
+extra: { type: Object, properties: {}, additional_properties: true },
+contact: { type: Array, items: { type: String, description: "Contact 
Info." }}
+}
+))]
 /// ACME Account data. This is the part of the account returned from and 
possibly sent to the ACME
 /// provider. Some fields may be uptdated by the user via a request to the 
account location, others
 /// may not be changed.
diff --git a/proxmox-acme/src/eab.rs b/proxmox-acme/src/eab.rs
index a4c0642..f006a3f 100644
--- a/proxmox-acme/src/eab.rs
+++ b/proxmox-acme/src/eab.rs
@@ -14,11 +14,16 @@ struct Protected {
 kid: String,
 }
 
+#[cfg_attr(feature="api-types", proxmox_schema::api())]
+/// External Account Bindings
 #[derive(Debug, Serialize, Deserialize, Clone)]
 #[serde(rename_all = "camelCase")]
 pub struct ExternalAccountBinding {
+/// JOSE Header (see RFC 7515)
 protected: String,
+/// Payload
 payload: String,
+/// HMAC signature
 signature: String,
 }
 
-- 
2.39.2


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH proxmox] proxmox-acme: derive PartialEq for API types

2024-03-07 Thread Dietmar Maurer
Signed-off-by: Dietmar Maurer 
---
 proxmox-acme/src/account.rs | 2 +-
 proxmox-acme/src/eab.rs | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/proxmox-acme/src/account.rs b/proxmox-acme/src/account.rs
index e244c09..7f00143 100644
--- a/proxmox-acme/src/account.rs
+++ b/proxmox-acme/src/account.rs
@@ -319,7 +319,7 @@ impl AccountStatus {
 /// ACME Account data. This is the part of the account returned from and 
possibly sent to the ACME
 /// provider. Some fields may be uptdated by the user via a request to the 
account location, others
 /// may not be changed.
-#[derive(Clone, Deserialize, Serialize)]
+#[derive(Clone, PartialEq, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct AccountData {
 /// The current account status.
diff --git a/proxmox-acme/src/eab.rs b/proxmox-acme/src/eab.rs
index f006a3f..9d044f3 100644
--- a/proxmox-acme/src/eab.rs
+++ b/proxmox-acme/src/eab.rs
@@ -16,7 +16,7 @@ struct Protected {
 
 #[cfg_attr(feature="api-types", proxmox_schema::api())]
 /// External Account Bindings
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
 #[serde(rename_all = "camelCase")]
 pub struct ExternalAccountBinding {
 /// JOSE Header (see RFC 7515)
-- 
2.39.2


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] applied: [PATCH proxmox] proxmox-acme: derive PartialEq for API types

2024-03-07 Thread Wolfgang Bumiller
applied, thanks


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] applied: [PATCH proxmox] proxmox-acme: add api-types feature

2024-03-07 Thread Wolfgang Bumiller
applied, thanks


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



Re: [pve-devel] [PATCH qemu-server] mediated devices: fix race condition in vm reboot

2024-03-07 Thread Mira Limbeck
On 3/7/24 10:33, Dominik Csapak wrote:
> when triggering a vm reboot from the host (via cli/api), the reboot code
> is called under a guest lock, which creates a reboot request, shuts down
> the vm and calls the regular cleanup code (which includes the mdev
> cleanup).
> 
> in parallel the qmeventd sees the vanished vm, and starts 'qm cleanup'
> which is (among other tasks) used to restart a vm with a pending reboot
> request. It does this also under a guest lock, with a default timeout of
> 10 seconds.
> 
> Since we currently wait 10 seconds for the nvidia driver to clean the
> mdev, this creates a race condition for the cleanup lock. Iow. when the
> call to `qm cleanup` starts before we started to sleep for 10 seconds,
> it will not be able to acquire its lock and not start the vm again.
> 
> To fix it, do two things:
> * increase the timeout in `qm cleanup` to 60 seconds
>   (technically this still might run into a timeout, as we can configure
>   up to 16 mediated devices with up to 10 seconds sleep each, but
>   realistically most users won't configure more than two or three of
>   them, if even that)
> 
> * change the `sleep 10` to a loop sleeping for 1 second each before
>   checking the state again. This shortens the timeout when the driver
>   can clean it up in the meantime.
> 
> Further, add a bit of logging, so we can properly see in the (task) log
> what is happening when.
> 
> Fixes: 49c51a60 (pci: workaround nvidia driver issue on mdev cleanup)
> Signed-off-by: Dominik Csapak 
> ---
>  PVE/CLI/qm.pm |  3 ++-
>  PVE/QemuServer.pm | 16 
>  2 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index b17b4fe2..dce6c7a1 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -915,7 +915,8 @@ __PACKAGE__->register_method({
>   my $storecfg = PVE::Storage::config();
>   warn "Starting cleanup for $vmid\n";
>  
> - PVE::QemuConfig->lock_config($vmid, sub {
> + # mdev cleanup can take a while, so wait up to 60 seconds
> + PVE::QemuConfig->lock_config_full($vmid, 60, sub {
>   my $conf = PVE::QemuConfig->load_config ($vmid);
>   my $pid = PVE::QemuServer::check_running ($vmid);
>   die "vm still running\n" if $pid;
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index b45507aa..efe93c62 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -6133,12 +6133,20 @@ sub cleanup_pci_devices {
>   my $dev_sysfs_dir = "/sys/bus/mdev/devices/$uuid";
>  
>   # some nvidia vgpu driver versions want to clean the mdevs up 
> themselves, and error
> - # out when we do it first. so wait for 10 seconds and then try it
> - if ($d->{ids}->[0]->[0]->{vendor} =~ m/^(0x)?10de$/) {
> - sleep 10;
> + # out when we do it first. so wait for up to 10 seconds and then 
> try it manually
> + if ($d->{ids}->[0]->[0]->{vendor} =~ m/^(0x)?10de$/ && -e 
> $dev_sysfs_dir) {
> + my $count = 0;
> + while (-e $dev_sysfs_dir && $count < 10) {
> + sleep 1;
> + $count++;
> + }
> + warn "waited $count seconds for mdev cleanup\n";
>   }
>  
> - PVE::SysFSTools::file_write("$dev_sysfs_dir/remove", "1") if -e 
> $dev_sysfs_dir;
> + if (-e $dev_sysfs_dir) {
> + warn "cleaning up mediated device $uuid\n";
> + PVE::SysFSTools::file_write("$dev_sysfs_dir/remove", "1");
> + }
>   }
>  }
>  PVE::QemuServer::PCI::remove_pci_reservation($vmid);

lgtm

Reviewed-by: Mira Limbeck 


Sadly I can't test it since I don't have a vGPU-capable nvidia card. But
the customer who reported it has tested the patch already and it seemed
to fix the issue without introducing other issues so far.


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] applied: [PATCH widget-toolkit] certificates: don't display name if there is no name

2024-03-07 Thread Thomas Lamprecht
Am 18/01/2024 um 15:14 schrieb Maximiliano Sandoval:
> The default certificate does not have a name.
> 
> Reported-by: Dietmar Maurer 
> Signed-off-by: Maximiliano Sandoval 
> ---
>  src/panel/Certificates.js | 14 ++
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/src/panel/Certificates.js b/src/panel/Certificates.js
> index a522ab6..f924512 100644
> --- a/src/panel/Certificates.js
> +++ b/src/panel/Certificates.js
> @@ -237,10 +237,16 @@ Ext.define('Proxmox.panel.Certificates', {
>   {
>   xtype: 'proxmoxButton',
>   text: gettext('Delete Custom Certificate'),
> - confirmMsg: rec => Ext.String.format(
> - gettext('Are you sure you want to remove the certificate 
> used for {0}'),
> - me.certById[rec.id].name,
> - ),
> + confirmMsg: function(rec) {

could have kept the arrow fn style

> + let cert = me.certById[rec.id];
> + if (cert.name) {
> + return Ext.String.format(
> + gettext('Are you sure you want to remove the 
> certificate used for {0}'),
> + cert.name,
> + );
> + }
> + return Ext.String.format(gettext('Are you sure you want to 
> remove the certificate'));

wrapping a string without format variable in Ext.String.format is rather
useless, I amended the commit and dropped that.

applied, thanks!


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 2/5] refactor(evpn): extract read_local_frr_config

2024-03-07 Thread Stefan Lendl
to allow mocking local fs access

Signed-off-by: Stefan Lendl 
---
 src/PVE/Network/SDN/Controllers/EvpnPlugin.pm | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm 
b/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
index c2fdf88..836a689 100644
--- a/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
+++ b/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
@@ -487,6 +487,12 @@ sub generate_frr_list {
 }
 }
 
+sub read_local_frr_config {
+if (-e "/etc/frr/frr.conf.local") {
+   return file_get_contents("/etc/frr/frr.conf.local");
+}
+};
+
 sub generate_controller_rawconfig {
 my ($class, $plugin_config, $config) = @_;
 
@@ -500,8 +506,8 @@ sub generate_controller_rawconfig {
 push @{$final_config}, "service integrated-vtysh-config";
 push @{$final_config}, "!";
 
-if (-e "/etc/frr/frr.conf.local") {
-   my $local_conf = file_get_contents("/etc/frr/frr.conf.local");
+my $local_conf = read_local_frr_config();
+if ($local_conf) {
parse_merge_frr_local_config($config, $local_conf);
 }
 
-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 1/5] refactor(controllers): extract read_etc_network_interfaces

2024-03-07 Thread Stefan Lendl
to allow mocking local fs access

Signed-off-by: Stefan Lendl 
---
 src/PVE/Network/SDN/Controllers.pm | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/PVE/Network/SDN/Controllers.pm 
b/src/PVE/Network/SDN/Controllers.pm
index 167d3ea..fd7ad54 100644
--- a/src/PVE/Network/SDN/Controllers.pm
+++ b/src/PVE/Network/SDN/Controllers.pm
@@ -70,6 +70,16 @@ sub complete_sdn_controller {
 return  $cmdname eq 'add' ? [] : [ 
PVE::Network::SDN::sdn_controllers_ids($cfg) ];
 }
 
+sub read_etc_network_interfaces {
+# read main config for physical interfaces
+my $current_config_file = "/etc/network/interfaces";
+my $fh = IO::File->new($current_config_file) or die "failed to open 
$current_config_file - $!\n";
+my $interfaces_config = 
PVE::INotify::read_etc_network_interfaces($current_config_file, $fh);
+$fh->close();
+
+return $interfaces_config;
+}
+
 sub generate_controller_config {
 
 my $cfg = PVE::Network::SDN::running_config();
@@ -79,11 +89,7 @@ sub generate_controller_config {
 
 return if !$vnet_cfg && !$zone_cfg && !$controller_cfg;
 
-# read main config for physical interfaces
-my $current_config_file = "/etc/network/interfaces";
-my $fh = IO::File->new($current_config_file) or die "failed to open 
$current_config_file - $!\n";
-my $interfaces_config = 
PVE::INotify::read_etc_network_interfaces($current_config_file, $fh);
-$fh->close();
+my $interfaces_config = read_etc_network_interfaces();
 
 # check uplinks
 my $uplinks = {};
-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 4/5] tests: disable failing DNS tests

2024-03-07 Thread Stefan Lendl
Signed-off-by: Stefan Lendl 
---
 src/test/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/Makefile b/src/test/Makefile
index eb59d5f..db70c89 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_zones test_ipams test_dns test_subnets
+test: test_zones test_ipams test_subnets
 
 test_zones: run_test_zones.pl
./run_test_zones.pl
-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 0/5] SDN tests in sbuild

2024-03-07 Thread Stefan Lendl
Extract and mock functions that otherwise access system files which is not
possible in a clean sbuild environment.
Namely /etc/network/interfaces as well as /etc/frr/frr.config.local
Disabling DNS tests

Changes v1 -> v2:
* Disabled DNS tests because they fail


Stefan Lendl (5):
  refactor(controllers): extract read_etc_network_interfaces
  refactor(evpn): extract read_local_frr_config
  tests: mocking more functions to avoid system access
  tests: disable failing DNS tests
  tests: run tests in sbuild

 src/Makefile  |  2 +-
 src/PVE/Network/SDN/Controllers.pm| 16 ++---
 src/PVE/Network/SDN/Controllers/EvpnPlugin.pm | 10 --
 src/test/Makefile |  2 +-
 src/test/run_test_zones.pl| 36 ++-
 5 files changed, 56 insertions(+), 10 deletions(-)

-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 5/5] tests: run tests in sbuild

2024-03-07 Thread Stefan Lendl
Signed-off-by: Stefan Lendl 
---
 src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile b/src/Makefile
index c9dee4c..c4056b4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,7 +10,7 @@ clean:
 
 .PHONY: test
 test:
-   [ -e /run/lock/sbuild ] || $(MAKE) -C $@
+   $(MAKE) -C $@
 
 .PHONY: install
 install:
-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



[pve-devel] [PATCH v2 pve-network 3/5] tests: mocking more functions to avoid system access

2024-03-07 Thread Stefan Lendl
previously extracted functions are now mocked in the zone tests

Signed-off-by: Stefan Lendl 
---
 src/test/run_test_zones.pl | 36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/test/run_test_zones.pl b/src/test/run_test_zones.pl
index ce8edc2..2d9be88 100755
--- a/src/test/run_test_zones.pl
+++ b/src/test/run_test_zones.pl
@@ -14,6 +14,10 @@ use PVE::Network::SDN::Zones;
 use PVE::Network::SDN::Controllers;
 use PVE::INotify;
 
+use Data::Dumper qw(Dumper);
+$Data::Dumper::Sortkeys = 1;
+$Data::Dumper::Indent = 1;
+
 sub read_sdn_config {
 my ($file) = @_;
 
@@ -29,7 +33,6 @@ sub read_sdn_config {
 return $sdn_config;
 }
 
-
 my @tests = grep { -d } glob './zones/*/*';
 
 foreach my $test (@tests) {
@@ -47,8 +50,20 @@ foreach my $test (@tests) {
return 'localhost';
},
read_file => sub {
+   # HACK this assumes we are always calling 
PVE::INotify::read_file('interfaces');
return $interfaces_config;
},
+   read_etc_network_interfaces => sub {
+   return $interfaces_config;
+   },
+);
+
+my $mocked_pve_sdn_controllers;
+$mocked_pve_sdn_controllers = 
Test::MockModule->new('PVE::Network::SDN::Controllers');
+$mocked_pve_sdn_controllers->mock(
+   read_etc_network_interfaces => sub {
+   return $interfaces_config;
+   }
 );
 
 my $pve_sdn_subnets;
@@ -88,6 +103,25 @@ foreach my $test (@tests) {
},
 );
 
+my ($first_plugin) = %{$sdn_config->{controllers}->{ids}} if defined 
$sdn_config->{controllers};
+if ($first_plugin) {
+   my $controller_plugin = PVE::Network::SDN::Controllers::Plugin->lookup(
+   $sdn_config->{controllers}->{ids}->{$first_plugin}->{type}
+   );
+   my $mocked_controller_plugin = 
Test::MockModule->new($controller_plugin);
+   $mocked_controller_plugin->mock(
+   write_controller_config => sub {
+   return;
+   },
+   reload_controller => sub {
+   return;
+   },
+   read_local_frr_config => sub {
+   return;
+   },
+   );
+}
+
 my $name = $test;
 my $expected = read_file("./$test/expected_sdn_interfaces");
 
-- 
2.43.0



___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



Re: [pve-devel] [PATCH pve-network 4/4] tests: run tests in sbuild

2024-03-07 Thread Stefan Lendl


rebased and sent v2


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel



Re: [pve-devel] [PATCH pve-network 1/2] gitignore: build artifacts from sbuild

2024-03-07 Thread Stefan Lendl


ping, still applies!


___
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel