Skip to content

Commit

Permalink
Merge branch 'SLE-12-SP3' into SLE-12-SP4
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Nov 26, 2018
2 parents 578aa93 + c4e1136 commit 44ec5a2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 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 @@
-------------------------------------------------------------------
Mon Nov 26 09:28:29 UTC 2018 - mfilka@suse.com

- bnc#709176
- keep original hostnames untouched in /etc/hosts when only IP
changed
- 3.4.1

-------------------------------------------------------------------
Thu Nov 22 11:54:59 UTC 2018 - mfilka@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: 3.4.0
Version: 3.4.1
Release: 0
BuildArch: noarch

Expand Down
40 changes: 13 additions & 27 deletions src/include/network/lan/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def initialize_network_lan_address(include_target)

textdomain "network"

Yast.import "Arch"
Yast.import "CWM"
Yast.import "CWMTab"
Yast.import "DNS"
Expand All @@ -53,7 +52,6 @@ def initialize_network_lan_address(include_target)
Yast.import "String"
Yast.import "SuSEFirewall4Network"
Yast.import "Wizard"
Yast.import "NetworkService"
Yast.import "Map"

Yast.include include_target, "network/summary.rb"
Expand Down Expand Up @@ -395,12 +393,6 @@ def initialize_network_lan_address(include_target)
)
end

# obsoleted by GetDefaultsForHW
# @return `next
def ChangeDefaults
:next
end

# `RadioButtonGroup uses CurrentButton instead of Value, grrr
# @param [String] key widget id
# @return what property to ask for to get the widget value
Expand Down Expand Up @@ -792,8 +784,6 @@ def enableDisableBootProto(current)
# Group called FOO has buttons FOO_bar FOO_qux and values bar qux
# @param [String] key id of the widget
def initBootProto(_key)
# if (LanItems::type=="br") UI::ReplaceWidget(`rp, `Empty());
# else
if LanItems.type != "eth"
UI.ReplaceWidget(
:rp,
Expand Down Expand Up @@ -992,20 +982,6 @@ def ValidateAddrIP(key, event)
true
end

# Validator for network masks adresses
# @param [String] key the widget being validated
# @param [Hash] event the event being handled
# @return whether valid
def ValidateNetmask(key, _event)
# TODO: general CWM improvement idea: validate and save only nondisabled
# widgets
if UI.QueryWidget(:bootproto, :CurrentButton) == :static
ipa = Convert.to_string(UI.QueryWidget(Id(key), :Value))
return Netmask.Check(ipa)
end
true
end

# Validator for ifcfg names
# @param [String] key the widget being validated
# @param [Hash] event the event being handled
Expand Down Expand Up @@ -1632,10 +1608,20 @@ def update_hostname(ipaddr, hostname)

return if !(ip_changed || hostname_changed || hostname.empty?)

log.info("Dropping record for #{LanItems.ipaddr} from /etc/hosts")

# store old names, remove the record
names = Host.names(LanItems.ipaddr).first
Host.remove_ip(LanItems.ipaddr)
Host.Update(initial_hostname, hostname, ipaddr) if !hostname.empty?

if ip_changed && !hostname_changed
log.info("Dropping record for #{LanItems.ipaddr} from /etc/hosts")

Host.add_name(ipaddr, names)
end
if !hostname.empty? && hostname_changed
log.info("Updating cannonical name for #{LanItems.ipaddr} in /etc/hosts")

Host.Update(initial_hostname, hostname, ipaddr)
end

nil
end
Expand Down
3 changes: 2 additions & 1 deletion src/include/network/lan/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def initialize_network_lan_help(_include_target)
_(
"<p>For <b>Static Address Setup</b> enter the static IP address for your computer (for example: <tt>192.168.100.99</tt>) and\n" \
"the network mask (usually <tt>255.255.255.0</tt> or just length of prefix <tt>/24</tt>).Optionally, you can enter\n" \
"a fully qualified hostname for this IP address. The hostname will be written to <tt>/etc/hosts</tt>.</p>\n"
"a fully qualified hostname for this IP address. The hostname will be written to <tt>/etc/hosts</tt> as canonical name.</p>\n" \
"YaST2 will also create aliases from the canonical name automatically.\n"
) +
# Address dialog help 8/8
_(
Expand Down
20 changes: 19 additions & 1 deletion test/address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,23 @@ def initialize
let(:initial_hostname) { "initial.hostname.com" }
let(:new_hostname) { "new.hostname.com" }

it "drops old /etc/hosts record if hostname was changed" do
before(:each) do
allow(Yast::LanItems)
.to receive(:ipaddr)
.and_return(ip)
allow(subject)
.to receive(:initial_hostname)
.and_return(initial_hostname)
allow(Yast::Host)
.to receive(:names)
.and_call_original
allow(Yast::Host)
.to receive(:names)
.with(ip)
.and_return(["#{initial_hostname} custom-name"])
end

it "drops old /etc/hosts record if hostname was changed" do
expect(Yast::Host)
.to receive(:remove_ip)
.with(ip)
Expand All @@ -150,6 +159,15 @@ def initialize

subject.send(:update_hostname, ip, new_hostname)
end

it "keeps names untouched when only the ip was changed" do
new_ip = "2.2.2.2"

original_names = Yast::Host.names(ip)
subject.send(:update_hostname, new_ip, initial_hostname)

expect(Yast::Host.names(new_ip)).to eql original_names
end
end

end

0 comments on commit 44ec5a2

Please sign in to comment.