Skip to content

Commit

Permalink
Merge pull request #950 from mchf/SLE-15-SP1
Browse files Browse the repository at this point in the history
Merged SLE-15-GA
  • Loading branch information
mchf committed Sep 12, 2019
2 parents d5d326d + 7c2b5de commit 40e7c85
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 11 deletions.
12 changes: 12 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,15 @@
-------------------------------------------------------------------
Tue Sep 10 07:40:04 UTC 2019 - Michal Filka <mfilka@suse.com>

- bnc#1149234
- apply udev rule from AY profile according to device's mac
value when permanent_mac is missing in list of the device's
options
- bsc#1133442
- Increased the DHCP timeout when NetworkManager is in use to
its default (45 seconds).
- 4.1.52

-------------------------------------------------------------------
Wed Jul 3 16:40:45 UTC 2019 - Imobach Gonzalez Sosa <igonzalezsosa@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.51
Version: 4.1.52
Release: 0
BuildArch: noarch

Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/edit_nic_name.rb
Expand Up @@ -41,7 +41,7 @@ def initialize
end

if current_item["hwinfo"]
@mac = current_item["hwinfo"]["permanent_mac"]
@mac = LanItems.item_mac(LanItems.current)
@bus_id = current_item["hwinfo"]["busid"]
else
@mac = ""
Expand Down
2 changes: 2 additions & 0 deletions src/lib/network/network_autoyast.rb
Expand Up @@ -340,6 +340,8 @@ def assign_udevs_to_devs(udev_rules)
# Match also parent busid if exist (bsc#1129012)
parent_busid = i["hwinfo"]["parent_busid"] || busid
mac = i["hwinfo"]["permanent_mac"]
# use mac if permanent_mac is missing (bsc#1149234)
mac = i["hwinfo"]["mac"] if mac.nil? || mac.empty?

[busid, parent_busid, mac].any? { |v| v.casecmp(key).zero? }
end
Expand Down
4 changes: 3 additions & 1 deletion src/modules/Lan.rb
Expand Up @@ -451,6 +451,8 @@ def writeIPv6
nil
end

NM_DHCP_TIMEOUT = 45

# Update the SCR according to network settings
# @return true on success
def Write(gui: true)
Expand Down Expand Up @@ -584,7 +586,7 @@ def Write(gui: true)

if NetworkService.is_network_manager
network = false
timeout = 15
timeout = NM_DHCP_TIMEOUT
while Ops.greater_than(timeout, 0)
if NetworkService.isNetworkRunning
network = true
Expand Down
23 changes: 17 additions & 6 deletions src/modules/LanItems.rb
Expand Up @@ -369,6 +369,17 @@ def SetItemUdevRule(itemId, rule)
GetLanItem(itemId)["udev"]["net"] = rule
end

# Returns item's mac
#
# hwinfo[permanent_mac] is prefered if exists. hwinfo[mac] is used otherwise
#
# @param item_id [Integer] a key for {#Items}
# @return [<String>, nil] mac address or nil
def item_mac(item_id)
hwinfo = GetLanItem(item_id).fetch("hwinfo", {})
hwinfo.fetch("permanent_mac", hwinfo.fetch("mac", nil))
end

# Inits item's udev rule to a default one if none is present
#
# @param item_id [Integer] a key for {#Items}
Expand All @@ -377,7 +388,7 @@ def InitItemUdevRule(item_id)
udev = GetItemUdevRule(item_id)
return udev if !udev.empty?

default_mac = GetLanItem(item_id).fetch("hwinfo", {})["permanent_mac"]
default_mac = item_mac(item_id)
raise ArgumentError, "Cannot propose udev rule - NIC not present" if !default_mac

default_udev = GetDefaultUdevRule(
Expand Down Expand Up @@ -437,7 +448,7 @@ def getUdevFallback
if IsEmpty(udev_rules)
udev_rules = GetDefaultUdevRule(
GetCurrentName(),
Ops.get_string(getCurrentItem, ["hwinfo", "permanent_mac"], "")
item_mac(@current) || ""
)
Builtins.y2milestone(
"No Udev rules found, creating default: %1",
Expand Down Expand Up @@ -492,7 +503,7 @@ def update_item_udev_rule!(based_on = :mac)
LanItems.ReplaceItemUdev(
"KERNELS",
"ATTR{address}",
LanItems.getCurrentItem.fetch("hwinfo", {}).fetch("permanent_mac", "")
item_mac(@current) || ""
)
when :bus_id
# Update or insert the dev_port if the sysfs dev_port attribute is present
Expand Down Expand Up @@ -1087,7 +1098,7 @@ def getDeviceName(oldname)

hardware.each do |hw|
hw_dev_name = hw["dev_name"] || ""
hw_dev_mac = hw["permanent_mac"] || ""
hw_dev_mac = hw["permanent_mac"] || hw["mac"] || ""
hw_dev_busid = hw["busid"] || ""

case oldname
Expand Down Expand Up @@ -1557,11 +1568,11 @@ def BuildLanOverview
conn = HTML.Bold(format("(%s)", _("Not connected"))) if !item_hwinfo["link"]
conn = HTML.Bold(format("(%s)", _("No hwinfo"))) if item_hwinfo.empty?

mac_dev = HTML.Bold("MAC : ") + item_hwinfo["permanent_mac"].to_s + "<br>"
mac_dev = HTML.Bold("MAC : ") + item_mac(key).to_s + "<br>"
bus_id = HTML.Bold("BusID : ") + item_hwinfo["busid"].to_s + "<br>"
physical_port_id = HTML.Bold("PhysicalPortID : ") + physical_port_id(ifcfg_name) + "<br>"

rich << " " << conn << "<br>" << mac_dev if IsNotEmpty(item_hwinfo["permanent_mac"])
rich << " " << conn << "<br>" << mac_dev if IsNotEmpty(item_mac(key))
rich << bus_id if IsNotEmpty(item_hwinfo["busid"])
rich << physical_port_id if physical_port_id?(ifcfg_name)
# display it only if we need it, don't duplicate "ifcfg_name" above
Expand Down
5 changes: 5 additions & 0 deletions test/network_autoconfiguration_test.rb
Expand Up @@ -222,6 +222,11 @@ def probe_netcard_factory(num)
context "when the proposal is required" do
let(:proposal) { true }

after(:each) do
# some methods might have sideeffects - clen them :-/
Yast::NetworkInterfaces.Devices.reject! { |k, _| k == "br" }
end

it "creates the virtulization proposal config" do
expect(Yast::Lan).to receive(:ProposeVirtualized).and_call_original
expect { instance.configure_virtuals }.to change { Yast::NetworkInterfaces.Devices.keys.size }.from(1).to(2)
Expand Down
37 changes: 35 additions & 2 deletions test/network_autoyast_test.rb
Expand Up @@ -433,6 +433,26 @@ def mock_lan_item(renamed_to: nil)
]
end

let(:udev_mac_rules) do
[
{
"name" => "eth1",
"rule" => "ATTR{address}",
"value" => "00:00:00:00:00:00"
},
{
"name" => "eth3",
"rule" => "ATTR{address}",
"value" => "00:00:00:00:00:01"
},
{
"name" => "eth0",
"rule" => "ATTR{address}",
"value" => "00:00:00:00:00:02"
}
]
end

let(:persistent_udevs) do
{
"eth0" => [
Expand Down Expand Up @@ -468,7 +488,7 @@ def mock_lan_item(renamed_to: nil)
"dev_name" => "eth2",
"busid" => "0000:01:00.2",
"mac" => "00:00:00:00:00:02",
"permanent_mac" => "00:00:00:00:00:02"
"permanent_mac" => ""
}
]
end
Expand All @@ -488,7 +508,6 @@ def mock_lan_item(renamed_to: nil)
.and_return(persistent_udevs)

Yast::LanItems.Read
Yast::LanItems.Items[3] = { "ifcfg" => "eth3" }
end

# see bnc#1056109
Expand All @@ -503,6 +522,8 @@ def mock_lan_item(renamed_to: nil)
# applying of the ruleset we could end with new nameset e.g. <eth2, eth0, eth0>
# which obviously leads to misconfiguration of the system
it "applies rules so, that names remain unique" do
Yast::LanItems.Items[3] = { "ifcfg" => "eth3" }

network_autoyast.send(:assign_udevs_to_devs, udev_rules)

lan_items = Yast::LanItems
Expand All @@ -513,6 +534,18 @@ def mock_lan_item(renamed_to: nil)
# check if device names are unique
expect(names.sort).to eql ["eth0", "eth1", "eth2", "eth3"]
end

it "matches devices according to permanent mac or mac field when first one is missing" do
network_autoyast.send(:assign_udevs_to_devs, udev_mac_rules)

lan_items = Yast::LanItems
names = lan_items.Items.keys.map do |i|
lan_items.renamed?(i) ? lan_items.renamed_to(i) : lan_items.GetDeviceName(i)
end

# check if device names are unique
expect(names.sort).to eql ["eth0", "eth1", "eth3"]
end
end
end

Expand Down

0 comments on commit 40e7c85

Please sign in to comment.