From: Stefan Lendl Date: Fri, 24 Nov 2023 13:16:13 +0000 (+0100) Subject: tests: mocking cfs_lock_file to pass subnet tests X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=af7e542ad763d57e279740f1143706d6972143c4;p=mirror%2Fpve-network.git tests: mocking cfs_lock_file to pass subnet tests 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 --- 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, ); }