test: run through perltidy

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2024-03-22 10:08:31 +01:00
parent 74dcbe9c08
commit ddd3d0f726
5 changed files with 297 additions and 254 deletions

View file

@ -20,6 +20,7 @@ $Data::Dumper::Sortkeys = 1;
sub read_sdn_config { sub read_sdn_config {
my ($file) = @_; my ($file) = @_;
# Read structure back in again # Read structure back in again
open my $in, '<', $file or die $!; open my $in, '<', $file or die $!;
my $sdn_config; my $sdn_config;
@ -32,7 +33,6 @@ sub read_sdn_config {
return $sdn_config; return $sdn_config;
} }
my @plugins = read_dir('./dns/', prefix => 1); my @plugins = read_dir('./dns/', prefix => 1);
foreach my $path (@plugins) { foreach my $path (@plugins) {
@ -40,7 +40,6 @@ foreach my $path (@plugins) {
my (undef, $dnsid) = split(/\//, $path); my (undef, $dnsid) = split(/\//, $path);
my $sdn_config = read_sdn_config("$path/sdn_config"); my $sdn_config = read_sdn_config("$path/sdn_config");
my $pve_sdn_dns; my $pve_sdn_dns;
$pve_sdn_dns = Test::MockModule->new('PVE::Network::SDN::Dns'); $pve_sdn_dns = Test::MockModule->new('PVE::Network::SDN::Dns');
$pve_sdn_dns->mock( $pve_sdn_dns->mock(
@ -64,11 +63,9 @@ foreach my $path (@plugins) {
my $encoded_data = $js->encode($data) if $data; my $encoded_data = $js->encode($data) if $data;
my $req = HTTP::Request->new($method, $url, $headers, $encoded_data); my $req = HTTP::Request->new($method, $url, $headers, $encoded_data);
die Dumper($req); die Dumper($req);
} },
); );
my $dns_cfg = PVE::Network::SDN::Dns::config(); my $dns_cfg = PVE::Network::SDN::Dns::config();
my $plugin_config = $dns_cfg->{ids}->{$dnsid}; my $plugin_config = $dns_cfg->{ids}->{$dnsid};
my $plugin = PVE::Network::SDN::Dns::Plugin->lookup($plugin_config->{type}); my $plugin = PVE::Network::SDN::Dns::Plugin->lookup($plugin_config->{type});
@ -93,7 +90,7 @@ foreach my $path (@plugins) {
}, },
get_zone_rrset => sub { get_zone_rrset => sub {
return undef; return undef;
} },
); );
## add_a_record ## add_a_record
@ -122,7 +119,6 @@ foreach my $path (@plugins) {
fail($name); fail($name);
} }
## del_ptr_record ## del_ptr_record
$test = "del_ptr_record"; $test = "del_ptr_record";
$expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion");
@ -136,7 +132,6 @@ foreach my $path (@plugins) {
fail($name); fail($name);
} }
## del_a_record ## del_a_record
$sdn_dns_plugin->mock( $sdn_dns_plugin->mock(
@ -148,17 +143,21 @@ foreach my $path (@plugins) {
my $type = Net::IP::ip_is_ipv6($ip) ? "AAAA" : "A"; my $type = Net::IP::ip_is_ipv6($ip) ? "AAAA" : "A";
my $fqdn = $hostname . "." . $zone . "."; my $fqdn = $hostname . "." . $zone . ".";
my $record = { content => $ip, my $record = {
content => $ip,
disabled => JSON::false, disabled => JSON::false,
name => $fqdn, name => $fqdn,
type => $type }; type => $type,
};
my $rrset = { name => $fqdn, my $rrset = {
name => $fqdn,
type => $type, type => $type,
ttl => '3600', ttl => '3600',
records => [ $record ] }; records => [$record],
};
return $rrset; return $rrset;
} },
); );
$test = "del_a_record"; $test = "del_a_record";
@ -182,22 +181,28 @@ foreach my $path (@plugins) {
}, },
get_zone_rrset => sub { get_zone_rrset => sub {
my $record = { content => $ip, my $record = {
content => $ip,
disabled => JSON::false, disabled => JSON::false,
name => $fqdn, name => $fqdn,
type => $type }; type => $type,
};
my $record2 = { content => $ip2, my $record2 = {
content => $ip2,
disabled => JSON::false, disabled => JSON::false,
name => $fqdn, name => $fqdn,
type => $type }; type => $type,
};
my $rrset = { name => $fqdn, my $rrset = {
name => $fqdn,
type => $type, type => $type,
ttl => '3600', ttl => '3600',
records => [ $record, $record2 ] }; records => [$record, $record2],
};
return $rrset; return $rrset;
} },
); );
$test = "del_a_multiple_record"; $test = "del_a_multiple_record";
@ -221,17 +226,21 @@ foreach my $path (@plugins) {
}, },
get_zone_rrset => sub { get_zone_rrset => sub {
my $record2 = { content => $ip2, my $record2 = {
content => $ip2,
disabled => JSON::false, disabled => JSON::false,
name => $fqdn, name => $fqdn,
type => $type }; type => $type,
};
my $rrset = { name => $fqdn, my $rrset = {
name => $fqdn,
type => $type, type => $type,
ttl => '3600', ttl => '3600',
records => [ $record2 ] }; records => [$record2],
};
return $rrset; return $rrset;
} },
); );
$test = "add_a_multiple_record"; $test = "add_a_multiple_record";
@ -264,4 +273,3 @@ foreach my $path (@plugins) {
done_testing(); done_testing();

View file

@ -20,6 +20,7 @@ $Data::Dumper::Sortkeys = 1;
sub read_sdn_config { sub read_sdn_config {
my ($file) = @_; my ($file) = @_;
# Read structure back in again # Read structure back in again
open my $in, '<', $file or die $!; open my $in, '<', $file or die $!;
my $sdn_config; my $sdn_config;
@ -32,7 +33,6 @@ sub read_sdn_config {
return $sdn_config; return $sdn_config;
} }
#my @plugins = <./ipams/*>; #my @plugins = <./ipams/*>;
my @plugins = read_dir('./ipams/', prefix => 1); my @plugins = read_dir('./ipams/', prefix => 1);
@ -41,7 +41,6 @@ foreach my $path (@plugins) {
my (undef, $ipamid) = split(/\//, $path); my (undef, $ipamid) = split(/\//, $path);
my $sdn_config = read_sdn_config("$path/sdn_config"); my $sdn_config = read_sdn_config("$path/sdn_config");
my $pve_sdn_subnets; my $pve_sdn_subnets;
$pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets'); $pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets');
$pve_sdn_subnets->mock( $pve_sdn_subnets->mock(
@ -73,11 +72,9 @@ foreach my $path (@plugins) {
my $encoded_data = $js->encode($data) if $data; my $encoded_data = $js->encode($data) if $data;
my $req = HTTP::Request->new($method, $url, $headers, $encoded_data); my $req = HTTP::Request->new($method, $url, $headers, $encoded_data);
die Dumper($req); die Dumper($req);
} },
); );
#test params; #test params;
my $subnetid = "myzone-10.0.0.0-24"; my $subnetid = "myzone-10.0.0.0-24";
my $ip = "10.0.0.1"; my $ip = "10.0.0.1";
@ -86,8 +83,8 @@ foreach my $path (@plugins) {
my $description = "mydescription"; my $description = "mydescription";
my $is_gateway = 1; my $is_gateway = 1;
my $subnet =
my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1); PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1);
my $ipam_cfg = PVE::Network::SDN::Ipams::config(); my $ipam_cfg = PVE::Network::SDN::Ipams::config();
my $plugin_config = $ipam_cfg->{ids}->{$ipamid}; my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
@ -102,7 +99,7 @@ foreach my $path (@plugins) {
}, },
is_ip_gateway => sub { is_ip_gateway => sub {
return 1; return 1;
} },
); );
## add_ip ## add_ip
@ -110,7 +107,8 @@ foreach my $path (@plugins) {
my $expected = Dumper read_sdn_config("$path/expected.$test"); my $expected = Dumper read_sdn_config("$path/expected.$test");
my $name = "$ipamid $test"; my $name = "$ipamid $test";
$plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1); $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description,
$is_gateway, 1);
if ($@) { if ($@) {
is($@, $expected, $name); is($@, $expected, $name);
@ -131,7 +129,6 @@ foreach my $path (@plugins) {
fail($name); fail($name);
} }
## del_ip ## del_ip
$test = "del_ip"; $test = "del_ip";
$expected = Dumper read_sdn_config("$path/expected.$test"); $expected = Dumper read_sdn_config("$path/expected.$test");
@ -149,7 +146,8 @@ foreach my $path (@plugins) {
$test = "update_ip"; $test = "update_ip";
$expected = Dumper read_sdn_config("$path/expected.$test"); $expected = Dumper read_sdn_config("$path/expected.$test");
$name = "$ipamid $test"; $name = "$ipamid $test";
$plugin->update_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1); $plugin->update_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description,
$is_gateway, 1);
if ($@) { if ($@) {
is($@, $expected, $name); is($@, $expected, $name);
@ -163,7 +161,8 @@ foreach my $path (@plugins) {
$expected = Dumper read_sdn_config("$path/expected.$test"); $expected = Dumper read_sdn_config("$path/expected.$test");
$name = "$ipamid $test"; $name = "$ipamid $test";
$plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1); $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description,
$is_gateway, 1);
if ($@) { if ($@) {
is($@, $expected, $name); is($@, $expected, $name);
@ -194,4 +193,3 @@ foreach my $path (@plugins) {
done_testing(); done_testing();

View file

@ -18,7 +18,6 @@ use JSON;
use Data::Dumper qw(Dumper); use Data::Dumper qw(Dumper);
$Data::Dumper::Sortkeys = 1; $Data::Dumper::Sortkeys = 1;
my $locks = {}; my $locks = {};
my $mocked_cfs_lock_file = sub { my $mocked_cfs_lock_file = sub {
@ -37,6 +36,7 @@ my $mocked_cfs_lock_file = sub {
sub read_sdn_config { sub read_sdn_config {
my ($file) = @_; my ($file) = @_;
# Read structure back in again # Read structure back in again
open my $in, '<', $file or die $!; open my $in, '<', $file or die $!;
my $sdn_config; my $sdn_config;
@ -49,7 +49,6 @@ sub read_sdn_config {
return $sdn_config; return $sdn_config;
} }
my @plugins = read_dir('./subnets/', prefix => 1); my @plugins = read_dir('./subnets/', prefix => 1);
foreach my $path (@plugins) { foreach my $path (@plugins) {
@ -59,7 +58,6 @@ foreach my $path (@plugins) {
print "test: $testid\n"; print "test: $testid\n";
my $sdn_config = read_sdn_config("$path/sdn_config"); my $sdn_config = read_sdn_config("$path/sdn_config");
my $pve_sdn_subnets; my $pve_sdn_subnets;
$pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets'); $pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets');
$pve_sdn_subnets->mock( $pve_sdn_subnets->mock(
@ -71,18 +69,17 @@ foreach my $path (@plugins) {
}, },
add_dns_record => sub { add_dns_record => sub {
return; return;
} },
); );
my $js = JSON->new; my $js = JSON->new;
$js->canonical(1); $js->canonical(1);
#test params; #test params;
my $subnets = $sdn_config->{subnets}->{ids}; my $subnets = $sdn_config->{subnets}->{ids};
my $subnetid = (keys %{$subnets})[0]; my $subnetid = (keys %{$subnets})[0];
my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1); my $subnet =
PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1);
my $subnet_cidr = $subnet->{cidr}; my $subnet_cidr = $subnet->{cidr};
my $iplist = NetAddr::IP->new($subnet_cidr); my $iplist = NetAddr::IP->new($subnet_cidr);
@ -132,7 +129,7 @@ foreach my $path (@plugins) {
}, },
del_cache_mac_ip => sub { del_cache_mac_ip => sub {
return; return;
} },
); );
## add_subnet ## add_subnet
@ -159,10 +156,16 @@ foreach my $path (@plugins) {
$test = "add_ip $ip"; $test = "add_ip $ip";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1}}}}}}}'; $expected =
'{"zones":{"myzone":{"subnets":{"'
. $subnet_cidr
. '":{"ips":{"'
. $ip
. '":{"gateway":1}}}}}}}';
eval { eval {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway); PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid,
$is_gateway);
}; };
if ($@) { if ($@) {
@ -180,7 +183,8 @@ foreach my $path (@plugins) {
$name = "$testid $test"; $name = "$testid $test";
eval { eval {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid); PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac,
$vmid);
}; };
if ($@) { if ($@) {
@ -194,7 +198,20 @@ foreach my $path (@plugins) {
$test = "add_second_ip $ip2"; $test = "add_second_ip $ip2";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}'; $expected =
'{"zones":{"myzone":{"subnets":{"'
. $subnet_cidr
. '":{"ips":{"'
. $ip
. '":{"gateway":1},"'
. $ip2
. '":{"hostname":"'
. $hostname
. '","mac":"'
. $mac
. '","vmid":"'
. $vmid
. '"}}}}}}}';
eval { eval {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip2, $hostname, $mac, $vmid); PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip2, $hostname, $mac, $vmid);
@ -213,10 +230,26 @@ foreach my $path (@plugins) {
$test = "find_next_freeip ($ipnextfree)"; $test = "find_next_freeip ($ipnextfree)";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}'; $expected =
'{"zones":{"myzone":{"subnets":{"'
. $subnet_cidr
. '":{"ips":{"'
. $ip
. '":{"gateway":1},"'
. $ipnextfree
. '":{},"'
. $ip2
. '":{"hostname":"'
. $hostname
. '","mac":"'
. $mac
. '","vmid":"'
. $vmid
. '"}}}}}}}';
eval { eval {
$ip3 = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid); $ip3 = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname,
$mac, $vmid);
}; };
if ($@) { if ($@) {
@ -230,11 +263,22 @@ foreach my $path (@plugins) {
$test = "del_ip $ip"; $test = "del_ip $ip";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}'; $expected =
'{"zones":{"myzone":{"subnets":{"'
. $subnet_cidr
. '":{"ips":{"'
. $ipnextfree
. '":{},"'
. $ip2
. '":{"hostname":"'
. $hostname
. '","mac":"'
. $mac
. '","vmid":"'
. $vmid
. '"}}}}}}}';
eval { eval { PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname); };
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -252,9 +296,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = undef; $expected = undef;
eval { eval { PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); };
PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet);
};
if ($@) { if ($@) {
is($result, $expected, $name); is($result, $expected, $name);
@ -263,7 +305,6 @@ foreach my $path (@plugins) {
} }
} }
## add_ip_rollback_failing_dns ## add_ip_rollback_failing_dns
$test = "add_ip_rollback_failing_dns"; $test = "add_ip_rollback_failing_dns";
@ -277,12 +318,25 @@ foreach my $path (@plugins) {
add_dns_record => sub { add_dns_record => sub {
die "error add dns record"; die "error add dns record";
return; return;
} },
); );
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}'; $expected =
'{"zones":{"myzone":{"subnets":{"'
. $subnet_cidr
. '":{"ips":{"'
. $ipnextfree
. '":{},"'
. $ip2
. '":{"hostname":"'
. $hostname
. '","mac":"'
. $mac
. '","vmid":"'
. $vmid
. '"}}}}}}}';
eval { eval {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid); PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid);
@ -299,7 +353,6 @@ foreach my $path (@plugins) {
fail("$name : $@"); fail("$name : $@");
} }
## del_empty_subnet ## del_empty_subnet
$test = "del_empty_subnet"; $test = "del_empty_subnet";
$name = "$testid $test"; $name = "$testid $test";
@ -309,9 +362,7 @@ foreach my $path (@plugins) {
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip2, $hostname); PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip2, $hostname);
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip3, $hostname); PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip3, $hostname);
eval { eval { PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); };
PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -326,4 +377,3 @@ foreach my $path (@plugins) {
done_testing(); done_testing();

View file

@ -21,6 +21,7 @@ $Data::Dumper::Sortkeys = 1;
sub read_sdn_config { sub read_sdn_config {
my ($file) = @_; my ($file) = @_;
# Read structure back in again # Read structure back in again
open my $in, '<', $file or die $!; open my $in, '<', $file or die $!;
my $sdn_config; my $sdn_config;
@ -32,7 +33,6 @@ sub read_sdn_config {
return $sdn_config; return $sdn_config;
} }
my @plugins = read_dir('./vnets/', prefix => 1); my @plugins = read_dir('./vnets/', prefix => 1);
foreach my $path (@plugins) { foreach my $path (@plugins) {
@ -69,7 +69,7 @@ foreach my $path (@plugins) {
}, },
add_dns_record => sub { add_dns_record => sub {
return; return;
} },
); );
my $js = JSON->new; my $js = JSON->new;
@ -80,7 +80,8 @@ foreach my $path (@plugins) {
my $subnets = $sdn_config->{subnets}->{ids}; my $subnets = $sdn_config->{subnets}->{ids};
my $subnetid = (sort keys %{$subnets})[0]; my $subnetid = (sort keys %{$subnets})[0];
my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1); my $subnet =
PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid, 1);
my $subnet_cidr = $subnet->{cidr}; my $subnet_cidr = $subnet->{cidr};
my $iplist = NetAddr::IP->new($subnet_cidr); my $iplist = NetAddr::IP->new($subnet_cidr);
my $mask = $iplist->masklen(); my $mask = $iplist->masklen();
@ -99,7 +100,8 @@ foreach my $path (@plugins) {
my $cidr_outofrange = '8.8.8.8/8'; my $cidr_outofrange = '8.8.8.8/8';
my $subnetid2 = (sort keys %{$subnets})[1]; my $subnetid2 = (sort keys %{$subnets})[1];
my $subnet2 = PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid2, 1); my $subnet2 =
PVE::Network::SDN::Subnets::sdn_subnets_config($sdn_config->{subnets}, $subnetid2, 1);
my $subnet2_cidr = $subnet2->{cidr}; my $subnet2_cidr = $subnet2->{cidr};
my $iplist2 = NetAddr::IP->new($subnet2_cidr); my $iplist2 = NetAddr::IP->new($subnet2_cidr);
$iplist2++; $iplist2++;
@ -127,7 +129,7 @@ foreach my $path (@plugins) {
write_db => sub { write_db => sub {
my ($cfg) = @_; my ($cfg) = @_;
$ipamdb = $cfg; $ipamdb = $cfg;
} },
); );
} }
@ -148,9 +150,7 @@ foreach my $path (@plugins) {
my $result = undef; my $result = undef;
my $expected = ''; my $expected = '';
eval { eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description); };
PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -164,9 +164,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = ''; $expected = '';
eval { eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description); };
PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description);
};
if ($@) { if ($@) {
is(undef, undef, $name); is(undef, undef, $name);
@ -182,9 +180,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = ''; $expected = '';
eval { eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr2, $hostname, $mac, $description); };
PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr2, $hostname, $mac, $description);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -199,7 +195,8 @@ foreach my $path (@plugins) {
$expected = ''; $expected = '';
eval { eval {
PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr_outofrange, $hostname, $mac, $description); PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr_outofrange, $hostname, $mac,
$description);
}; };
if ($@) { if ($@) {
@ -214,9 +211,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = ''; $expected = '';
eval { eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr4, $hostname, $mac, $description); };
PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr4, $hostname, $mac, $description);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -224,14 +219,14 @@ foreach my $path (@plugins) {
is(undef, undef, $name); is(undef, undef, $name);
} }
$test = "find_next_free_cidr_in_second_subnet ($cidr3)"; $test = "find_next_free_cidr_in_second_subnet ($cidr3)";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = $ipam ? $cidr3 : undef; $expected = $ipam ? $cidr3 : undef;
eval { eval {
$result = PVE::Network::SDN::Vnets::add_next_free_cidr($vnetid, $hostname, $mac, $description); $result =
PVE::Network::SDN::Vnets::add_next_free_cidr($vnetid, $hostname, $mac, $description);
}; };
if ($@) { if ($@) {
@ -240,15 +235,12 @@ foreach my $path (@plugins) {
is($result, $expected, $name); is($result, $expected, $name);
} }
$test = "del_cidr $cidr1"; $test = "del_cidr $cidr1";
$name = "$testid $test"; $name = "$testid $test";
$result = undef; $result = undef;
$expected = undef; $expected = undef;
eval { eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname); };
$result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -261,9 +253,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = undef; $expected = undef;
eval { eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr3, $hostname); };
$result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr3, $hostname);
};
if ($@) { if ($@) {
fail("$name : $@"); fail("$name : $@");
@ -276,9 +266,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = undef; $expected = undef;
eval { eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname); };
$result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname);
};
if ($@) { if ($@) {
is(undef, undef, $name); is(undef, undef, $name);
@ -293,9 +281,7 @@ foreach my $path (@plugins) {
$result = undef; $result = undef;
$expected = undef; $expected = undef;
eval { eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr_outofrange, $hostname); };
$result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr_outofrange, $hostname);
};
if ($@) { if ($@) {
is(undef, undef, $name); is(undef, undef, $name);
@ -309,7 +295,8 @@ foreach my $path (@plugins) {
$expected = $ipam ? $cidr1 : undef; $expected = $ipam ? $cidr1 : undef;
eval { eval {
$result = PVE::Network::SDN::Vnets::add_next_free_cidr($vnetid, $hostname, $mac, $description); $result =
PVE::Network::SDN::Vnets::add_next_free_cidr($vnetid, $hostname, $mac, $description);
}; };
if ($@) { if ($@) {
@ -324,7 +311,8 @@ foreach my $path (@plugins) {
$expected = undef; $expected = undef;
eval { eval {
$result = PVE::Network::SDN::Vnets::update_cidr($vnetid, $cidr1, $hostname, $hostname, $mac, $description); $result = PVE::Network::SDN::Vnets::update_cidr($vnetid, $cidr1, $hostname, $hostname, $mac,
$description);
}; };
if ($@) { if ($@) {
@ -339,7 +327,8 @@ foreach my $path (@plugins) {
$expected = undef; $expected = undef;
eval { eval {
$result = PVE::Network::SDN::Vnets::update_cidr($vnetid, $cidr1, $hostname, $hostname, $mac, $description); $result = PVE::Network::SDN::Vnets::update_cidr($vnetid, $cidr1, $hostname, $hostname, $mac,
$description);
}; };
if ($@) { if ($@) {
@ -352,4 +341,3 @@ foreach my $path (@plugins) {
done_testing(); done_testing();

View file

@ -29,7 +29,6 @@ sub read_sdn_config {
return $sdn_config; return $sdn_config;
} }
my @tests = grep { -d } glob './zones/*/*'; my @tests = grep { -d } glob './zones/*/*';
foreach my $test (@tests) { foreach my $test (@tests) {
@ -78,7 +77,7 @@ foreach my $test (@tests) {
}, },
find_bridge => sub { find_bridge => sub {
return; return;
} },
); );
my $sdn_module = Test::MockModule->new("PVE::Network::SDN"); my $sdn_module = Test::MockModule->new("PVE::Network::SDN");
@ -106,7 +105,8 @@ foreach my $test (@tests) {
eval { eval {
my $config = PVE::Network::SDN::Controllers::generate_controller_config(); my $config = PVE::Network::SDN::Controllers::generate_controller_config();
$controller_rawconfig = PVE::Network::SDN::Controllers::generate_controller_rawconfig($config); $controller_rawconfig =
PVE::Network::SDN::Controllers::generate_controller_rawconfig($config);
}; };
if (my $err = $@) { if (my $err = $@) {
diag("got unexpected error - $err"); diag("got unexpected error - $err");
@ -119,4 +119,3 @@ foreach my $test (@tests) {
done_testing(); done_testing();