Skip to content

Commit

Permalink
Merge pull request #705 from mchf/SLE-15-GA
Browse files Browse the repository at this point in the history
Merged SLE-12-SP4
  • Loading branch information
mchf committed Nov 26, 2018
2 parents d5ef15d + 8bdeb02 commit 1079e9f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 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
- 4.0.45

-------------------------------------------------------------------
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: 4.0.44
Version: 4.0.45
Release: 0
BuildArch: noarch

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

textdomain "network"

Yast.import "Arch"
Yast.import "CWM"
Yast.import "CWMTab"
Yast.import "DNS"
Expand All @@ -57,7 +56,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 @@ -950,20 +948,6 @@ def ValidateAddrIP(key, event)
true
end

# Validator for network masks adresses
# @param key [String] the widget being validated
# @param _event [Hash] 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 key [String] the widget being validated
# @param _event [Hash] the event being handled
Expand Down Expand Up @@ -1541,10 +1525,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 @@ -90,14 +90,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 @@ -107,6 +116,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 1079e9f

Please sign in to comment.