Skip to content

Commit

Permalink
Merge pull request #682 from yast/network_proposal
Browse files Browse the repository at this point in the history
Added new network configuration proposal (fate#326480)
  • Loading branch information
teclator committed Oct 18, 2018
2 parents 637883a + b2d5836 commit 3f90577
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 28 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Oct 16 19:29:30 UTC 2018 - knut.anderssen@suse.com

- Simplified the installation network proposal collecting all the
configured dhcp interfaces in a single entry (fate#326480)
- 4.1.13

-------------------------------------------------------------------
Tue Oct 16 09:02:26 UTC 2018 - mfilka@suse.com

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


Name: yast2-network
Version: 4.1.12
Version: 4.1.13
Release: 0
BuildArch: noarch

Expand Down
2 changes: 1 addition & 1 deletion src/clients/lan_auto.rb
Expand Up @@ -59,7 +59,7 @@ def main
Builtins.y2milestone("Lan autoinst callback: #{@func}")

if @func == "Summary"
@ret = Ops.get_string(Lan.Summary("summary"), 0, "")
@ret = Lan.Summary("summary")
elsif @func == "Reset"
Lan.Import({})
@ret = {}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/clients/network_proposal.rb
Expand Up @@ -24,7 +24,7 @@ def description

def make_proposal(_)
{
"preformatted_proposal" => Yast::Lan.Summary("summary").first,
"preformatted_proposal" => Yast::Lan.Summary("proposal"),
"label_proposal" => [Yast::LanItems.summary("one_line")]
}
end
Expand Down
67 changes: 67 additions & 0 deletions src/lib/network/lan_items_summary.rb
Expand Up @@ -56,6 +56,29 @@ def default
Summary.DevicesList(items)
end

# Generates a summary in RichText format for the configured interfaces
#
# @example
# LanItemsSummary.new.proposal
# => "<ul><li><p>Configured with DHCP: eth0, eth1<br></p></li>" \
# "<li><p>br0 (Bridge)<br>IP address: 192.168.122.60/24" \
# "<br>Bridge Ports: eth2 eth3</p></li></ul>"
#
# @see Summary
# @return [String] summary in RichText
def proposal
items = []

items << "<li>#{dhcp_summary}</li>" unless LanItems.find_dhcp_ifaces.empty?
items << "<li>#{static_summary}</li>" unless LanItems.find_static_ifaces.empty?
items << "<li>#{bridge_summary}</li>" unless bridges.empty?
items << "<li>#{bonding_summary}</li>" unless bonds.empty?

return Summary.NotConfigured if items.empty?

Summary.DevicesList(items)
end

# Generates a one line text summary for the configured interfaces.
#
# @example with one configured interface
Expand Down Expand Up @@ -109,5 +132,49 @@ def ifcfg_protocol(ifcfg)
LanItems.DeviceProtocol(ifcfg)
end
end

# Return a summary of the interfaces configurew with DHCP
#
# @return [String] interfaces configured with DHCP summary
def dhcp_summary
# TRANSLATORS: %s is the list of interfaces configured by DHCP
_("Configured with DHCP: %s") % LanItems.find_dhcp_ifaces.sort.join(", ")
end

# Return a summary of the interfaces configured statically
#
# @return [String] statically configured interfaces summary
def static_summary
# TRANSLATORS: %s is the list of interfaces configured by DHCP
_("Statically configured: %s") % LanItems.find_static_ifaces.sort.join(", ")
end

# Return a summary of the configured bridge interfaces
#
# @return [String] bridge configured interfaces summary
def bridge_summary
_("Bridges: %s") % bridges.map { |n| "#{n} (#{LanItems.bridge_slaves(n).sort.join(", ")})" }
end

# Return a summary of the configured bonding interfaces
#
# @return [String] bonding configured interfaces summary
def bonding_summary
_("Bonds: %s") % bonds.map { |n| "#{n} (#{LanItems.GetBondSlaves(n).sort.join(", ")})" }
end

# Convenience method that obtains the list of bonding configured interfaces
#
# @return [Array<String>] bonding configured interface names
def bonds
LanItems.getNetworkInterfaces("bond").sort
end

# Convenience method that obtains the list of bridge configured interfaces
#
# @return [Array<String>] bridge configured interface names
def bridges
LanItems.getNetworkInterfaces("br").sort
end
end
end
26 changes: 9 additions & 17 deletions src/modules/Lan.rb
Expand Up @@ -794,26 +794,18 @@ def Export
end

# Create a textual summary and a list of unconfigured devices
# @param [String] mode "split": split configured and unconfigured?<br />
# "summary": add resolver and routing symmary,
# "proposal": for proposal, add links for direct config
# @param [String] mode "summary": add resolver and routing summary,
# "proposal": for proposal also with resolver an routing summary
# @return summary of the current configuration
def Summary(mode)
sum = LanItems.BuildLanOverview

# Testing improved summary
if mode == "summary"
Ops.set(
sum,
0,
Ops.add(
Ops.add(Ops.get_string(sum, 0, ""), DNS.Summary),
Routing.Summary
)
)
case mode
when "summary"
"#{LanItems.BuildLanOverview.first}#{DNS.Summary}#{Routing.Summary}"
when "proposal"
"#{LanItems.summary(:proposal)}#{DNS.Summary}#{Routing.Summary}"
else
LanItems.BuildLanOverview.first
end

deep_copy(sum)
end

# Create a textual summary for the general network settings
Expand Down
22 changes: 16 additions & 6 deletions src/modules/LanItems.rb
Expand Up @@ -940,6 +940,15 @@ def find_dhcp_ifaces
end
end

# Find all NICs configured statically
#
# @return [Array<String>] list of NIC names which have a static config
def find_static_ifaces
find_by_sysconfig do |ifcfg|
ifcfg.fetch("BOOTPROTO", "").match(/static/i)
end
end

# Finds all devices which has DHCLIENT_SET_HOSTNAME set to "yes"
#
# @return [Array<String>] list of NIC names which has the option set to "yes"
Expand Down Expand Up @@ -971,14 +980,15 @@ def valid_dhcp_cfg?

# Get list of all configured interfaces
#
# @param type [String] only obtains configured interfaces of the given type
# return [Array] list of strings - interface names (eth0, ...)
# FIXME: rename e.g. to configured_interfaces
def getNetworkInterfaces
def getNetworkInterfaces(type = nil)
configurations = NetworkInterfaces.FilterDevices("netcard")
devtypes = NetworkInterfaces.CardRegex["netcard"].to_s.split("|")
devtypes = type ? [type] : NetworkInterfaces.CardRegex["netcard"].to_s.split("|")

devtypes.inject([]) do |acc, type|
conf = configurations[type].to_h
devtypes.inject([]) do |acc, conf_type|
conf = configurations[conf_type].to_h
acc.concat(conf.keys)
end
end
Expand Down Expand Up @@ -2579,8 +2589,6 @@ def self.publish_variable(name, type)
publish variable: name, type: type
end

private

# Returns a formated string with the interfaces that are part of a bridge
# or of a bond interface.
#
Expand Down Expand Up @@ -2609,6 +2617,8 @@ def enslaved?(ifcfg_name)
false
end

private

# Checks if given lladdr can be written into ifcfg
#
# @param lladdr [String] logical link address, usually MAC address in case
Expand Down
7 changes: 7 additions & 0 deletions test/lan_items_helpers_test.rb
Expand Up @@ -97,6 +97,13 @@
allow(Yast::NetworkInterfaces).to receive(:FilterDevices) { NETCONFIG_ITEMS }
expect(Yast::LanItems.getNetworkInterfaces).to match_array(EXPECTED_INTERFACES)
end

context "when a type is given" do
it "returns the list of known interfaces of the given type" do
allow(Yast::NetworkInterfaces).to receive(:FilterDevices) { NETCONFIG_ITEMS }
expect(Yast::LanItems.getNetworkInterfaces("br")).to eql(["br0"])
end
end
end

describe "LanItemsClass#s390_correct_lladdr" do
Expand Down
27 changes: 26 additions & 1 deletion test/lan_items_summary_test.rb 100644 → 100755
Expand Up @@ -12,7 +12,10 @@
[
{ "BOOTPROTO" => "dhcp" },
{ "BOOTPROTO" => "none" },
{ "IPADDR" => "1.2.3.4", "NETMASK" => "255.255.255.0" }
{ "BOOTPROTO" => "static",
"IPADDR" => "1.2.3.4",
"NETMASK" => "255.255.255.0",
"BRIDGE_PORTS" => "eth1" }
].freeze
end

Expand All @@ -27,9 +30,11 @@
before do
allow(Yast::LanItems).to receive(:Items).and_return(items)
allow(Yast::LanItems).to receive(:IsItemConfigured).and_return(true)
allow(Yast::NetworkInterfaces).to receive(:FilterDevices).with("netcard").and_return("br" => { "br0" => dhcp_maps[2] })
dhcp_maps.each_with_index do |item, index|
allow(Yast::LanItems).to receive(:GetDeviceMap).with(index).and_return(item)
end
allow(subject).to receive(:bridges).and_return(["br0"])
end

describe "#default" do
Expand All @@ -49,6 +54,26 @@
end
end

describe "#proposal" do
it "returns a Richtext summary of the configured interfaces" do
expect(subject.proposal)
.to eql "<ul>" \
"<li>Configured with DHCP: eth0</li>" \
"<li>Statically configured: br0</li>" \
"<li>Bridges: br0 (eth1)</li>" \
"</ul>"
end

it "returns Summary.NotConfigured in case of not configured interfaces" do
allow(Yast::LanItems).to receive(:find_dhcp_ifaces).and_return([])
allow(Yast::LanItems).to receive(:find_static_ifaces).and_return([])
allow(subject).to receive(:bridges).and_return([])
allow(subject).to receive(:bonds).and_return([])

expect(subject.proposal).to eql Yast::Summary.NotConfigured
end
end

describe "#one_line" do
it "returns a plain text summary of the configured interfaces in one line" do
expect(subject.one_line).to eql(MULTIPLE_INTERFACES)
Expand Down
3 changes: 2 additions & 1 deletion test/network_proposal_test.rb 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env rspec
require_relative "test_helper"

require "network/clients/network_proposal"
Expand All @@ -9,7 +10,7 @@
before do
stub_const("Yast::Wizard", double.as_null_object)
allow(Yast::LanItems).to receive(:summary).with("one_line").and_return("one_line_summary")
allow(Yast::Lan).to receive(:Summary).with("summary").and_return(["rich_text_summary", ""])
allow(Yast::Lan).to receive(:Summary).with("proposal").and_return("rich_text_summary")
end

describe "#description" do
Expand Down

0 comments on commit 3f90577

Please sign in to comment.