Skip to content

Commit

Permalink
Merge pull request #36 from kobliha/fix_import
Browse files Browse the repository at this point in the history
Fixed AutoYast Import() and Write()
  • Loading branch information
kobliha committed Dec 8, 2014
2 parents 3ee6d2f + d7f8c3a commit 550d213
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 19 deletions.
11 changes: 11 additions & 0 deletions package/yast2-dns-server.changes
@@ -1,3 +1,14 @@
-------------------------------------------------------------------
Fri Dec 5 16:44:27 CET 2014 - locilka@suse.com

- Fixed Import() and Write() in AutoYast (bnc#898659)
- Imported zones were not written to the system as they were not
marked as 'modified'
- Directory /etc/named.d/ was used even if it didn't exist
- The whole named.conf was rewritten from scratch as Yast thought
that something has changed that file while Yast was running
- 3.1.7.1

-------------------------------------------------------------------
Thu Sep 4 12:20:11 UTC 2014 - mvidner@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-dns-server.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-dns-server
Version: 3.1.7
Version: 3.1.7.1
Release: 0
Url: https://github.com/yast/yast-dns-server

Expand Down
3 changes: 1 addition & 2 deletions src/clients/dns-server_auto.rb
Expand Up @@ -46,8 +46,7 @@ def main

# Create a summary
if @func == "Summary"
@ret_list = DnsServer.Summary
@ret = Ops.get_string(@ret_list, 0, "")
@ret = DnsServer.Summary.join("<br>\n")
# Reset configuration
elsif @func == "Reset"
DnsServer.Import({})
Expand Down
28 changes: 22 additions & 6 deletions src/modules/DnsServer.pm
Expand Up @@ -34,6 +34,7 @@ YaST::YCP::Import ("NetworkService");
YaST::YCP::Import ("Hostname");
YaST::YCP::Import ("FileUtils");
YaST::YCP::Import ("DnsServerHelperFunctions");
YaST::YCP::Import ("String");

use DnsZones;
use DnsTsigKeys;
Expand All @@ -52,7 +53,9 @@ my $reverse_zones_connections = 'yast2-dns-server_reverse-zones';

my %reverse_zones_connections_data = ();

my $forwarders_include = '/etc/named.d/forwarders.conf';
my $includes_dir = '/etc/named.d/';

my $forwarders_include = $includes_dir.'forwarders.conf';

my $data_file = Directory->vardir."/dns_server";

Expand Down Expand Up @@ -123,7 +126,7 @@ sub ZoneWrite {
return 0;
}

if ($zone_name eq "localhost" || $zone_name eq "0.0.127.in-addr.arpa")
if ($zone_name eq "localhost" || $zone_name eq "0.0.127.in-addr.arpa" || $zone_name =~ /^(0\.)+ip6.arpa$/)
{
y2milestone ("Skipping system zone $zone_name");
return 1;
Expand Down Expand Up @@ -1338,6 +1341,9 @@ sub Write {
}
}

# Make sure the includes dir really exists
SCR->Execute(".target.bash", "mkdir -pv '".String->Quote($includes_dir)."'");

foreach my $z (@zones) {

if (defined $z->{"connected_with"} && $z->{"connected_with"} ne "") {
Expand Down Expand Up @@ -1547,11 +1553,22 @@ sub Import {
my $self = shift;
my %settings = %{+shift};

# Cache the timestamp as done in Read() otherwise the named.conf
# is re-created from scratch in Write() as is pretends to be changed
# while Yast was running.
$configuration_timestamp = $self->GetConfigurationStat();

$start_service = $settings{"start_service"} || 0;
$chroot = $settings{"chroot"} || 1;
$use_ldap = $settings{"use_ldap"} || 0;
@allowed_interfaces = @{$settings{"allowed_interfaces"} || []};
@zones = @{$settings{"zones"} || []};

@zones = @{$settings{"zones"} || []};
for my $i (0..@zones-1) {
$zones[$i]{"modified"} = 1;
y2milestone("Imported zone: ".$zones[$i]{"zone"});
}

@options = @{$settings{"options"} || []};
@logging = @{$settings{"logging"} || []};

Expand Down Expand Up @@ -1604,8 +1621,7 @@ sub Summary {
}

my @zones_descr = map {
my $zone_ref = $_;
my %zone_map = %{$zone_ref};
my %zone_map = %{$_};
my $zone_name = $zone_map{"zone"} || "";
my $zone_type = $zone_map{"type"} || "";
$zone_type = $zone_types{$zone_type} || $zone_type;
Expand All @@ -1627,7 +1643,7 @@ sub Summary {
$_ ne "";
} @zones_descr;

my $zones_list = join (", ", @zones_descr);
my $zones_list = join (",<br>\n", @zones_descr);
# summary string, %s is list of DNS zones (their names), coma separated
push (@ret, sprintf (__("Configured Zones: %s"), $zones_list));
return \@ret;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/.gitignore
Expand Up @@ -13,4 +13,4 @@ tmp
zone
zone_new
*.bak

raw.tmp.*
4 changes: 2 additions & 2 deletions testsuite/tests/Write.out
@@ -1,10 +1,10 @@
Dump =======================
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":0, "stderr":"", "stdout":"20030806"]
Return true
Dump =======================
Execute .target.bash "mkdir -pv '/etc/named.d/'" 0
Write .target.ycp "/var/lib/YaST2/yast2-dns-server_reverse-zones" $[] true
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":0, "stderr":"", "stdout":"20030806"]
Execute .target.bash_output "mv --force /etc/named.conf /etc/named.conf.yast2-save" $["exit":0, "stderr":"", "stdout":"20030806"]
Execute .target.bash "touch /etc/named.conf" 0
Write .dns.named.value.acl [] true
Dir .dns.named.section: ["options", "zone \"localhost\" in"]
Dir .dns.named.value.options: ["directory", "notify", "xxx"]
Expand Down
14 changes: 11 additions & 3 deletions testsuite/tests/Write.rb
Expand Up @@ -98,7 +98,12 @@ def main
}
}
@I_WRITE = {}
@I_EXEC = {}
@I_EXEC = {
"target" => {
"bash_output" => { "exit" => 0, "stdout" => "20030806", "stderr"=>"" },
"bash" => 0,
}
}

TESTSUITE_INIT([@I_READ, @I_WRITE, @I_EXEC], nil)

Expand Down Expand Up @@ -255,7 +260,10 @@ def main
}
@WRITE = {}
@EXEC = {
"target" => { "bash_output" => { "exit" => 0, "stdout" => "20030806", "stderr"=>"" } }
"target" => {
"bash_output" => { "exit" => 0, "stdout" => "20030806", "stderr"=>"" },
"bash" => 0,
}
}

DUMP("=======================")
Expand Down Expand Up @@ -306,7 +314,7 @@ def main
]
}
)
end, [], 0)
end, [@READ, @WRITE, @EXEC], 0)
DUMP("=======================")
TEST(lambda { DnsServer.Write }, [@READ, @WRITE, @EXEC], 0)

Expand Down
3 changes: 2 additions & 1 deletion testsuite/tests/YaPIReadGlobalOptions.rb
Expand Up @@ -264,7 +264,8 @@ def main
@WRITE = {}
@EXEC = {
"target" => {
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" }
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" },
"bash" => 0
},
"passwd" => { "init" => true }
}
Expand Down
3 changes: 2 additions & 1 deletion testsuite/tests/YaPIReadZones.rb
Expand Up @@ -263,7 +263,8 @@ def main
@WRITE = {}
@EXEC = {
"target" => {
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" }
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" },
"bash" => 0,
},
"passwd" => { "init" => true }
}
Expand Down
1 change: 1 addition & 0 deletions testsuite/tests/YaPIWriteGlobalOptions.out
Expand Up @@ -19,6 +19,7 @@ Read .dns.zone "/var/lib/named/localhost.zone" $["TTL":"1W", "records":[$["key":
Dir .dns.named.value."zone \"localhost\" in": ["file", "type"]
Read .dns.named.value."zone \"localhost\" in"."file" ["\"localhost.zone\""]
Read .dns.named.value."zone \"localhost\" in"."type" ["master"]
Execute .target.bash "mkdir -pv '/etc/named.d/'" 0
Write .target.ycp "/var/lib/YaST2/yast2-dns-server_reverse-zones" $[] true
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":1, "stderr":"", "stdout":""]
Write .dns.named.value.acl [] true
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/YaPIWriteGlobalOptions.rb
Expand Up @@ -241,7 +241,7 @@ def main
@EXEC = {
"target" => {
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" },
"bash" => 1
"bash" => 0
},
"passwd" => { "init" => true }
}
Expand Down
1 change: 1 addition & 0 deletions testsuite/tests/YaPIWriteZones.out
Expand Up @@ -19,6 +19,7 @@ Read .dns.zone "/var/lib/named/localhost.zone" $["TTL":"1W", "records":[$["key":
Dir .dns.named.value."zone \"localhost\" in": ["file", "type"]
Read .dns.named.value."zone \"localhost\" in"."file" ["\"localhost.zone\""]
Read .dns.named.value."zone \"localhost\" in"."type" ["master"]
Execute .target.bash "mkdir -pv '/etc/named.d/'" 0
Write .target.ycp "/var/lib/YaST2/yast2-dns-server_reverse-zones" $[] true
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":1, "stderr":"", "stdout":""]
Write .dns.named.value.acl [] true
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/YaPIWriteZones.rb
Expand Up @@ -263,7 +263,7 @@ def main
@EXEC = {
"target" => {
"bash_output" => { "exit" => 1, "stdout" => "", "stderr" => "" },
"bash" => 1
"bash" => 0
},
"passwd" => { "init" => true }
}
Expand Down

0 comments on commit 550d213

Please sign in to comment.