[pve-devel] [PATCH pve-network 11/15] tests: add dns tests

Alexandre Derumier aderumier at odiso.com
Tue Jan 5 10:35:32 CET 2021


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 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





More information about the pve-devel mailing list