Skip to content

Commit

Permalink
Added argument to the interfaces writer for write only
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 20, 2020
1 parent 8d12d0f commit 5894766
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
11 changes: 9 additions & 2 deletions src/lib/network/network_autoyast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def set_network_service
NetworkService.EnableDisableNow
end

# Initializates NICs setup according AY profile
# Writes the autoyast network configuration according to the already
# imported configuration
#
# If the network was already written before the proposal it returns without
# touching it
Expand All @@ -111,7 +112,13 @@ def configure_lan
log.info("NetworkAutoYast: Lan configuration")
return false if Lan.autoinst.before_proposal

Lan.WriteOnly
# force a write only as it is run at the end of the installation and in
# the target system
original_value = Lan.write_only
Lan.write_only = true
ret = Lan.Write
Lan.write_only = original_value
ret
end

# Takes care of activate s390 devices from the profile declaration
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/sysconfig/config_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def write_hostname_settings(config, old_config)
# @param interfaces [Y2Network::InterfacesCollection]
# @see Y2Network::Sysconfig::InterfacesWriter
def write_interfaces(interfaces)
writer = Y2Network::Sysconfig::InterfacesWriter.new
writer = Y2Network::Sysconfig::InterfacesWriter.new(reload: !Yast::Lan.write_only)
writer.write(interfaces)
end

Expand Down
17 changes: 7 additions & 10 deletions test/network_autoyast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,16 @@ def nm_installed(installed)
let(:networking_section) { { "setup_before_proposal" => before_proposal } }

it "does not write anything" do
expect(Yast::Lan).to_not receive(:WriteOnly)
expect(Yast::Lan).to_not receive(:Write)

subject.configure_lan
end
end

context "when the configuration is not done before the proposal" do
let(:before_proposal) { true }
let(:before_proposal) { false }
let(:networking_section) { { "setup_before_proposal" => before_proposal } }

it "does not write anything" do
expect(Yast::Lan).to_not receive(:WriteOnly)

subject.configure_lan
end

context "and the user wants to keep the installation network" do
let(:networking_section) { { "keep_install_network" => true } }

Expand All @@ -331,8 +325,11 @@ def nm_installed(installed)
end
end

it "writes the current configuration taking into account if needs to start it immediately" do
expect(Yast::Lan).to_not receive(:WriteOnly)
it "writes the current configuration without starting it" do
original_value = Yast::Lan.write_only
expect(Yast::Lan).to receive(:write_only=).with(true)
expect(Yast::Lan).to receive(:Write)
expect(Yast::Lan).to receive(:write_only=).with(original_value)

subject.configure_lan
end
Expand Down
42 changes: 30 additions & 12 deletions test/y2network/sysconfig/interfaces_writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
require "tmpdir"

describe Y2Network::Sysconfig::InterfacesWriter do
subject(:writer) { described_class.new }
let(:reload) { false }
subject(:writer) { described_class.new(reload: reload) }

describe "#write" do
let(:interfaces) { Y2Network::InterfacesCollection.new([eth0]) }
Expand Down Expand Up @@ -71,20 +72,18 @@
end

context "and the reload is forced" do
let(:reload) { true }

it "sets the interface down" do
expect(Yast::Execute).to receive(:on_target).with("/sbin/ifdown", "eth0")
subject.write(interfaces)
end
end

context "and the reload is not forced (ie: autoinstallation)" do
before do
allow(Yast::Mode).to receive(:autoinst).and_return(true)
end

context "and the reload is not forced (ie: end of the autoinstallation)" do
context "if not forced the reload" do
it "does not set the interface down" do
expect(Yast::Execute).to receive(:on_target).with("/sbin/ifdown", any_args)
expect(Yast::Execute).to_not receive(:on_target).with("/sbin/ifdown", any_args)
subject.write(interfaces)
end
end
Expand Down Expand Up @@ -201,11 +200,30 @@
end
end

it "refreshes udev" do
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "control", any_args)
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "trigger", any_args)
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "settle")
subject.write(interfaces)
context "after the udev rules have been written" do
context "when the reload is forced" do
let(:reload) { true }

it "refreshes udev" do
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "control", any_args)
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "trigger", any_args)
expect(Yast::Execute).to receive(:on_target).with("/usr/bin/udevadm", "settle")
subject.write(interfaces)
end
end

context "when the reload is not forced" do
it "does not refresh udev" do
expect(Yast::Execute)
.to_not receive(:on_target).with("/usr/bin/udevadm", "control", any_args)
expect(Yast::Execute)
.to_not receive(:on_target).with("/usr/bin/udevadm", "trigger", any_args)
expect(Yast::Execute)
.to_not receive(:on_target).with("/usr/bin/udevadm", "settle")
subject.write(interfaces)
end
end

end
end
end

0 comments on commit 5894766

Please sign in to comment.