Skip to content

Commit

Permalink
Merge pull request #1096 from yast/bsc-1171416-sysctl-ipv6
Browse files Browse the repository at this point in the history
Write the "\n" after sysctl settings
  • Loading branch information
imobachgs committed Aug 31, 2020
2 parents 5c06fb7 + 58a63f4 commit 7bf1060
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Aug 31 14:45:25 UTC 2020 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Add a line return after the 'disable_ipv6' line in sysctl.conf
(bsc#1171416).
- 4.1.54

-------------------------------------------------------------------
Tue Sep 24 09:58:00 UTC 2019 - Knut Anderssen <kanderssen@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.1.53
Version: 4.1.54
Release: 0
BuildArch: noarch

Expand Down
2 changes: 2 additions & 0 deletions src/modules/Lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ def writeIPv6
file = Builtins.add(file, row)
end
file = Builtins.add(file, sysctl_row) if !found
# Make sure a '\n' is added even if it was already missing (bsc#1171416)
file << "" unless file.empty? || file.last.empty?
SCR.Write(
path(".target.string"),
filename,
Expand Down
96 changes: 96 additions & 0 deletions test/lan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,99 @@ def expect_modification_succeedes(modname, method)
end
end
end

describe "Yast::LanClass#writeIPv6" do
subject { Yast::Lan }

let(:sysctl_content) { "" }
let(:ipv6) { false }

before do
allow(Yast::SCR).to receive(:Write)
.with(path(".target.string"), "")
allow(Yast::SCR).to receive(:Read)
.with(path(".target.string"), /sysctl.conf/)
.and_return(sysctl_content)
allow(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), String)
end

around do |example|
old_ipv6 = subject.ipv6
subject.ipv6 = ipv6
example.run
subject.ipv6 = old_ipv6
end

context "when IPv6 must be enabled" do
let(:ipv6) { true }

context "and the configuration is present in sysctl.conf" do
let(:sysctl_content) { "# net.ipv6.conf.all.disable_ipv6=1" }

it "enables IPv6 in the sysctl.conf (by commenting the disable_ipv6 line)" do
expect(Yast::SCR).to receive(:Write)
.with(path(".target.string"), /sysctl.conf/, "# net.ipv6.conf.all.disable_ipv6 = 1\n")
subject.writeIPv6
end
end

context "and the configuration is missing from sysctl.conf" do
let(:sysctl_content) { "" }

it "enables IPv6 in the sysctl.conf (by commenting the disable_ipv6 line)" do
expect(Yast::SCR).to receive(:Write)
.with(path(".target.string"), /sysctl.conf/, "# net.ipv6.conf.all.disable_ipv6 = 1\n")
subject.writeIPv6
end
end

it "enables IPv6 using sysctl" do
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash"), /sysctl -w net.ipv6.conf.all.disable_ipv6=0/)
subject.writeIPv6
end

it "enables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "yes")
subject.writeIPv6
end
end

context "when IPv6 must be disabled" do
let(:ipv6) { false }

context "and the configuration is present in sysctl.conf" do
let(:sysctl_content) { "net.ipv6.conf.all.disable_ipv6=1" }

it "disables IPv6 in the sysctl.conf" do
expect(Yast::SCR).to receive(:Write)
.with(path(".target.string"), /sysctl.conf/, "net.ipv6.conf.all.disable_ipv6 = 1\n")
subject.writeIPv6
end
end

context "and the configuration is missing from sysctl.conf" do
let(:sysctl_content) { "" }

it "disables IPv6 in the sysctl.conf" do
expect(Yast::SCR).to receive(:Write)
.with(path(".target.string"), /sysctl.conf/, "net.ipv6.conf.all.disable_ipv6 = 1\n")
subject.writeIPv6
end
end

it "disables IPv6 using sysctl" do
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash"), /sysctl -w net.ipv6.conf.all.disable_ipv6=1/)
subject.writeIPv6
end

it "disables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "no")
subject.writeIPv6
end
end
end

0 comments on commit 7bf1060

Please sign in to comment.