public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Lendl <s.lendl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network] tests: mocking cfs_lock_file to pass subnet tests
Date: Fri, 24 Nov 2023 14:16:13 +0100	[thread overview]
Message-ID: <20231124131612.234972-2-s.lendl@proxmox.com> (raw)

IPAM tries to lock file in clusterfs which it can't when testing as
non-root.

Mocking cfs_lock_file to emulate locking behavior.

Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
---
 src/test/run_test_subnets.pl | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/test/run_test_subnets.pl b/src/test/run_test_subnets.pl
index 49b4205..7d57e99 100755
--- a/src/test/run_test_subnets.pl
+++ b/src/test/run_test_subnets.pl
@@ -18,6 +18,23 @@ use JSON;
 use Data::Dumper qw(Dumper);
 $Data::Dumper::Sortkeys = 1;
 
+
+my $locks = {};
+
+my $mocked_cfs_lock_file = sub {
+    my ($filename, $timeout, $code, @param) = @_;
+
+    die "$filename already locked\n" if ($locks->{$filename});
+
+    $locks->{$filename} = 1;
+
+    my $res = eval { $code->(@param); };
+
+    delete $locks->{$filename};
+
+    return $res;
+};
+
 sub read_sdn_config {
     my ($file) = @_;
     # Read structure back in again
@@ -98,7 +115,8 @@ foreach my $path (@plugins) {
 	    write_db => sub {
 		my ($cfg) = @_;
 		$ipamdb = $cfg;
-	    }
+	    },
+	    cfs_lock_file => $mocked_cfs_lock_file,
 	);
     }
 
-- 
2.42.0





             reply	other threads:[~2023-11-24 13:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 13:16 Stefan Lendl [this message]
2023-11-29 14:09 ` [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=20231124131612.234972-2-s.lendl@proxmox.com \
    --to=s.lendl@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