Skip to content

Commit

Permalink
Moved valid_dhcp_cfg? method into another module
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Nov 23, 2016
1 parent 6eb63f0 commit bd9da93
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/include/network/services/dns.rb
Expand Up @@ -426,7 +426,7 @@ def InitDhcpHostname(_key)
selected = DNS.dhcp_hostname ? ANY_LABEL : NONE_LABEL
items = []

if !DNS.valid_dhcp_cfg?
if !LanItems.valid_dhcp_cfg?
fix_dhclient_warning(hostname_ifaces)

selected = NO_CHANGE_LABEL
Expand Down
10 changes: 0 additions & 10 deletions src/modules/DNS.rb
Expand Up @@ -668,16 +668,6 @@ def create_hostname_link
nil
end

# Checks if system DHCLIENT_SET_HOSTNAME is valid
#
# @return [Boolean]
def valid_dhcp_cfg?
return false if LanItems.find_set_hostname_ifaces.size > 1
return false if !LanItems.find_set_hostname_ifaces.empty? && DNS.dhcp_hostname

true
end

private

def read_hostname_from_install_inf
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Lan.rb
Expand Up @@ -422,7 +422,7 @@ def Read(cache)
return false if Abort()
@initialized = true

fix_dhclient_warning(LanItems.find_set_hostname_ifaces) if @gui && !DNS.valid_dhcp_cfg?
fix_dhclient_warning(LanItems.find_set_hostname_ifaces) if @gui && !LanItems.valid_dhcp_cfg?

Progress.Finish if @gui

Expand Down
10 changes: 10 additions & 0 deletions src/modules/LanItems.rb
Expand Up @@ -935,6 +935,16 @@ def find_set_hostname_ifaces
end
end

# Checks if system DHCLIENT_SET_HOSTNAME is valid
#
# @return [Boolean]
def valid_dhcp_cfg?
return false if LanItems.find_set_hostname_ifaces.size > 1
return false if !LanItems.find_set_hostname_ifaces.empty? && DNS.dhcp_hostname

true
end

# Get list of all configured interfaces
#
# return [Array] list of strings - interface names (eth0, ...)
Expand Down
35 changes: 0 additions & 35 deletions test/dns_test.rb
Expand Up @@ -102,40 +102,5 @@ module Yast
end
end
end

describe "#valid_dhcp_cfg?" do
def mock_dhcp_setup(ifaces, global)
allow(LanItems)
.to receive(:find_set_hostname_ifaces)
.and_return(ifaces)
allow(DNS)
.to receive(:dhcp_hostname)
.and_return(global)
end

it "fails when DHCLIENT_SET_HOSTNAME is set for multiple ifaces" do
mock_dhcp_setup(["eth0", "eth1"], false)

expect(DNS.valid_dhcp_cfg?).to be false
end

it "fails when DHCLIENT_SET_HOSTNAME is set globaly even in an ifcfg" do
mock_dhcp_setup(["eth0"], true)

expect(DNS.valid_dhcp_cfg?).to be false
end

it "succeedes when DHCLIENT_SET_HOSTNAME is set for one iface" do
mock_dhcp_setup(["eth0"], false)

expect(DNS.valid_dhcp_cfg?).to be true
end

it "succeededs when only global DHCLIENT_SET_HOSTNAME is set" do
mock_dhcp_setup([], true)

expect(DNS.valid_dhcp_cfg?).to be true
end
end
end
end
35 changes: 35 additions & 0 deletions test/lan_items_helpers_test.rb
Expand Up @@ -375,4 +375,39 @@ def mock_items(dev_maps)
Yast::LanItems.clear_set_hostname
end
end

describe "LanItems#valid_dhcp_cfg?" do
def mock_dhcp_setup(ifaces, global)
allow(Yast::LanItems)
.to receive(:find_set_hostname_ifaces)
.and_return(ifaces)
allow(Yast::DNS)
.to receive(:dhcp_hostname)
.and_return(global)
end

it "fails when DHCLIENT_SET_HOSTNAME is set for multiple ifaces" do
mock_dhcp_setup(["eth0", "eth1"], false)

expect(Yast::LanItems.valid_dhcp_cfg?).to be false
end

it "fails when DHCLIENT_SET_HOSTNAME is set globaly even in an ifcfg" do
mock_dhcp_setup(["eth0"], true)

expect(Yast::LanItems.valid_dhcp_cfg?).to be false
end

it "succeedes when DHCLIENT_SET_HOSTNAME is set for one iface" do
mock_dhcp_setup(["eth0"], false)

expect(Yast::LanItems.valid_dhcp_cfg?).to be true
end

it "succeededs when only global DHCLIENT_SET_HOSTNAME is set" do
mock_dhcp_setup([], true)

expect(Yast::LanItems.valid_dhcp_cfg?).to be true
end
end
end

0 comments on commit bd9da93

Please sign in to comment.