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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3552B65FE5 for ; Tue, 5 Jan 2021 10:35:54 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1C29025950 for ; Tue, 5 Jan 2021 10:35:53 +0100 (CET) Received: from kvmformation1.odiso.net (globalOdiso.M6Lille.odiso.net [89.248.211.242]) by firstgate.proxmox.com (Proxmox) with ESMTP id CAB0F254DF for ; Tue, 5 Jan 2021 10:35:37 +0100 (CET) Received: by kvmformation1.odiso.net (Postfix, from userid 0) id 87D0ED2598; Tue, 5 Jan 2021 10:35:37 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Tue, 5 Jan 2021 10:35:32 +0100 Message-Id: <20210105093536.1727641-12-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210105093536.1727641-1-aderumier@odiso.com> References: <20210105093536.1727641-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 2 AWL -1.135 Adjusted score from AWL reputation of From: address HEADER_FROM_DIFFERENT_DOMAINS 0.248 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.287 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [2.ip6.arpa, 10.in-addr.arpa] URI_TRY_3LD 1.997 "Try it" URI, suspicious hostname Subject: [pve-devel] [PATCH pve-network 11/15] tests: add dns tests 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: Tue, 05 Jan 2021 09:35:54 -0000 Signed-off-by: Alexandre Derumier --- test/Makefile | 5 +- test/dns/powerdns/dns_config | 10 + .../expected.add_a_multiple_record.ipv4 | 13 + .../expected.add_a_multiple_record.ipv6 | 13 + test/dns/powerdns/expected.add_a_record.ipv4 | 12 + test/dns/powerdns/expected.add_a_record.ipv6 | 13 + .../dns/powerdns/expected.add_ptr_record.ipv4 | 13 + .../dns/powerdns/expected.add_ptr_record.ipv6 | 12 + .../expected.del_a_multiple_record.ipv4 | 13 + .../expected.del_a_multiple_record.ipv6 | 12 + test/dns/powerdns/expected.del_a_record.ipv4 | 13 + test/dns/powerdns/expected.del_a_record.ipv6 | 12 + .../dns/powerdns/expected.del_ptr_record.ipv4 | 12 + .../dns/powerdns/expected.del_ptr_record.ipv6 | 13 + test/dns/powerdns/expected.verify_zone | 12 + test/dns/powerdns/sdn_config | 20 ++ test/run_test_dns.pl | 271 ++++++++++++++++++ 17 files changed, 468 insertions(+), 1 deletion(-) create mode 100644 test/dns/powerdns/dns_config create mode 100644 test/dns/powerdns/expected.add_a_multiple_record.ipv4 create mode 100644 test/dns/powerdns/expected.add_a_multiple_record.ipv6 create mode 100644 test/dns/powerdns/expected.add_a_record.ipv4 create mode 100644 test/dns/powerdns/expected.add_a_record.ipv6 create mode 100644 test/dns/powerdns/expected.add_ptr_record.ipv4 create mode 100644 test/dns/powerdns/expected.add_ptr_record.ipv6 create mode 100644 test/dns/powerdns/expected.del_a_multiple_record.ipv4 create mode 100644 test/dns/powerdns/expected.del_a_multiple_record.ipv6 create mode 100644 test/dns/powerdns/expected.del_a_record.ipv4 create mode 100644 test/dns/powerdns/expected.del_a_record.ipv6 create mode 100644 test/dns/powerdns/expected.del_ptr_record.ipv4 create mode 100644 test/dns/powerdns/expected.del_ptr_record.ipv6 create mode 100644 test/dns/powerdns/expected.verify_zone create mode 100644 test/dns/powerdns/sdn_config create mode 100755 test/run_test_dns.pl diff --git a/test/Makefile b/test/Makefile index 6eb88a1..ca05cf7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,9 +1,12 @@ all: test -test: test_zones test_ipams +test: test_zones test_ipams test_dns test_zones: run_test_zones.pl ./run_test_zones.pl test_ipams: run_test_ipams.pl ./run_test_ipams.pl + +test_dns: run_test_dns.pl + ./run_test_dns.pl diff --git a/test/dns/powerdns/dns_config b/test/dns/powerdns/dns_config new file mode 100644 index 0000000..6052366 --- /dev/null +++ b/test/dns/powerdns/dns_config @@ -0,0 +1,10 @@ +{ + 'ids' => { + 'powerdns' => { + 'url' => 'http://localhost:8881/api/v1/servers/localhost', + 'type' => 'powerdns', + 'key' => '1234', + 'ttl' => '3600' + }, + }, +} diff --git a/test/dns/powerdns/expected.add_a_multiple_record.ipv4 b/test/dns/powerdns/expected.add_a_multiple_record.ipv4 new file mode 100644 index 0000000..0e5539f --- /dev/null +++ b/test/dns/powerdns/expected.add_a_multiple_record.ipv4 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"127.0.0.1","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"A"},{"content":"10.0.0.1","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"A"}],"ttl":"3600","type":"A"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.add_a_multiple_record.ipv6 b/test/dns/powerdns/expected.add_a_multiple_record.ipv6 new file mode 100644 index 0000000..e432e7b --- /dev/null +++ b/test/dns/powerdns/expected.add_a_multiple_record.ipv6 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"2001:4860:4860::8844","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"AAAA"},{"content":"2001:4860:4860::8888","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"AAAA"}],"ttl":"3600","type":"AAAA"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.add_a_record.ipv4 b/test/dns/powerdns/expected.add_a_record.ipv4 new file mode 100644 index 0000000..888d67f --- /dev/null +++ b/test/dns/powerdns/expected.add_a_record.ipv4 @@ -0,0 +1,12 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"10.0.0.1","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"A"}],"ttl":"3600","type":"A"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); \ No newline at end of file diff --git a/test/dns/powerdns/expected.add_a_record.ipv6 b/test/dns/powerdns/expected.add_a_record.ipv6 new file mode 100644 index 0000000..bfeeab7 --- /dev/null +++ b/test/dns/powerdns/expected.add_a_record.ipv6 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"2001:4860:4860::8888","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"AAAA"}],"ttl":"3600","type":"AAAA"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.add_ptr_record.ipv4 b/test/dns/powerdns/expected.add_ptr_record.ipv4 new file mode 100644 index 0000000..6923971 --- /dev/null +++ b/test/dns/powerdns/expected.add_ptr_record.ipv4 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"1.0.0.10.in-addr.arpa.","records":[{"content":"myhostname.","disabled":false,"name":"1.0.0.10.in-addr.arpa.","priority":0,"type":"PTR"}],"ttl":"3600","type":"PTR"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.add_ptr_record.ipv6 b/test/dns/powerdns/expected.add_ptr_record.ipv6 new file mode 100644 index 0000000..1d8049f --- /dev/null +++ b/test/dns/powerdns/expected.add_ptr_record.ipv6 @@ -0,0 +1,12 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa.","records":[{"content":"myhostname.","disabled":false,"name":"8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa.","priority":0,"type":"PTR"}],"ttl":"3600","type":"PTR"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); diff --git a/test/dns/powerdns/expected.del_a_multiple_record.ipv4 b/test/dns/powerdns/expected.del_a_multiple_record.ipv4 new file mode 100644 index 0000000..45d76c6 --- /dev/null +++ b/test/dns/powerdns/expected.del_a_multiple_record.ipv4 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"127.0.0.1","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"A"}],"ttl":"3600","type":"A"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.del_a_multiple_record.ipv6 b/test/dns/powerdns/expected.del_a_multiple_record.ipv6 new file mode 100644 index 0000000..9b56abd --- /dev/null +++ b/test/dns/powerdns/expected.del_a_multiple_record.ipv6 @@ -0,0 +1,12 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"REPLACE","name":"myhostname.domain.com.","records":[{"content":"2001:4860:4860::8844","disabled":false,"name":"myhostname.domain.com.","priority":0,"type":"AAAA"}],"ttl":"3600","type":"AAAA"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); diff --git a/test/dns/powerdns/expected.del_a_record.ipv4 b/test/dns/powerdns/expected.del_a_record.ipv4 new file mode 100644 index 0000000..7c0cf45 --- /dev/null +++ b/test/dns/powerdns/expected.del_a_record.ipv4 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"DELETE","name":"myhostname.domain.com.","records":[],"type":"A"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.del_a_record.ipv6 b/test/dns/powerdns/expected.del_a_record.ipv6 new file mode 100644 index 0000000..9494c83 --- /dev/null +++ b/test/dns/powerdns/expected.del_a_record.ipv6 @@ -0,0 +1,12 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"DELETE","name":"myhostname.domain.com.","records":[],"type":"AAAA"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); diff --git a/test/dns/powerdns/expected.del_ptr_record.ipv4 b/test/dns/powerdns/expected.del_ptr_record.ipv4 new file mode 100644 index 0000000..120485b --- /dev/null +++ b/test/dns/powerdns/expected.del_ptr_record.ipv4 @@ -0,0 +1,12 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"DELETE","name":"1.0.0.10.in-addr.arpa.","records":[],"type":"PTR"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); diff --git a/test/dns/powerdns/expected.del_ptr_record.ipv6 b/test/dns/powerdns/expected.del_ptr_record.ipv6 new file mode 100644 index 0000000..7948e78 --- /dev/null +++ b/test/dns/powerdns/expected.del_ptr_record.ipv6 @@ -0,0 +1,13 @@ +bless( { + '_content' => '{"rrsets":[{"changetype":"DELETE","name":"8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa.","records":[],"type":"PTR"}]}', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'PATCH', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com')}, 'URI::http' ) + }, 'HTTP::Request' ); + diff --git a/test/dns/powerdns/expected.verify_zone b/test/dns/powerdns/expected.verify_zone new file mode 100644 index 0000000..b476875 --- /dev/null +++ b/test/dns/powerdns/expected.verify_zone @@ -0,0 +1,12 @@ +bless( { + '_content' => '', + '_headers' => bless( { + '::std_case' => { + 'x-api-key' => 'X-API-Key' + }, + 'content-type' => 'application/json; charset=UTF-8', + 'x-api-key' => '1234' + }, 'HTTP::Headers' ), + '_method' => 'GET', + '_uri' => bless( do{\(my $o = 'http://localhost:8881/api/v1/servers/localhost/zones/domain.com?rrsets=false')}, 'URI::http' ) + }, 'HTTP::Request' ); diff --git a/test/dns/powerdns/sdn_config b/test/dns/powerdns/sdn_config new file mode 100644 index 0000000..2087729 --- /dev/null +++ b/test/dns/powerdns/sdn_config @@ -0,0 +1,20 @@ +{ + version => 1, + vnets => { + ids => { + myvnet => { type => "vnet", zone => "myzone" }, + }, + }, + + zones => { + ids => { myzone => { ipam => "pve", type =>"simple", dns => "powerdns", reversedns => "powerdns", dnszone => "domain.com" } }, + }, + + subnets => { + ids => { 'myzone-10.0.0.0-24' => { + 'type' => 'subnet', + 'vnet' => 'myvnet', + } + } + } +} diff --git a/test/run_test_dns.pl b/test/run_test_dns.pl new file mode 100755 index 0000000..87e011e --- /dev/null +++ b/test/run_test_dns.pl @@ -0,0 +1,271 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use lib qw(..); +use File::Slurp; +use Net::IP; + +use Test::More; +use Test::MockModule; + +use PVE::Network::SDN; +use PVE::Network::SDN::Zones; +use PVE::Network::SDN::Controllers; +use JSON; + +use Data::Dumper qw(Dumper); +$Data::Dumper::Sortkeys = 1; + +sub read_sdn_config { + my ($file) = @_; + # Read structure back in again + open my $in, '<', $file or die $!; + my $sdn_config; + { + local $/; # slurp mode + $sdn_config = eval <$in>; + } + close $in; + + return $sdn_config; +} + + +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 $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"); + return $dns_config; + }, + ); + + my $sdn_module = Test::MockModule->new("PVE::Network::SDN"); + $sdn_module->mock( + config => sub { + 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 $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 $hostname = "myhostname"; + + foreach my $ip (@ips) { + + 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 $sdn_dns_plugin = Test::MockModule->new($plugin); + $sdn_dns_plugin->mock( + + get_zone_content => sub { + return undef; + }, + get_zone_rrset => sub { + return undef; + } + ); + + ## add_a_record + my $test = "add_a_record"; + my $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + my $name = "$dnsid $test"; + + $plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + + ## add_ptr_record + $test = "add_ptr_record"; + $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + $name = "$dnsid $test"; + + $plugin->add_ptr_record($plugin_config, $zone, $hostname, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + + + ## del_ptr_record + $test = "del_ptr_record"; + $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + $name = "$dnsid $test"; + + $plugin->del_ptr_record($plugin_config, $zone, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + + + ## del_a_record + + $sdn_dns_plugin->mock( + + get_zone_content => sub { + return undef; + }, + 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, + priority => 0 }; + + my $rrset = { name => $fqdn, + type => $type, + ttl => '3600', + records => [ $record ] }; + return $rrset; + } + ); + + $test = "del_a_record"; + $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + $name = "$dnsid $test"; + + $plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + + ## del_a_multiple_record + + $sdn_dns_plugin->mock( + + get_zone_content => sub { + return undef; + }, + get_zone_rrset => sub { + + my $record = { content => $ip, + disabled => JSON::false, + name => $fqdn, + type => $type, + priority => 0 }; + + my $record2 = { content => $ip2, + disabled => JSON::false, + name => $fqdn, + type => $type, + priority => 0 }; + + my $rrset = { name => $fqdn, + type => $type, + ttl => '3600', + records => [ $record, $record2 ] }; + return $rrset; + } + ); + + $test = "del_a_multiple_record"; + $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + $name = "$dnsid $test"; + + $plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + + ## add_a_multiple_record + + $sdn_dns_plugin->mock( + + get_zone_content => sub { + return undef; + }, + get_zone_rrset => sub { + + my $record2 = { content => $ip2, + disabled => JSON::false, + name => $fqdn, + type => $type, + priority => 0 }; + + my $rrset = { name => $fqdn, + type => $type, + ttl => '3600', + records => [ $record2 ] }; + return $rrset; + } + ); + + $test = "add_a_multiple_record"; + $expected = Dumper read_sdn_config("$path/expected.$test.$ipversion"); + $name = "$dnsid $test"; + + $plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + } + + ## verify_zone + my $test = "verify_zone"; + my $expected = Dumper read_sdn_config("$path/expected.$test"); + my $name = "$dnsid $test"; + + $plugin->verify_zone($plugin_config, $zone, 1); + + if ($@) { + is ($@, $expected, $name); + } else { + fail($name); + } + +} + +done_testing(); + + -- 2.20.1