-
Notifications
You must be signed in to change notification settings - Fork 266
/
yast_dns_server.pm
138 lines (122 loc) · 6.65 KB
/
yast_dns_server.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# SUSE's openQA tests
#
# Copyright © 2019-2020 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#
# All of cases is based on the reference:
# https://documentation.suse.com/sles/15-SP1/single-html/SLES-admin/#id-1.3.3.6.13.6.11
#
# Package: yast2-dns-server bind bind-libs
# Summary: Create DNS forwarder and DNS server, verify lookup.
#
# 1. Create a sub to handle command and verify it result
# 2. Create DNS forwarder
# 3. Create DNS server
# 4. Add, remove, show records
# 5. Reproduce bugs
# Maintainer: Tony Yuan <tyuan@suse.com>
package yast_dns_server;
use base 'consoletest';
use strict;
use warnings;
use testapi;
use utils;
use List::Util qw(all any);
use Utils::Systemd 'disable_and_stop_service';
use version_utils 'is_sle';
sub cmd_handle {
my ($self, $cmd, $subcmd, %args) = @_;
my $zop;
my $op;
foreach my $k (keys %args) {
if ($k eq "zone") {
$zop = "zone=$args{$k}";
delete $args{$k};
next;
}
$op .= " $k=$args{$k}";
}
assert_script_run("yast2 dns-server $cmd $subcmd $zop $op");
validate_script_output("yast2 dns-server $cmd show $zop 2>&1", sub {
my $output = $_;
if ($subcmd eq "remove") {
any { $output !~ m/\Q$_\E/; } values %args;
}
else {
all { $output =~ m/\Q$_\E/i; } values %args;
} });
}
sub bug1151130_softfail {
my ($self, $cmd, $subcmd, $zone, %args) = @_;
my $op = '';
my $vrf;
foreach my $k (keys %args) {
$op .= " $k=$args{$k}";
}
$vrf = $1 if ($op =~ /.*=(.*)$/);
assert_script_run("yast2 dns-server $cmd $subcmd zone=$zone $op");
my $out = script_output("yast2 dns-server $cmd show zone=$zone 2>&1");
record_soft_failure("bsc#1151135") unless $out =~ /\Q$vrf\E/;
}
sub run {
my $self = shift;
select_console 'root-console';
zypper_call("in yast2-dns-server bind", exitcode => [0, 102, 103, 106]);
zypper_call("in bind-libs", exitcode => [0, 102, 103, 106]) if is_sle('=12-SP2');
#enables netconfig to always force a replace of modified file to avoid ncurse prompt.
assert_script_run(qq(sed -i 's/NETCONFIG_FORCE_REPLACE="no"/NETCONFIG_FORCE_REPLACE="yes"/' /etc/sysconfig/network/config));
#Forward server and test lookup
my $opensuseip = script_output("dig www.opensuse.org +short");
$opensuseip =~ s/.*^(\d+\.\d+\.\d+\.\d+).*/$1/ms;
$self->cmd_handle("forwarders", "add", ip => "10.0.2.3");
#disable dnssec validation
assert_script_run("sed -i 's/#dnssec-validation auto/dnssec-validation no/' /etc/named.conf");
systemctl("start named.service");
validate_script_output('dig @localhost www.opensuse.org +short', sub { /\Q$opensuseip\E/ });
assert_script_run("sed -i 's/dnssec-validation no/#dnssec-validation auto/' /etc/named.conf");
$self->cmd_handle("forwarders", "remove", ip => "10.0.2.3");
record_soft_failure("bsc#1151138") if (systemctl("is-active named.service", ignore_failure => 1));
# create zone and reverse zone
$self->cmd_handle("zones", "add", name => "example.org", zonetype => "master");
$self->cmd_handle("zones", "add", name => "100.168.192.in-addr.arpa", zonetype => "master");
# Create host and test lookup
$self->cmd_handle("host", "add", zone => "example.org", hostname => "host02.example.org.", ip => "192.168.100.4");
systemctl("start named.service") if systemctl("is-active named.service", ignore_failure => 1);
validate_script_output('dig @localhost host02.example.org +short', sub { /\Q192.168.100.4\E/ });
validate_script_output('dig @localhost -x 192.168.100.4 +short', sub { /\Qhost02.example.org\E/ });
$self->cmd_handle("host", "remove", zone => "example.org", hostname => "host02.example.org.", ip => "192.168.100.4");
#logging
$self->cmd_handle("logging", "set", destination => "file", maxsize => "100M", file => "/var/log/named.log", maxversions => "3");
# soa
$self->cmd_handle("soa", "set", zone => "example.org", serial => "2019090502", expiry => "2W", retry => "2H");
# dns record
#i.e. dnsrecord add zone=example.org query=example.org. type=MX value='10 mail01'
$self->cmd_handle("dnsrecord", "add", zone => "example.org", query => "subdomain.example.org.", type => "NS", value => "ns1"); #delegated domain
$self->cmd_handle("dnsrecord", "remove", zone => "example.org", query => "subdomain.example.org.", type => "NS", value => "ns1");
$self->cmd_handle("dnsrecord", "add", zone => "example.org", query => "host1", type => "A", value => "192.168.100.3"); #host adress
$self->cmd_handle("dnsrecord", "remove", zone => "example.org", query => "host1", type => "A", value => "192.168.100.3");
$self->cmd_handle("dnsrecord", "add", zone => "100.168.192.in-addr.arpa", query => "123", type => "PTR", value => "host1"); ##PTR
$self->cmd_handle("dnsrecord", "remove", zone => "100.168.192.in-addr.arpa", query => "123", type => "PTR", value => "host1");
$self->cmd_handle("dnsrecord", "add", zone => "example.org", query => "ns6", type => "CNAME", value => "server6.anywhere.net."); ##CNAME
$self->cmd_handle("dnsrecord", "remove", zone => "example.org", query => "ns6", type => "CNAME", value => "server6.anywhere.net.");
# mailserver, nameserver
$self->bug1151130_softfail("mailserver", "add", "example.org", priority => "97", mx => "mx001");
$self->bug1151130_softfail("nameserver", "add", "example.org", ns => "ns2.example.com.");
#startup setting
systemctl("stop named.service") unless systemctl("is-active named.service", ignore_failure => 1);
assert_script_run("yast2 dns-server startup atboot");
my $out = script_output("yast2 dns-server startup show 2>&1");
record_soft_failure("bsc#1151130") unless $out =~ /enabled in the boot process/; #sle15+ bug
record_soft_failure("bsc#1151130") unless systemctl("is-active named.service", ignore_failure => 1); #sle12sp4- bug
assert_script_run("yast2 dns-server startup manual");
#remove zone, stop service
$self->cmd_handle("zones", "remove", name => "example.org", zonetype => "master");
$self->cmd_handle("zones", "remove", name => "100.168.192.in-addr.arpa", zonetype => "master");
disable_and_stop_service('named.service');
assert_script_run(qq(sed -i 's/NETCONFIG_FORCE_REPLACE="yes"/NETCONFIG_FORCE_REPLACE="no"/' /etc/sysconfig/network/config));
}
1;