[pve-devel] [PATCH pve-network] tests: mocking cfs_lock_file to pass subnet tests

Stefan Lendl s.lendl at proxmox.com
Fri Nov 24 14:16:13 CET 2023


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 at 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






More information about the pve-devel mailing list