Skip to content

Commit

Permalink
Changes based on CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Feb 7, 2020
1 parent e162801 commit 7dedd62
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/include/network/services/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ def InitDhcpHostname(_key)
Item(Id(:any), _("yes: any"), dhcp_hostname == :any)
]

config = Yast::Lan.yast_config
iface_names = config.connections.to_a.select { |c| c.bootproto.dhcp? }.map(&:interface)
iface_names = config.connections.to_a.select(&:dhcp?).map(&:interface)
items += iface_names.map do |iface|
# translators: label is in form yes: <device name>
Item(Id(iface), format(_("yes: %s"), iface), dhcp_hostname == iface)
Expand Down Expand Up @@ -631,13 +630,17 @@ def DNSMainDialog(_standalone)
ret
end

def config
Yast::Lan.yast_config
end

# Checks if any interface is configured to use DHCP
#
# @return [Boolean] true when an interface uses DHCP config
def dhcp?
config = Yast::Lan.yast_config
return false unless config&.connections

!!config&.connections&.any? { |c| c.bootproto&.dhcp? }
config.connections.any?(&:dhcp?)
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/connection_config/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def find_master(configs)
end
end

def dhcp?
return false unless bootproto

bootproto.dhcp?
end

private

def replace_ifplugd?
Expand Down
5 changes: 3 additions & 2 deletions src/lib/y2network/presenters/dns_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def text
private

def dhcp_hostname?
return false unless config.connections.any? { |c| c.bootproto&.dhcp? }
return false unless hostname.dhcp_hostname
return false unless config.connections.any?(&:dhcp?)

hostname.dhcp_hostname && hostname.dhcp_hostname != :none
hostname.dhcp_hostname != :none
end

def add_hostname(summary)
Expand Down
6 changes: 4 additions & 2 deletions test/y2network/presenters/dns_summary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
end

let(:config) do
Y2Network::Config.new(interfaces: interfaces, connections: connections,
source: :testing, hostname: hostname, dns: dns)
Y2Network::Config.new(
interfaces: interfaces, connections: connections,
source: :testing, hostname: hostname, dns: dns
)
end

let(:eth0) do
Expand Down

0 comments on commit 7dedd62

Please sign in to comment.