sub read_sdn_config {
my ($file) = @_;
+
# Read structure back in again
open my $in, '<', $file or die $!;
my $sdn_config;
{
- local $/; # slurp mode
+ local $/; # slurp mode
$sdn_config = eval <$in>;
}
close $in;
return $sdn_config;
}
-
-my @plugins = read_dir( './dns/', prefix => 1 ) ;
+my @plugins = read_dir('./dns/', prefix => 1);
foreach my $path (@plugins) {
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;
$pve_sdn_dns = Test::MockModule->new('PVE::Network::SDN::Dns');
$pve_sdn_dns->mock(
config => sub {
- my $dns_config = read_sdn_config ("$path/dns_config");
+ my $dns_config = read_sdn_config("$path/dns_config");
return $dns_config;
},
);
return $sdn_config;
},
api_request => sub {
- my ($method, $url, $headers, $data) = @_;
-
- my $js = JSON->new;
- $js->canonical(1);
-
- my $encoded_data = $js->encode($data) if $data;
- my $req = HTTP::Request->new($method,$url, $headers, $encoded_data);
- die Dumper($req);
- }
- );
+ my ($method, $url, $headers, $data) = @_;
+ my $js = JSON->new;
+ $js->canonical(1);
+ my $encoded_data = $js->encode($data) if $data;
+ my $req = HTTP::Request->new($method, $url, $headers, $encoded_data);
+ die Dumper($req);
+ },
+ );
my $dns_cfg = PVE::Network::SDN::Dns::config();
my $plugin_config = $dns_cfg->{ids}->{$dnsid};
my $plugin = PVE::Network::SDN::Dns::Plugin->lookup($plugin_config->{type});
-
+
#test params;
my @ips = ("10.0.0.1", "2001:4860:4860::8888");
my $zone = "domain.com";
my $ipversion = Net::IP::ip_is_ipv6($ip) ? "ipv6" : "ipv4";
my $type = Net::IP::ip_is_ipv6($ip) ? "AAAA" : "A";
my $ip2 = $type eq 'AAAA' ? '2001:4860:4860::8844' : '127.0.0.1';
- my $fqdn = $hostname.".".$zone.".";
+ my $fqdn = $hostname . "." . $zone . ".";
- my $sdn_dns_plugin = Test::MockModule->new($plugin);
+ my $sdn_dns_plugin = Test::MockModule->new($plugin);
$sdn_dns_plugin->mock(
get_zone_content => sub {
},
get_zone_rrset => sub {
return undef;
- }
+ },
);
## add_a_record
$plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
$plugin->add_ptr_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
-
## del_ptr_record
$test = "del_ptr_record";
$expected = Dumper read_sdn_config("$path/expected.$test.$ipversion");
$plugin->del_ptr_record($plugin_config, $zone, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
-
## del_a_record
$sdn_dns_plugin->mock(
get_zone_rrset => sub {
my $type = Net::IP::ip_is_ipv6($ip) ? "AAAA" : "A";
- my $fqdn = $hostname.".".$zone.".";
- my $record = { content => $ip,
- disabled => JSON::false,
- name => $fqdn,
- type => $type };
-
- my $rrset = { name => $fqdn,
- type => $type,
- ttl => '3600',
- records => [ $record ] };
+ my $fqdn = $hostname . "." . $zone . ".";
+ my $record = {
+ content => $ip,
+ disabled => JSON::false,
+ name => $fqdn,
+ type => $type,
+ };
+
+ my $rrset = {
+ name => $fqdn,
+ type => $type,
+ ttl => '3600',
+ records => [$record],
+ };
return $rrset;
- }
+ },
);
$test = "del_a_record";
$plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
},
get_zone_rrset => sub {
- my $record = { content => $ip,
- disabled => JSON::false,
- name => $fqdn,
- type => $type };
-
- my $record2 = { content => $ip2,
- disabled => JSON::false,
- name => $fqdn,
- type => $type };
-
- my $rrset = { name => $fqdn,
- type => $type,
- ttl => '3600',
- records => [ $record, $record2 ] };
+ my $record = {
+ content => $ip,
+ disabled => JSON::false,
+ name => $fqdn,
+ type => $type,
+ };
+
+ my $record2 = {
+ content => $ip2,
+ disabled => JSON::false,
+ name => $fqdn,
+ type => $type,
+ };
+
+ my $rrset = {
+ name => $fqdn,
+ type => $type,
+ ttl => '3600',
+ records => [$record, $record2],
+ };
return $rrset;
- }
+ },
);
$test = "del_a_multiple_record";
$plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
},
get_zone_rrset => sub {
- my $record2 = { content => $ip2,
- disabled => JSON::false,
- name => $fqdn,
- type => $type };
-
- my $rrset = { name => $fqdn,
- type => $type,
- ttl => '3600',
- records => [ $record2 ] };
+ my $record2 = {
+ content => $ip2,
+ disabled => JSON::false,
+ name => $fqdn,
+ type => $type,
+ };
+
+ my $rrset = {
+ name => $fqdn,
+ type => $type,
+ ttl => '3600',
+ records => [$record2],
+ };
return $rrset;
- }
+ },
);
$test = "add_a_multiple_record";
$plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
$plugin->verify_zone($plugin_config, $zone, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
done_testing();
-
sub read_sdn_config {
my ($file) = @_;
+
# Read structure back in again
open my $in, '<', $file or die $!;
my $sdn_config;
{
- local $/; # slurp mode
+ local $/; # slurp mode
$sdn_config = eval <$in>;
}
close $in;
return $sdn_config;
}
-
#my @plugins = <./ipams/*>;
-my @plugins = read_dir( './ipams/', prefix => 1 ) ;
+my @plugins = read_dir('./ipams/', prefix => 1);
foreach my $path (@plugins) {
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;
$pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets');
$pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Ipams');
$pve_sdn_subnets->mock(
config => sub {
- my $ipam_config = read_sdn_config ("$path/ipam_config");
+ my $ipam_config = read_sdn_config("$path/ipam_config");
return $ipam_config;
},
);
return $sdn_config;
},
api_request => sub {
- my ($method, $url, $headers, $data) = @_;
-
- my $js = JSON->new;
- $js->canonical(1);
-
- my $encoded_data = $js->encode($data) if $data;
- my $req = HTTP::Request->new($method,$url, $headers, $encoded_data);
- die Dumper($req);
- }
- );
+ my ($method, $url, $headers, $data) = @_;
+
+ my $js = JSON->new;
+ $js->canonical(1);
+ my $encoded_data = $js->encode($data) if $data;
+ my $req = HTTP::Request->new($method, $url, $headers, $encoded_data);
+ die Dumper($req);
+ },
+ );
-
#test params;
my $subnetid = "myzone-10.0.0.0-24";
my $ip = "10.0.0.1";
my $description = "mydescription";
my $is_gateway = 1;
+ 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 $ipam_cfg = PVE::Network::SDN::Ipams::config();
+ my $ipam_cfg = PVE::Network::SDN::Ipams::config();
my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
my $sdn_ipam_plugin = Test::MockModule->new($plugin);
},
is_ip_gateway => sub {
return 1;
- }
+ },
);
## add_ip
my $expected = Dumper read_sdn_config("$path/expected.$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 ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
$plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
-
## del_ip
$test = "del_ip";
$expected = Dumper read_sdn_config("$path/expected.$test");
$plugin->del_ip($plugin_config, $subnetid, $subnet, $ip, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
$test = "update_ip";
$expected = Dumper read_sdn_config("$path/expected.$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 ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
$expected = Dumper read_sdn_config("$path/expected.$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 ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
- $sdn_ipam_plugin->mock(
+ $sdn_ipam_plugin->mock(
get_prefix_id => sub {
return undef;
},
$plugin->add_subnet($plugin_config, $subnetid, $subnet, 1);
if ($@) {
- is ($@, $expected, $name);
+ is($@, $expected, $name);
} else {
fail($name);
}
done_testing();
-
use Data::Dumper qw(Dumper);
$Data::Dumper::Sortkeys = 1;
-
my $locks = {};
my $mocked_cfs_lock_file = sub {
sub read_sdn_config {
my ($file) = @_;
+
# Read structure back in again
open my $in, '<', $file or die $!;
my $sdn_config;
{
- local $/; # slurp mode
+ local $/; # slurp mode
$sdn_config = eval <$in>;
}
close $in;
return $sdn_config;
}
-
-my @plugins = read_dir( './subnets/', prefix => 1 ) ;
+my @plugins = read_dir('./subnets/', prefix => 1);
foreach my $path (@plugins) {
my (undef, $testid) = split(/\//, $path);
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;
$pve_sdn_subnets = Test::MockModule->new('PVE::Network::SDN::Subnets');
},
add_dns_record => sub {
return;
- }
+ },
);
-
my $js = JSON->new;
$js->canonical(1);
-
#test params;
my $subnets = $sdn_config->{subnets}->{ids};
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 $iplist = NetAddr::IP->new($subnet_cidr);
my $plugin;
my $sdn_ipam_plugin;
- if($ipam) {
+ if ($ipam) {
$plugin = PVE::Network::SDN::Ipams::Plugin->lookup($ipam);
$sdn_ipam_plugin = Test::MockModule->new($plugin);
$sdn_ipam_plugin->mock(
$pve_sdn_ipams = Test::MockModule->new('PVE::Network::SDN::Ipams');
$pve_sdn_ipams->mock(
config => sub {
- my $ipam_config = read_sdn_config ("$path/ipam_config");
+ my $ipam_config = read_sdn_config("$path/ipam_config");
return $ipam_config;
},
add_cache_mac_ip => sub {
},
del_cache_mac_ip => sub {
return;
- }
+ },
);
## add_subnet
my $test = "add_subnet $subnetid";
my $name = "$testid $test";
my $result = undef;
- my $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{}}}}}}';
+ my $expected = '{"zones":{"myzone":{"subnets":{"' . $subnet_cidr . '":{"ips":{}}}}}}';
eval {
- PVE::Network::SDN::Subnets::add_subnet($zone, $subnetid, $subnet);
+ PVE::Network::SDN::Subnets::add_subnet($zone, $subnetid, $subnet);
};
if ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
## add_ip
$test = "add_ip $ip";
$name = "$testid $test";
$result = undef;
- $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1}}}}}}}';
+ $expected =
+ '{"zones":{"myzone":{"subnets":{"'
+ . $subnet_cidr
+ . '":{"ips":{"'
+ . $ip
+ . '":{"gateway":1}}}}}}}';
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 ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
- if($ipam) {
+ if ($ipam) {
## add_already_exist_ip
$test = "add_already_exist_ip $ip";
$name = "$testid $test";
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 ($@) {
- is (undef, undef, $name);
+ is(undef, undef, $name);
} else {
fail("$name : $@");
}
$test = "add_second_ip $ip2";
$name = "$testid $test";
$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 {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip2, $hostname, $mac, $vmid);
};
if ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
## add_next_free
$test = "find_next_freeip ($ipnextfree)";
$name = "$testid $test";
$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 {
- $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 ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
}
## del_ip
$test = "del_ip $ip";
$name = "$testid $test";
$result = undef;
- $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}';
-
- eval {
- PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname);
- };
+ $expected =
+ '{"zones":{"myzone":{"subnets":{"'
+ . $subnet_cidr
+ . '":{"ips":{"'
+ . $ipnextfree
+ . '":{},"'
+ . $ip2
+ . '":{"hostname":"'
+ . $hostname
+ . '","mac":"'
+ . $mac
+ . '","vmid":"'
+ . $vmid
+ . '"}}}}}}}';
+
+ eval { PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname); };
if ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
- if($ipam){
+ if ($ipam) {
## del_subnet_not_empty
$test = "del_subnet_not_empty $subnetid";
$name = "$testid $test";
$result = undef;
$expected = undef;
- eval {
- PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet);
- };
+ eval { PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); };
if ($@) {
- is ($result, $expected, $name);
+ is($result, $expected, $name);
} else {
fail("$name : $@");
}
}
-
## add_ip_rollback_failing_dns
$test = "add_ip_rollback_failing_dns";
add_dns_record => sub {
die "error add dns record";
return;
- }
+ },
);
$name = "$testid $test";
$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 {
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid);
};
if ($@) {
- if($ipam) {
+ if ($ipam) {
$result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
} else {
- fail("$name : $@");
+ fail("$name : $@");
}
-
## del_empty_subnet
$test = "del_empty_subnet";
$name = "$testid $test";
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip2, $hostname);
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip3, $hostname);
- eval {
- PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet);
- };
+ eval { PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); };
if ($@) {
- fail("$name : $@");
- } elsif($ipam) {
- $result = $js->encode($plugin->read_db());
- is ($result, $expected, $name);
+ fail("$name : $@");
+ } elsif ($ipam) {
+ $result = $js->encode($plugin->read_db());
+ is($result, $expected, $name);
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
}
done_testing();
-
sub read_sdn_config {
my ($file) = @_;
+
# Read structure back in again
open my $in, '<', $file or die $!;
my $sdn_config;
{
- local $/; # slurp mode
+ local $/; # slurp mode
$sdn_config = eval <$in>;
}
close $in;
return $sdn_config;
}
-
-my @plugins = read_dir( './vnets/', prefix => 1 ) ;
+my @plugins = read_dir('./vnets/', prefix => 1);
foreach my $path (@plugins) {
my (undef, $testid) = split(/\//, $path);
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_zones;
$pve_sdn_zones = Test::MockModule->new('PVE::Network::SDN::Zones');
},
add_dns_record => sub {
return;
- }
+ },
);
my $js = JSON->new;
$js->canonical(1);
-
+
#test params;
#test params;
my $subnets = $sdn_config->{subnets}->{ids};
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 $iplist = NetAddr::IP->new($subnet_cidr);
my $mask = $iplist->masklen();
my $ipversion = undef;
- if (Net::IP::ip_is_ipv4($iplist->canon())){
+ if (Net::IP::ip_is_ipv4($iplist->canon())) {
$iplist++; #skip network address for ipv4
$ipversion = 4;
- } else {
+ } else {
$ipversion = 6;
}
- my $cidr1 = $iplist->canon()."/$mask";
+ my $cidr1 = $iplist->canon() . "/$mask";
$iplist++;
- my $cidr2 = $iplist->canon()."/$mask";
+ my $cidr2 = $iplist->canon() . "/$mask";
my $cidr_outofrange = '8.8.8.8/8';
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 $iplist2 = NetAddr::IP->new($subnet2_cidr);
$iplist2++;
- my $cidr3 = $iplist2->canon()."/$mask";
+ my $cidr3 = $iplist2->canon() . "/$mask";
$iplist2++;
- my $cidr4 = $iplist2->canon()."/$mask";
+ my $cidr4 = $iplist2->canon() . "/$mask";
my $hostname = "myhostname";
my $mac = "da:65:8f:18:9b:6f";
my $description = "mydescription";
- my $ipamdb = read_sdn_config ("$path/ipam.db");
+ my $ipamdb = read_sdn_config("$path/ipam.db");
my $zone = $sdn_config->{zones}->{ids}->{"myzone"};
my $ipam = $zone->{ipam};
my $plugin;
my $sdn_ipam_plugin;
- if($ipam) {
+ if ($ipam) {
$plugin = PVE::Network::SDN::Ipams::Plugin->lookup($ipam);
$sdn_ipam_plugin = Test::MockModule->new($plugin);
$sdn_ipam_plugin->mock(
write_db => sub {
my ($cfg) = @_;
$ipamdb = $cfg;
- }
+ },
);
}
$pve_sdn_ipams = Test::MockModule->new('PVE::Network::SDN::Ipams');
$pve_sdn_ipams->mock(
config => sub {
- my $ipam_config = read_sdn_config ("$path/ipam_config");
+ my $ipam_config = read_sdn_config("$path/ipam_config");
return $ipam_config;
},
);
my $result = undef;
my $expected = '';
- eval {
- PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description);
- };
+ eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description); };
if ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
## add_ip
$result = undef;
$expected = '';
- eval {
- PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description);
- };
+ eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr1, $hostname, $mac, $description); };
if ($@) {
- is (undef, undef, $name);
- } elsif($ipam) {
- fail("$name : $@");
+ is(undef, undef, $name);
+ } elsif ($ipam) {
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
## add_ip
$result = undef;
$expected = '';
- eval {
- PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr2, $hostname, $mac, $description);
- };
+ eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr2, $hostname, $mac, $description); };
if ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
## add_ip
$expected = '';
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 ($@) {
- is (undef, undef, $name);
+ is(undef, undef, $name);
} else {
- fail("$name : $@");
+ fail("$name : $@");
}
## add_ip
$result = undef;
$expected = '';
- eval {
- PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr4, $hostname, $mac, $description);
- };
+ eval { PVE::Network::SDN::Vnets::add_cidr($vnetid, $cidr4, $hostname, $mac, $description); };
if ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
-
$test = "find_next_free_cidr_in_second_subnet ($cidr3)";
$name = "$testid $test";
$result = undef;
$expected = $ipam ? $cidr3 : undef;
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 ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is ($result, $expected, $name);
+ is($result, $expected, $name);
}
-
$test = "del_cidr $cidr1";
$name = "$testid $test";
$result = undef;
$expected = undef;
- eval {
- $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname);
- };
+ eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname); };
if ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
$test = "del_cidr $cidr3";
$result = undef;
$expected = undef;
- eval {
- $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr3, $hostname);
- };
+ eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr3, $hostname); };
if ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
$test = "del_cidr not exist $cidr1";
$result = undef;
$expected = undef;
- eval {
- $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname);
- };
+ eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr1, $hostname); };
if ($@) {
- is (undef, undef, $name);
- } elsif($ipam) {
- fail("$name : $@");
+ is(undef, undef, $name);
+ } elsif ($ipam) {
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
$test = "del_cidr outofrange $cidr_outofrange";
$result = undef;
$expected = undef;
- eval {
- $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr_outofrange, $hostname);
- };
+ eval { $result = PVE::Network::SDN::Vnets::del_cidr($vnetid, $cidr_outofrange, $hostname); };
if ($@) {
- is (undef, undef, $name);
+ is(undef, undef, $name);
} else {
- fail("$name : $@");
+ fail("$name : $@");
}
$test = "find_next_free_cidr_in_first_subnet ($cidr1)";
$expected = $ipam ? $cidr1 : undef;
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 ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is ($result, $expected, $name);
+ is($result, $expected, $name);
}
$test = "update_cidr $cidr1";
$expected = undef;
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 ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
$test = "update_cidr deleted $cidr3";
$expected = undef;
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 ($@) {
- fail("$name : $@");
+ fail("$name : $@");
} else {
- is (undef, undef, $name);
+ is(undef, undef, $name);
}
}
done_testing();
-
return $sdn_config;
}
-
my @tests = grep { -d } glob './zones/*/*';
foreach my $test (@tests) {
- my $sdn_config = read_sdn_config ("./$test/sdn_config");
+ my $sdn_config = read_sdn_config("./$test/sdn_config");
open(my $fh1, '<', "./$test/interfaces") or die "can't read interfaces file - $!";
my $interfaces_config = PVE::INotify::__read_etc_network_interfaces($fh1, undef, undef);
},
find_bridge => sub {
return;
- }
+ },
);
my $sdn_module = Test::MockModule->new("PVE::Network::SDN");
diag("got unexpected error - $err");
fail($name);
} else {
- is ($result, $expected, $name);
+ is($result, $expected, $name);
}
if ($sdn_config->{controllers}) {
eval {
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 = $@) {
diag("got unexpected error - $err");
fail($name);
} else {
- is ($controller_rawconfig, $expected, $name);
+ is($controller_rawconfig, $expected, $name);
}
}
}
done_testing();
-