Skip to content

Commit

Permalink
Merge pull request #566 from teclator/merge_SLE-12-SP3
Browse files Browse the repository at this point in the history
Merge SLE-12-Sp3
  • Loading branch information
teclator committed Sep 27, 2017
2 parents 273c8f3 + 87b4f80 commit 3603748
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 18 deletions.
10 changes: 10 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Tue Sep 26 12:44:47 UTC 2017 - knut.anderssen@suse.com

- Preload the global DHCLIENT_SET_HOSTNAME option based on linuxrc
sethostname option if given or based in control file default if
not. (bsc#1054933)
- Do not override the configuration with the default defined in
the control file at the end of the first stage (bsc#1056633)
- 4.0.0

-------------------------------------------------------------------
Wed Aug 30 14:14:08 UTC 2017 - knut.anderssen@suse.com

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


Name: yast2-network
Version: 3.3.12
Version: 4.0.0
Release: 0
BuildArch: noarch

Expand Down
15 changes: 9 additions & 6 deletions src/include/network/services/dns.rb
Expand Up @@ -118,11 +118,7 @@ def initialize_network_services_dns(include_target)
"custom_widget" => HBox(
Label(_("Set Hostname via DHCP")),
HSpacing(2),
ComboBox(
Id("DHCP_HOSTNAME"),
"",
[]
),
ReplacePoint(Id("dhcp_hostname_method"), Empty()),
ReplacePoint(Id("dh_host_text"), Empty())
),
"init" => fun_ref(method(:InitDhcpHostname), "void (string)"),
Expand Down Expand Up @@ -445,7 +441,14 @@ def InitDhcpHostname(_key)
Item(Id(iface), format(_("yes: %s"), iface), iface == selected)
end

UI.ChangeWidget(Id("DHCP_HOSTNAME"), :Items, items)
UI.ReplaceWidget(
Id("dhcp_hostname_method"),
ComboBox(
Id("DHCP_HOSTNAME"),
"",
items
)
)

log.info("InitDhcpHostname: preselected item = #{selected}")

Expand Down
43 changes: 42 additions & 1 deletion src/lib/network/clients/inst_setup_dhcp.rb
@@ -1,12 +1,17 @@
require "network/network_autoconfiguration"

Yast.import "Linuxrc"
Yast.import "DNS"

module Yast
class SetupDhcp
include Singleton
include Logger

def main
nac = Yast::NetworkAutoconfiguration.instance
nac = NetworkAutoconfiguration.instance
set_dhcp_hostname! if Stage.initial

if !nac.any_iface_active?
nac.configure_dhcp
else
Expand All @@ -17,5 +22,41 @@ def main
# warning: possibly useless use of a literal in void context
:next
end

# Check if set of DHCLIENT_SET_HOSTNAME in /etc/sysconfig/network/dhcp has
# been disable by linuxrc cmdline
#
# @return [Boolean] false if sethostname=0; true otherwise
def set_dhcp_hostname?
set_hostname = Linuxrc.InstallInf("SetHostname")
log.info("SetHostname: #{set_hostname}")
set_hostname != "0"
end

# Write the DHCLIENT_SET_HOSTNAME in /etc/sysconfig/network/dhcp based on
# linuxrc sethostname cmdline option if provided or the default value
# defined in the control file if not.
def set_dhcp_hostname!
DNS.dhcp_hostname =
set_hostname_used? ? set_dhcp_hostname? : DNS.default_dhcp_hostname

log.info("Write dhcp hostname default: #{DNS.dhcp_hostname}")
SCR.Write(
Yast::Path.new(".sysconfig.network.dhcp.DHCLIENT_SET_HOSTNAME"),
DNS.dhcp_hostname ? "yes" : "no"
)
# Flush cache
SCR.Write(
Yast::Path.new(".sysconfig.network.dhcp"),
nil
)
end

# Check whether the linuxrc sethostname option has been used or not
#
# @return [Boolean] true if sethosname linuxrc cmdline option was given
def set_hostname_used?
Linuxrc.InstallInf("SetHostnameUsed") == "1"
end
end
end
5 changes: 0 additions & 5 deletions src/lib/network/network_autoconfiguration.rb
Expand Up @@ -88,11 +88,6 @@ def configure_dns
DNS.Read # handles NetworkConfig too
DNS.ProposeHostname # generate random hostname, if none known so far

# FIXME: after SLE12: DNS.default_dhcp_hostname should be private (setting
# default values is not something for an API), but that would need some
# refactoring of this part.
DNS.dhcp_hostname = DNS.default_dhcp_hostname

# get default value, from control.xml
DNS.write_hostname = DNS.DefaultWriteHostname

Expand Down
97 changes: 92 additions & 5 deletions test/inst_setup_dhcp_test.rb
Expand Up @@ -5,9 +5,7 @@
require "network/clients/inst_setup_dhcp"

describe Yast::SetupDhcp do
before do
allow(Yast::NetworkInterfaces).to receive(:adapt_old_config!)
end
subject { Yast::SetupDhcp.instance }

describe "#main" do

Expand All @@ -16,15 +14,104 @@
.to receive(:any_iface_active?)
.and_return(true)

expect(Yast::SetupDhcp.instance.main).to eql :next
expect(subject.main).to eql :next
end

it "returns :next when autoconfiguration is not performed" do
allow(Yast::NetworkAutoconfiguration)
.to receive(:any_iface_active?)
.and_return(false)

expect(Yast::SetupDhcp.instance.main).to eql :next
expect(subject.main).to eql :next
end

it "runs network dhcp autoconfiguration if no active interfaces" do
allow(Yast::NetworkAutoconfiguration)
.to receive(:any_iface_active?)
.and_return(false)
expect(Yast::NetworkAutoconfiguration.instance)
.to receive(:configure_dhcp)

subject.main
end

context "in the initial Stage" do
it "writes DHCLIENT_SET_HOSTNAME in /etc/sysconfig/network/dhcp" do
expect(Yast::Stage).to receive(:initial).and_return(true)
expect(subject).to receive(:set_dhcp_hostname!)

subject.main
end
end
end

describe "#set_dhcp_hostname!" do
let(:dhclient_set_hostname_path) do
Yast::Path.new(".sysconfig.network.dhcp.DHCLIENT_SET_HOSTNAME")
end

before do
allow(Yast::SCR).to receive(:Write)
end

context "when the linurc sethostname option has been used" do
before do
allow(subject).to receive(:set_hostname_used?).and_return(true)
end

it "sets DNS.dhcp_hostname according to the linuxrc sethosname value" do
expect(subject).to receive(:set_dhcp_hostname?).and_return(false)
expect(Yast::DNS).to receive(:dhcp_hostname=).with(false)

subject.set_dhcp_hostname!
end
end

context "when the linurc sethostname option has not been used" do
before do
allow(subject).to receive(:set_hostname_used?).and_return(false)
end

it "sets DNS.dhcp_hostname according to DNS.default_dhcp_hostname" do
expect(subject).to_not receive(:set_dhcp_hostname?)
expect(Yast::DNS).to receive(:default_dhcp_hostname).and_return(true)
expect(Yast::DNS).to receive(:dhcp_hostname=).with(true)

subject.set_dhcp_hostname!
end
end

context "once initialized DNS.dhcp_hostname" do
it "writes global DHCLIENT_SET_HOSTNAME in /etc/sysconfig/network/dhcp with it" do
allow(Yast::DNS).to receive(:dhcp_hostname=)
allow(Yast::DNS).to receive(:dhcp_hostname).and_return(false)
expect(Yast::SCR).to receive(:Write).with(dhclient_set_hostname_path, "no")

subject.set_dhcp_hostname!
end
end
end

describe "set_dhcp_hostname?" do
before do
allow(Yast::Linuxrc).to receive(:InstallInf)
.with("SetHostname").and_return(set_hostname)
end

context "when dhcp hostname has not been disabled by linuxrc" do
let(:set_hostname) { "1" }

it "returns true" do
expect(subject.set_dhcp_hostname?).to eql(true)
end
end

context "when dhcp hostname has been disabled by linuxrc" do
let(:set_hostname) { "0" }

it "returns false" do
expect(subject.set_dhcp_hostname?).to eql(false)
end
end
end
end

0 comments on commit 3603748

Please sign in to comment.