]>
git.proxmox.com Git - pve-network.git/blob - src/test/run_test_vnets.pl
8 use NetAddr
::IP
qw(:lower);
13 use PVE
::Network
::SDN
;
14 use PVE
::Network
::SDN
::Zones
;
15 use PVE
::Network
::SDN
::Controllers
;
19 use Data
::Dumper
qw(Dumper);
20 $Data::Dumper
::Sortkeys
= 1;
25 # Read structure back in again
26 open my $in, '<', $file or die $!;
29 local $/; # slurp mode
30 $sdn_config = eval <$in>;
36 my @plugins = read_dir
('./vnets/', prefix
=> 1);
38 foreach my $path (@plugins) {
40 my (undef, $testid) = split(/\//, $path);
42 print "test: $testid\n";
43 my $sdn_config = read_sdn_config
("$path/sdn_config");
46 $pve_sdn_zones = Test
::MockModule-
>new('PVE::Network::SDN::Zones');
49 return $sdn_config->{zones
};
54 $pve_sdn_vnets = Test
::MockModule-
>new('PVE::Network::SDN::Vnets');
57 return $sdn_config->{vnets
};
62 $pve_sdn_subnets = Test
::MockModule-
>new('PVE::Network::SDN::Subnets');
63 $pve_sdn_subnets->mock(
65 return $sdn_config->{subnets
};
67 verify_dns_zone
=> sub {
70 add_dns_record
=> sub {
80 my $subnets = $sdn_config->{subnets
}->{ids
};
82 my $subnetid = (sort keys %{$subnets})[0];
84 PVE
::Network
::SDN
::Subnets
::sdn_subnets_config
($sdn_config->{subnets
}, $subnetid, 1);
85 my $subnet_cidr = $subnet->{cidr
};
86 my $iplist = NetAddr
::IP-
>new($subnet_cidr);
87 my $mask = $iplist->masklen();
88 my $ipversion = undef;
90 if (Net
::IP
::ip_is_ipv4
($iplist->canon())) {
91 $iplist++; #skip network address for ipv4
97 my $cidr1 = $iplist->canon() . "/$mask";
99 my $cidr2 = $iplist->canon() . "/$mask";
100 my $cidr_outofrange = '8.8.8.8/8';
102 my $subnetid2 = (sort keys %{$subnets})[1];
104 PVE
::Network
::SDN
::Subnets
::sdn_subnets_config
($sdn_config->{subnets
}, $subnetid2, 1);
105 my $subnet2_cidr = $subnet2->{cidr
};
106 my $iplist2 = NetAddr
::IP-
>new($subnet2_cidr);
108 my $cidr3 = $iplist2->canon() . "/$mask";
110 my $cidr4 = $iplist2->canon() . "/$mask";
112 my $hostname = "myhostname";
113 my $mac = "da:65:8f:18:9b:6f";
114 my $description = "mydescription";
115 my $ipamdb = read_sdn_config
("$path/ipam.db");
117 my $zone = $sdn_config->{zones
}->{ids
}->{"myzone"};
118 my $ipam = $zone->{ipam
};
123 $plugin = PVE
::Network
::SDN
::Ipams
::Plugin-
>lookup($ipam);
124 $sdn_ipam_plugin = Test
::MockModule-
>new($plugin);
125 $sdn_ipam_plugin->mock(
137 $pve_sdn_ipams = Test
::MockModule-
>new('PVE::Network::SDN::Ipams');
138 $pve_sdn_ipams->mock(
140 my $ipam_config = read_sdn_config
("$path/ipam_config");
145 my $vnetid = "myvnet";
148 my $test = "add_cidr $cidr1";
149 my $name = "$testid $test";
153 eval { PVE
::Network
::SDN
::Vnets
::add_cidr
($vnetid, $cidr1, $hostname, $mac, $description); };
158 is(undef, undef, $name);
162 $test = "add_already_exist_cidr $cidr1";
163 $name = "$testid $test";
167 eval { PVE
::Network
::SDN
::Vnets
::add_cidr
($vnetid, $cidr1, $hostname, $mac, $description); };
170 is(undef, undef, $name);
174 is(undef, undef, $name);
178 $test = "add_cidr $cidr2";
179 $name = "$testid $test";
183 eval { PVE
::Network
::SDN
::Vnets
::add_cidr
($vnetid, $cidr2, $hostname, $mac, $description); };
188 is(undef, undef, $name);
192 $test = "add_ip_out_of_range_subnets $cidr_outofrange";
193 $name = "$testid $test";
198 PVE
::Network
::SDN
::Vnets
::add_cidr
($vnetid, $cidr_outofrange, $hostname, $mac,
203 is(undef, undef, $name);
209 $test = "add_cidr $cidr4";
210 $name = "$testid $test";
214 eval { PVE
::Network
::SDN
::Vnets
::add_cidr
($vnetid, $cidr4, $hostname, $mac, $description); };
219 is(undef, undef, $name);
222 $test = "find_next_free_cidr_in_second_subnet ($cidr3)";
223 $name = "$testid $test";
225 $expected = $ipam ?
$cidr3 : undef;
229 PVE
::Network
::SDN
::Vnets
::add_next_free_cidr
($vnetid, $hostname, $mac, $description);
235 is($result, $expected, $name);
238 $test = "del_cidr $cidr1";
239 $name = "$testid $test";
243 eval { $result = PVE
::Network
::SDN
::Vnets
::del_cidr
($vnetid, $cidr1, $hostname); };
248 is(undef, undef, $name);
251 $test = "del_cidr $cidr3";
252 $name = "$testid $test";
256 eval { $result = PVE
::Network
::SDN
::Vnets
::del_cidr
($vnetid, $cidr3, $hostname); };
261 is(undef, undef, $name);
264 $test = "del_cidr not exist $cidr1";
265 $name = "$testid $test";
269 eval { $result = PVE
::Network
::SDN
::Vnets
::del_cidr
($vnetid, $cidr1, $hostname); };
272 is(undef, undef, $name);
276 is(undef, undef, $name);
279 $test = "del_cidr outofrange $cidr_outofrange";
280 $name = "$testid $test";
284 eval { $result = PVE
::Network
::SDN
::Vnets
::del_cidr
($vnetid, $cidr_outofrange, $hostname); };
287 is(undef, undef, $name);
292 $test = "find_next_free_cidr_in_first_subnet ($cidr1)";
293 $name = "$testid $test";
295 $expected = $ipam ?
$cidr1 : undef;
299 PVE
::Network
::SDN
::Vnets
::add_next_free_cidr
($vnetid, $hostname, $mac, $description);
305 is($result, $expected, $name);
308 $test = "update_cidr $cidr1";
309 $name = "$testid $test";
314 $result = PVE
::Network
::SDN
::Vnets
::update_cidr
($vnetid, $cidr1, $hostname, $hostname, $mac,
321 is(undef, undef, $name);
324 $test = "update_cidr deleted $cidr3";
325 $name = "$testid $test";
330 $result = PVE
::Network
::SDN
::Vnets
::update_cidr
($vnetid, $cidr1, $hostname, $hostname, $mac,
337 is(undef, undef, $name);