Hello community, here is the log from the commit of package yast2-network for openSUSE:Factory checked in at 2018-01-28 00:37:35 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yast2-network (Old) and /work/SRC/openSUSE:Factory/.yast2-network.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "yast2-network" Sun Jan 28 00:37:35 2018 rev:378 rq:569453 version:4.0.14 Changes: -------- --- /work/SRC/openSUSE:Factory/yast2-network/yast2-network.changes 2018-01-17 21:42:19.168115397 +0100 +++ /work/SRC/openSUSE:Factory/.yast2-network.new/yast2-network.changes 2018-01-28 00:37:37.374556839 +0100 @@ -1,0 +2,8 @@ +Wed Jan 24 16:03:20 UTC 2018 - mfilka@suse.com + +- bnc#1056109 + - improved device name collision recognition when applying device + renaming according to the AY profile +- 4.0.14 + +------------------------------------------------------------------- Old: ---- yast2-network-4.0.13.tar.bz2 New: ---- yast2-network-4.0.14.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yast2-network.spec ++++++ --- /var/tmp/diff_new_pack.YrDWf9/_old 2018-01-28 00:37:38.002527585 +0100 +++ /var/tmp/diff_new_pack.YrDWf9/_new 2018-01-28 00:37:38.006527399 +0100 @@ -1,7 +1,7 @@ # # spec file for package yast2-network # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.0.13 +Version: 4.0.14 Release: 0 BuildArch: noarch ++++++ yast2-network-4.0.13.tar.bz2 -> yast2-network-4.0.14.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/package/yast2-network.changes new/yast2-network-4.0.14/package/yast2-network.changes --- old/yast2-network-4.0.13/package/yast2-network.changes 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/package/yast2-network.changes 2018-01-25 10:37:34.000000000 +0100 @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Wed Jan 24 16:03:20 UTC 2018 - mfilka@suse.com + +- bnc#1056109 + - improved device name collision recognition when applying device + renaming according to the AY profile +- 4.0.14 + +------------------------------------------------------------------- Mon Dec 11 11:29:18 UTC 2017 - knut.anderssen@suse.com - Remote: reimplemented the module dialogs and clients under diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/package/yast2-network.spec new/yast2-network-4.0.14/package/yast2-network.spec --- old/yast2-network-4.0.13/package/yast2-network.spec 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/package/yast2-network.spec 2018-01-25 10:37:34.000000000 +0100 @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.0.13 +Version: 4.0.14 Release: 0 BuildArch: noarch diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/src/lib/network/network_autoyast.rb new/yast2-network-4.0.14/src/lib/network/network_autoyast.rb --- old/yast2-network-4.0.13/src/lib/network/network_autoyast.rb 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/src/lib/network/network_autoyast.rb 2018-01-25 10:37:34.000000000 +0100 @@ -292,6 +292,7 @@ # selecting according device name is unreliable (selects only in between configured devices) LanItems.current = item + LanItems.InitItemUdevRule(item) if !attr.nil? && !key.nil? # find out what attribude is currently used for setting device name and @@ -332,16 +333,11 @@ end next if !matching_item - name_from = LanItems.GetDeviceName(item) + name_from = item_name(item) log.info("Matching device found - renaming <#{name_from}> -> <#{name_to}>") - # find rule in collision - colliding_item, _item_map = LanItems.Items.find do |i, _| - LanItems.GetDeviceName(i) == name_to - end - # rename item in collision - rename_lan_item(colliding_item, name_from) + rename_lan_item(colliding_item(name_to), name_from) # rename matching item rename_lan_item(item, name_to, attr, key) @@ -368,5 +364,24 @@ true end + + # Returns items id, taking into account that item could be renamed + # + # @return [String] device name + def item_name(item_id) + LanItems.renamed?(item_id) ? LanItems.renamed_to(item_id) : LanItems.GetDeviceName(item_id) + end + + # Finds a LanItem which name is in collision to the provided name + # + # @param [String] a device name (eth0, ...) + # @return [Integer] item id (see LanItems::Items) + def colliding_item(name) + colliding_item, _item_map = LanItems.Items.find do |i, _| + name == item_name(i) + end + + colliding_item + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/src/lib/y2remote/widgets/remote.rb new/yast2-network-4.0.14/src/lib/y2remote/widgets/remote.rb --- old/yast2-network-4.0.13/src/lib/y2remote/widgets/remote.rb 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/src/lib/y2remote/widgets/remote.rb 2018-01-25 10:37:34.000000000 +0100 @@ -189,7 +189,7 @@ end def help - @cwm_interfaces["help"] + @cwm_interfaces["help"] || "" end def handle(event) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/src/modules/LanItems.rb new/yast2-network-4.0.14/src/modules/LanItems.rb --- old/yast2-network-4.0.13/src/modules/LanItems.rb 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/src/modules/LanItems.rb 2018-01-25 10:37:34.000000000 +0100 @@ -344,6 +344,34 @@ Ops.get_list(GetLanItem(itemId), ["udev", "net"], []) end + # Sets udev rule for given item + # + # @param itemId [Integer] a key for {#Items} + # @param rule [String] an udev rule + def SetItemUdevRule(itemId, rule) + GetLanItem(itemId)["udev"]["net"] = rule + end + + # Inits item's udev rule to a default one if none is present + # + # @param itemId [Integer] a key for {#Items} + # @return [String] item's udev rule + def InitItemUdevRule(item_id) + udev = GetItemUdevRule(item_id) + return udev if !udev.empty? + + default_mac = GetLanItem(item_id).fetch("hwinfo", {})["mac"] + raise ArgumentError, "Cannot propose udev rule - NIC not present" if !default_mac + + default_udev = GetDefaultUdevRule( + GetDeviceName(item_id), + default_mac + ) + SetItemUdevRule(item_id, default_udev) + + default_udev + end + def ReadUdevDriverRules Builtins.y2milestone("Reading udev rules ...") @udev_net_rules = Convert.convert( @@ -560,7 +588,7 @@ # # @param item_id [Integer] a key for {#Items} def renamed_to(item_id) - @Items[item_id]["renamed_to"] + Items()[item_id]["renamed_to"] end def current_renamed_to @@ -571,7 +599,7 @@ # # @param item_id [Integer] a key for {#Items} def renamed?(item_id) - return false if !LanItems.Items[item_id].key?("renamed_to") + return false if !renamed_to(item_id) renamed_to(item_id) != GetDeviceName(item_id) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/test/lan_items_helpers_test.rb new/yast2-network-4.0.14/test/lan_items_helpers_test.rb --- old/yast2-network-4.0.13/test/lan_items_helpers_test.rb 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/test/lan_items_helpers_test.rb 2018-01-25 10:37:34.000000000 +0100 @@ -125,6 +125,50 @@ end end +describe "LanItems#InitItemUdev" do + def udev_rule(mac, name) + [ + "SUBSYSTEM==\"net\"", + "ACTION==\"add\"", + "DRIVERS==\"?*\"", + "ATTR{address}==\"#{mac}\"", + "ATTR{type}==\"1\"", + "NAME=\"#{name}\"" + ] + end + + before(:each) do + allow(Yast::LanItems) + .to receive(:Items) + .and_return( + 0 => { + "ifcfg" => "eth0", + "udev" => { + "net" => udev_rule("24:be:05:ce:1e:91", "eth0") + } + }, + 1 => { + "hwinfo" => { + "mac" => "00:00:00:00:00:01", + "dev_name" => "eth1" + }, + # always exists + "udev" => { + "net" => [] + } + } + ) + end + + it "returns existing udev rule if there is any already" do + expect(Yast::LanItems.InitItemUdevRule(0)).to eql udev_rule("24:be:05:ce:1e:91", "eth0") + end + + it "creates new udev rule if none is present" do + expect(Yast::LanItems.InitItemUdevRule(1)).to eql udev_rule("00:00:00:00:00:01", "eth1") + end +end + describe "LanItems#GetItemUdev" do def check_GetItemUdev(key, expected_value) expect(Yast::LanItems.GetItemUdev(key)).to eql expected_value diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.0.13/test/network_autoyast_test.rb new/yast2-network-4.0.14/test/network_autoyast_test.rb --- old/yast2-network-4.0.13/test/network_autoyast_test.rb 2017-12-11 16:57:37.000000000 +0100 +++ new/yast2-network-4.0.14/test/network_autoyast_test.rb 2018-01-25 10:37:34.000000000 +0100 @@ -336,7 +336,7 @@ before(:each) do allow(Yast::LanItems) .to receive(:Items) - .and_return(0 => { "ifcfg" => "eth0" }) + .and_return(0 => { "ifcfg" => "eth0", "udev" => { "net" => ["ATTR{address}==\"24:be:05:ce:1e:91\"", "KERNEL==\"eth*\"", "NAME=\"eth0\""] } }) end context "valid arguments given" do @@ -389,4 +389,154 @@ end end end + + context "When creating udev rules based on the AY profile" do + def mock_lan_item(renamed_to: nil) + allow(Yast::LanItems) + .to receive(:Items) + .and_return( + 0 => { + "ifcfg" => "eth0", + "renamed_to" => renamed_to, + "udev" => { + "net" => [ + "ATTR{address}==\"24:be:05:ce:1e:91\"", + "NAME=\"#{renamed_to}\"" + ] + } + } + ) + end + + describe "#item_name" do + it "returns old name when the device has not been renamed" do + mock_lan_item + + expect(network_autoyast.send(:item_name, 0)).to eql "eth0" + end + + it "returns new name when the device has been renamed" do + new_name = "new1" + mock_lan_item(renamed_to: new_name) + + expect(network_autoyast.send(:item_name, 0)).to eql new_name + end + end + + describe "#colliding_item" do + it "returns nothing if no collision was found" do + mock_lan_item + + expect(network_autoyast.send(:colliding_item, "enp0s3")).to be nil + end + + it "returns device name which is in collision" do + mock_lan_item + + expect(network_autoyast.send(:colliding_item, "eth0")).to be 0 + end + + it "returns device name when the device was already renamed before and we new name is in collision" do + mock_lan_item(renamed_to: "enp0s3") + + expect(network_autoyast.send(:colliding_item, "enp0s3")).to be 0 + end + end + + describe "#assign_udevs_to_devs" do + Yast.import "LanItems" + + let(:udev_rules) do + [ + { + "name" => "eth1", + "rule" => "KERNELS", + "value" => "0000:01:00.0" + }, + { + "name" => "eth0", + "rule" => "KERNELS", + "value" => "0000:01:00.2" + } + ] + end + + let(:persistent_udevs) do + { + "eth0" => [ + "KERNELS==\"0000:01:00.0\"", + "NAME=eth0" + ], + "eth1" => [ + "KERNELS==\"0000:01:00.1\"", + "NAME=eth1" + ], + "eth2" => [ + "KERNELS==\"0000:01:00.2\"", + "NAME=eth2" + ] + } + end + + let(:hw_netcard) do + [ + { + "dev_name" => "eth0", + "busid" => "0000:01:00.0", + "mac" => "00:00:00:00:00:00" + }, + { + "dev_name" => "eth1", + "busid" => "0000:01:00.1", + "mac" => "00:00:00:00:00:01" + }, + { + "dev_name" => "eth2", + "busid" => "0000:01:00.2", + "mac" => "00:00:00:00:00:02" + } + ] + end + + before(:each) do + allow(Yast::LanItems) + .to receive(:ReadHardware) + .with("netcard") + .and_return(hw_netcard) + allow(Yast::NetworkInterfaces) + .to receive(:Read) + .and_return(true) + # respective agent is not able to change scr root + allow(Yast::SCR) + .to receive(:Read) + .with(path(".udev_persistent.net")) + .and_return(persistent_udevs) + + Yast::LanItems.Read + end + + # see bnc#1056109 + # - basically dev_name is renamed_to || ifcfg || hwinfo.devname for purposes + # of this test (ifcfg is name distinguished from sysconfig configuration, + # hwinfo.devname is name assigned by kernel during device initialization and + # renamed_to is new device name assigned by user when asking for device renaming + # - updating udev rules) + # + # - when we have devices <eth0, eth1, eth2> and ruleset defined in AY profile + # which renames these devices it could, before the fix, happen that after + # 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 + network_autoyast.send(:assign_udevs_to_devs, udev_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", "eth2"] + end + end + end end