]>
git.proxmox.com Git - pve-network.git/blob - test/run_test_ipams.pl
12 use PVE
::Network
::SDN
;
13 use PVE
::Network
::SDN
::Zones
;
14 use PVE
::Network
::SDN
::Controllers
;
18 use Data
::Dumper
qw(Dumper);
19 $Data::Dumper
::Sortkeys
= 1;
23 # Read structure back in again
24 open my $in, '<', $file or die $!;
27 local $/; # slurp mode
28 $sdn_config = eval <$in>;
36 #my @plugins = <./ipams/*>;
37 my @plugins = read_dir
( './ipams/', prefix
=> 1 ) ;
39 foreach my $path (@plugins) {
41 my (undef, $ipamid) = split(/\//, $path);
42 my $sdn_config = read_sdn_config
("$path/sdn_config");
46 $pve_sdn_subnets = Test
::MockModule-
>new('PVE::Network::SDN::Subnets');
47 $pve_sdn_subnets->mock(
49 return $sdn_config->{subnets
};
54 $pve_sdn_subnets = Test
::MockModule-
>new('PVE::Network::SDN::Ipams');
55 $pve_sdn_subnets->mock(
57 my $ipam_config = read_sdn_config
("$path/ipam_config");
62 my $sdn_module = Test
::MockModule-
>new("PVE::Network::SDN");
68 my ($method, $url, $headers, $data) = @_;
73 my $encoded_data = $js->encode($data) if $data;
74 my $req = HTTP
::Request-
>new($method,$url, $headers, $encoded_data);
82 my $subnetid = "myzone-10.0.0.0-24";
84 my $hostname = "myhostname";
85 my $mac = "da:65:8f:18:9b:6f";
86 my $description = "mydescription";
90 my $subnet = PVE
::Network
::SDN
::Subnets
::sdn_subnets_config
($sdn_config->{subnets
}, $subnetid, 1);
92 my $ipam_cfg = PVE
::Network
::SDN
::Ipams
::config
();
93 my $plugin_config = $ipam_cfg->{ids
}->{$ipamid};
94 my $plugin = PVE
::Network
::SDN
::Ipams
::Plugin-
>lookup($plugin_config->{type
});
95 my $sdn_ipam_plugin = Test
::MockModule-
>new($plugin);
96 $sdn_ipam_plugin->mock(
97 get_prefix_id
=> sub {
103 is_ip_gateway
=> sub {
110 my $expected = Dumper read_sdn_config
("$path/expected.$test");
111 my $name = "$ipamid $test";
113 $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1);
116 is ($@, $expected, $name);
122 $test = "add_next_freeip";
123 $expected = Dumper read_sdn_config
("$path/expected.$test");
124 $name = "$ipamid $test";
126 $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description, 1);
129 is ($@, $expected, $name);
137 $expected = Dumper read_sdn_config
("$path/expected.$test");
138 $name = "$ipamid $test";
140 $plugin->del_ip($plugin_config, $subnetid, $subnet, $ip, 1);
143 is ($@, $expected, $name);
150 $expected = Dumper read_sdn_config
("$path/expected.$test");
151 $name = "$ipamid $test";
152 $plugin->update_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1);
155 is ($@, $expected, $name);
162 $test = "add_ip_notgateway";
163 $expected = Dumper read_sdn_config
("$path/expected.$test");
164 $name = "$ipamid $test";
166 $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, 1);
169 is ($@, $expected, $name);
174 $sdn_ipam_plugin->mock(
175 get_prefix_id
=> sub {
181 $test = "add_subnet";
182 $expected = Dumper read_sdn_config
("$path/expected.$test");
183 $name = "$ipamid $test";
185 $plugin->add_subnet($plugin_config, $subnetid, $subnet, 1);
188 is ($@, $expected, $name);