Skip to content

Commit

Permalink
Merge pull request #658 from yast/bsc-1174118/no-networking-section
Browse files Browse the repository at this point in the history
[bsc#1174118] Do not crash when the networking section is missing
  • Loading branch information
imobachgs committed Jul 22, 2020
2 parents 796729b + e6cb2db commit b703a05
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Jul 21 19:24:34 UTC 2020 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Do not crash when the networking section is missing
(bsc#1174118).
- 4.3.29

-------------------------------------------------------------------
Mon Jul 20 14:51:49 UTC 2020 - Josef Reidinger <jreidinger@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.3.28
Version: 4.3.29
Release: 0
Summary: YaST2 - Automated Installation
License: GPL-2.0-only
Expand Down
29 changes: 12 additions & 17 deletions src/lib/autoinstall/autosetup_helpers.rb
Expand Up @@ -126,23 +126,13 @@ def autosetup_network
# Prevent to be called twice in case of already configured
return if @network_configured

if Yast::Profile.current["networking"]
if network_before_proposal?
log.info("Networking setup before the proposal")
else
log.info("Networking setup at the end of first installation stage")
end

log.info("Importing Network settings from configuration file")
Yast::WFM.CallFunction("lan_auto", ["Import", Yast::Profile.current["networking"]])
Yast::Profile.remove_sections("networking")

# Import also the host section in order to resolve hosts only available
# with the network configuration and the host entry
if Yast::Profile.current["host"] && network_before_proposal?
Yast::WFM.CallFunction("host_auto", ["Import", Yast::Profile.current["host"]])
Yast::Profile.remove_sections("host")
end
networking_section = Yast::Profile.current.fetch("networking", {})
Yast::WFM.CallFunction("lan_auto", ["Import", networking_section])

# Import also the host section in order to resolve hosts only available
# with the network configuration and the host entry
if Yast::Profile.current["host"]
Yast::WFM.CallFunction("host_auto", ["Import", Yast::Profile.current["host"]])
end

if semi_auto?("networking")
Expand All @@ -151,7 +141,12 @@ def autosetup_network
@network_before_proposal = true
end

log.info("Networking setup before the proposal: #{network_before_proposal?}")
Yast::WFM.CallFunction("lan_auto", ["Write"]) if network_before_proposal?

# Clean-up the profile
Yast::Profile.remove_sections(["networking", "host"])

@network_configured = true
end

Expand Down
26 changes: 19 additions & 7 deletions test/lib/autosetup_helpers_test.rb
Expand Up @@ -241,7 +241,7 @@ class DummyClient < Yast::Client

end

describe "#network_autosetup" do
describe "#autosetup_network" do
let(:profile) { networking_section }
let(:networking_section) { { "networking" => { "setup_before_proposal" => true } } }
let(:host_section) { { "host" => { "hosts" => [] } } }
Expand Down Expand Up @@ -299,22 +299,34 @@ class DummyClient < Yast::Client
end

it "sets the network config to be written before the proposal" do
expect { client.autosetup_network }
.to change { client.network_before_proposal? }
.from(false).to(true)
allow(Yast::WFM).to receive(:CallFunction).with("inst_lan", anything)
expect(Yast::WFM).to receive(:CallFunction).with("lan_auto", ["Write"])

client.autosetup_network
end
end

context "in case it was definitely se to be configured before the proposal" do
before do
allow(client).to receive(:network_before_proposal?).and_return(true)
context "in case it was definitely set to be configured before the proposal" do
let(:networking_section) do
{ "networking" => { "setup_before_proposal" => true } }
end

it "writes the network configuration calling the auto client" do
expect(Yast::WFM).to receive(:CallFunction).with("lan_auto", ["Write"])

client.autosetup_network
end
end

context "when no network configuration is given" do
let(:networking_section) { {} }

it "imports the empty profile" do
expect(Yast::WFM).to receive(:CallFunction).with("lan_auto", ["Import", {}])

client.autosetup_network
end
end
end

describe "#semi_auto?" do
Expand Down

0 comments on commit b703a05

Please sign in to comment.