Skip to content

Commit

Permalink
Report error when 2nd stage is disabled (bsc#1046198) (#524)
Browse files Browse the repository at this point in the history
* Report error when 2nd stage is disabled (bsc#1046198)

* Code review fixes

* Added unit test

* Check more settings, use more generic message

* Changes
  • Loading branch information
lslezak committed Jul 10, 2017
1 parent 7f99c07 commit e038d72
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Tue Jul 4 15:06:40 UTC 2017 - lslezak@suse.cz

- Display a warning in AutoYaST installation when importing the DNS
configuration with disabled seconds stage (the second stage is
currently required for writing the config) (bsc#1046198)
- 3.2.31

-------------------------------------------------------------------
Tue Jul 4 12:57:05 UTC 2017 - mfilka@suse.com

Expand Down
29 changes: 29 additions & 0 deletions src/modules/DNS.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def main
Yast.import "Service"
Yast.import "String"
Yast.import "FileUtils"
Yast.import "Stage"
Yast.import "Mode"
Yast.import "Report"

Yast.include self, "network/routines.rb"
Yast.include self, "network/runtime.rb"
Expand Down Expand Up @@ -83,6 +86,9 @@ def main

# True if DNS is already read
@initialized = false

# report the profile error only once
@error_reported = false
end

# Use the parameter, coming usually from install.inf, if it is defined.
Expand Down Expand Up @@ -479,6 +485,23 @@ def Import(settings)

@nameservers = Builtins.eval(Ops.get_list(settings, "nameservers", []))
@searchlist = Builtins.eval(Ops.get_list(settings, "searchlist", []))

# check for AY unsupported scenarios, the name servers and the search domains
# are written in the 2nd stage, if is disabled then it cannot work (bsc#1046198)
if Stage.initial && Mode.auto && !@error_reported && !empty?
# lazy loading to avoid the dependency on AutoYaST, this can be imported only
# in the initial stage otherwise it might fail!
Yast.import "AutoinstConfig"

if !AutoinstConfig.second_stage
# TRANSLATORS: Warning message, the AutoYaST XML profile is incorrect
Report.Warning(_("DNS configuration error: The DNS configuration\n" \
"is written in the second installation stage (after reboot)\n" \
"but the second stage is disabled in the AutoYaST XML profile."))
@error_reported = true
end
end

@modified = true
# empty settings means that we're probably resetting the config
# thus, setup is not initialized anymore
Expand Down Expand Up @@ -691,6 +714,12 @@ def read_hostname_from_install_inf
fqhostname
end

# empty configuration?
# @return [Boolean] true if the configuration is empty (or contains defaults)
def empty?
@nameservers.empty? && @searchlist.empty? && @hostname.empty? && @domain.empty?
end

publish variable: :proposal_valid, type: "boolean"
publish variable: :hostname, type: "string"
publish variable: :domain, type: "string"
Expand Down
35 changes: 35 additions & 0 deletions test/dns_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ module Yast
end

describe ".Import" do
before do
allow(Yast::Stage).to receive(:initial).and_return(false)
end

context "with present dhcp_hostname and write_hostname" do
let(:settings) { { "hostname" => "host", "dhcp_hostname" => true, "write_hostname" => true } }

Expand All @@ -101,6 +105,37 @@ module Yast
expect(DNS.dhcp_hostname).to eql(false)
end
end

context "The AutoYaST first stage installation" do
let(:settings) { { "hostname" => "host", "searchlist" => ["example.com"] } }

before do
allow(Yast::Stage).to receive(:initial).and_return(true)
allow(Yast::Mode).to receive(:auto).and_return(true)
allow(Yast).to receive(:import).with("AutoinstConfig")
# reset the internal counter
DNS.instance_variable_set(:@error_reported, false)
end

it "prints a warning when the 2nd stage is disabled for writing the search list" do
stub_const("Yast::AutoinstConfig", double(second_stage: false))
expect(Yast::Report).to receive(:Warning)
DNS.Import(settings)
end

it "prints the warning only once on multiple calls" do
stub_const("Yast::AutoinstConfig", double(second_stage: false))
expect(Yast::Report).to receive(:Warning).once
DNS.Import(settings)
DNS.Import(settings)
end

it "does not print a warning when the 2nd stage is enabled for writing the search list" do
stub_const("Yast::AutoinstConfig", double(second_stage: true))
expect(Yast::Report).to_not receive(:Warning)
DNS.Import(settings)
end
end
end
end
end

0 comments on commit e038d72

Please sign in to comment.