From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B25217A708 for ; Sat, 8 May 2021 07:51:45 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A39D79A84 for ; Sat, 8 May 2021 07:51:45 +0200 (CEST) Received: from kvmformation3.odiso.net (globalOdiso.M6Lille.odiso.net [89.248.211.242]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9B0BB9A69 for ; Sat, 8 May 2021 07:51:44 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 3229CA00BA; Sat, 8 May 2021 07:51:38 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Sat, 8 May 2021 07:51:35 +0200 Message-Id: <20210508055136.3118159-2-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210508055136.3118159-1-aderumier@odiso.com> References: <20210508055136.3118159-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.162 Adjusted score from AWL reputation of From: address HEADER_FROM_DIFFERENT_DOMAINS 0.249 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KHOP_HELO_FCRDNS 0.399 Relay HELO differs from its IP's reverse DNS NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH pve-network 1/2] subnets: tests: add noipam test X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 May 2021 05:51:45 -0000 --- test/run_test_subnets.pl | 122 ++++++++++++++++++++------------ test/subnets/noipam/ipam_config | 18 +++++ test/subnets/noipam/sdn_config | 20 ++++++ 3 files changed, 115 insertions(+), 45 deletions(-) create mode 100644 test/subnets/noipam/ipam_config create mode 100644 test/subnets/noipam/sdn_config diff --git a/test/run_test_subnets.pl b/test/run_test_subnets.pl index 6ffa6a3..364baa6 100755 --- a/test/run_test_subnets.pl +++ b/test/run_test_subnets.pl @@ -39,6 +39,7 @@ foreach my $path (@plugins) { my (undef, $testid) = split(/\//, $path); + print "test: $testid\n"; my $sdn_config = read_sdn_config ("$path/sdn_config"); @@ -83,17 +84,31 @@ foreach my $path (@plugins) { my $ipamdb = {}; my $zone = $sdn_config->{zones}->{ids}->{"myzone"}; + my $ipam = $zone->{ipam}; + + my $plugin; + my $sdn_ipam_plugin; + if($ipam) { + $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($ipam); + $sdn_ipam_plugin = Test::MockModule->new($plugin); + $sdn_ipam_plugin->mock( + read_db => sub { + return $ipamdb; + }, + write_db => sub { + my ($cfg) = @_; + $ipamdb = $cfg; + } + ); + } - my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup('pve'); - my $sdn_ipam_plugin = Test::MockModule->new($plugin); - $sdn_ipam_plugin->mock( - read_db => sub { - return $ipamdb; + my $pve_sdn_ipams; + $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"); + return $ipam_config; }, - write_db => sub { - my ($cfg) = @_; - $ipamdb = $cfg; - } ); ## add_subnet @@ -103,14 +118,17 @@ foreach my $path (@plugins) { my $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{}}}}}}'; eval { - $plugin->add_subnet(undef, $subnetid, $subnet, 1); + PVE::Network::SDN::Subnets::add_subnet($zone, $subnetid, $subnet); + }; if ($@) { - fail($name); - } else { + fail("$name : $@"); + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); + } else { + is (undef, undef, $name); } ## add_ip @@ -125,23 +143,27 @@ foreach my $path (@plugins) { if ($@) { fail("$name : $@"); - } else { + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); + } else { + is (undef, undef, $name); } - ## add_already_exist_ip - $test = "add_already_exist_ip"; - $name = "$testid $test"; + if($ipam) { + ## add_already_exist_ip + $test = "add_already_exist_ip"; + $name = "$testid $test"; - eval { - PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description); - }; + eval { + PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description); + }; - if ($@) { - is (undef, undef, $name); - } else { - fail("$name : $@"); + if ($@) { + is (undef, undef, $name); + } else { + fail("$name : $@"); + } } ## add_second_ip @@ -156,12 +178,13 @@ foreach my $path (@plugins) { if ($@) { fail("$name : $@"); - } else { + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); + } else { + is (undef, undef, $name); } - ## add_next_free $test = "add_next_freeip"; $name = "$testid $test"; @@ -174,7 +197,7 @@ foreach my $path (@plugins) { if ($@) { fail("$name : $@"); - } else { + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); } @@ -191,27 +214,30 @@ foreach my $path (@plugins) { if ($@) { fail("$name : $@"); - } else { + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); - } - - ## del_subnet_not_empty - $test = "del_subnet_not_empty"; - $name = "$testid $test"; - $result = undef; - $expected = undef; - - eval { - PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); - }; - - if ($@) { - is ($result, $expected, $name); } else { - fail("$name : $@"); + is (undef, undef, $name); } + if($ipam){ + ## del_subnet_not_empty + $test = "del_subnet_not_empty"; + $name = "$testid $test"; + $result = undef; + $expected = undef; + + eval { + PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); + }; + + if ($@) { + is ($result, $expected, $name); + } else { + fail("$name : $@"); + } + } ## add_ip_rollback_failing_dns @@ -239,8 +265,12 @@ foreach my $path (@plugins) { }; if ($@) { - $result = $js->encode($plugin->read_db()); - is ($result, $expected, $name); + if($ipam) { + $result = $js->encode($plugin->read_db()); + is ($result, $expected, $name); + } else { + is (undef, undef, $name); + } } else { fail("$name : $@"); } @@ -261,9 +291,11 @@ foreach my $path (@plugins) { if ($@) { fail("$name : $@"); - } else { + } elsif($ipam) { $result = $js->encode($plugin->read_db()); is ($result, $expected, $name); + } else { + is (undef, undef, $name); } } diff --git a/test/subnets/noipam/ipam_config b/test/subnets/noipam/ipam_config new file mode 100644 index 0000000..a33be30 --- /dev/null +++ b/test/subnets/noipam/ipam_config @@ -0,0 +1,18 @@ +{ + 'ids' => { + 'phpipam' => { + 'url' => 'https://localhost/api/apiadmin', + 'type' => 'phpipam', + 'section' => 1, + 'token' => 'JPHkPSLB4O_XL-GQz4qtEFmNpx-99Htw' + }, + 'pve' => { + 'type' => 'pve' + }, + 'netbox' => { + 'token' => '0123456789abcdef0123456789abcdef01234567', + 'type' => 'netbox', + 'url' => 'http://localhost:8000/api' + } + }, +} diff --git a/test/subnets/noipam/sdn_config b/test/subnets/noipam/sdn_config new file mode 100644 index 0000000..55107d6 --- /dev/null +++ b/test/subnets/noipam/sdn_config @@ -0,0 +1,20 @@ +{ + version => 1, + vnets => { + ids => { + myvnet => { type => "vnet", zone => "myzone" }, + }, + }, + + zones => { + ids => { myzone => { type =>"simple" } }, + }, + + subnets => { + ids => { 'myzone-10.0.0.0-24' => { + 'type' => 'subnet', + 'vnet' => 'myvnet', + } + } + } +} -- 2.20.1