diff --git a/package/yast2-network.changes b/package/yast2-network.changes index 72b970494..489fd55a8 100644 --- a/package/yast2-network.changes +++ b/package/yast2-network.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon Apr 12 12:05:02 UTC 2021 - Knut Anderssen + +- Do not require a MAC address when activating a qeth device + with layer2 support (bsc#1184474). +- 4.3.65 + ------------------------------------------------------------------- Wed Apr 7 11:27:26 UTC 2021 - Imobach Gonzalez Sosa diff --git a/package/yast2-network.spec b/package/yast2-network.spec index 61340a99b..ca98393be 100644 --- a/package/yast2-network.spec +++ b/package/yast2-network.spec @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.3.64 +Version: 4.3.65 Release: 0 Summary: YaST2 - Network Configuration License: GPL-2.0-only diff --git a/src/lib/y2network/widgets/s390_common.rb b/src/lib/y2network/widgets/s390_common.rb index 73dbfe2c4..e8d661cd9 100644 --- a/src/lib/y2network/widgets/s390_common.rb +++ b/src/lib/y2network/widgets/s390_common.rb @@ -244,15 +244,40 @@ def handle(event) nil end + # @see CWM::AbstractWidget def validate - return true if !layer2? || valid_mac?(mac_address_widget.value) + return true if !layer2? || !lladdress_for(mac_address_widget.value) + + unless valid_mac?(mac_address_widget.value) + report_mac_error + + return false + end + + use_selected_mac? + end - report_mac_error - false + # @see CWM::AbstractWidget + def store + @settings.layer2 = layer2? + @settings.lladdress = layer2? ? lladdress_for(mac_address_widget.value) : nil end private + def use_selected_mac? + Yast::Popup.YesNoHeadline( + Yast::Label.WarningMsg, + format( + # TRANSLATORS: Popup trying to prevent the user to set an specific MAC address + _("Specifying a MAC address is optional. \n" \ + "In most cases letting it empty (default) is the correct choice. \n\n" \ + "Do you really want to set it it '%s'?"), + mac_address_widget.value + ) + ) + end + def report_mac_error # TRANSLATORS: Popup error about not valid MAC address provided msg = _("The MAC address provided is not valid, please provide a valid one.") @@ -272,12 +297,23 @@ def layer2? # @return [Boolean] true when valid; false otherwise # @param mac_address [String] def valid_mac?(mac_address) - return false if mac_address.to_s.empty? - return false if mac_address == "00:00:00:00:00:00" + return true unless lladdress_for(mac_address) !!(mac_address =~ /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i) end + # Return the MAC address in case it is not empty or a zero's MAC address + # otherwise it returns nil. + # + # @param mac_widget_value [String] + # @return [String, nil] the MAC address in case it is not empty or a + # zero's MAC address; nil otherwise + def lladdress_for(mac_widget_value) + return if ["", "00:00:00:00:00:00"].include?(mac_widget_value.to_s) + + mac_widget_value + end + # Convenience method to enable or disable the mac address widget when the # layer2 support is modified def refresh @@ -326,11 +362,6 @@ def help "

Select Enable Layer 2 Support if this card has been " \ "configured with layer 2 support.

" end - - # @see CWM::AbstractWidget - def store - @settings.layer2 = value - end end # Widget for setting the mac address to be used in case of layer2 supported @@ -356,12 +387,7 @@ def label # @see CWM::AbstractWidget def help _("

Enter the Layer 2 MAC Address if this card has been " \ - "configured with layer 2 support.

") - end - - # @see CWM::AbstractWidget - def store - @settings.lladdress = value + "configured with layer 2 support (optional).

") end end end diff --git a/test/y2network/widgets/s390_common_test.rb b/test/y2network/widgets/s390_common_test.rb index 0c957b220..7dd91e63f 100644 --- a/test/y2network/widgets/s390_common_test.rb +++ b/test/y2network/widgets/s390_common_test.rb @@ -121,15 +121,42 @@ end context "when the layer2 support is enabled" do - context "and the MAC provided is valid" do - let(:layer2_address) { "02:00:00:00:01:FD" } + context "and the MAC address is empty" do + let(:layer2_address) { "" } + + it "returns true" do + expect(subject.validate).to eql(true) + end + end + context "and the MAC address is '00:00:00:00:00:00'" do it "returns true" do expect(subject.validate).to eql(true) end end + context "and the MAC provided is a valid one" do + let(:layer2_address) { "02:00:00:00:01:FD" } + + it "requests user confirmation before storing the defined MAC" do + expect(subject).to receive(:use_selected_mac?) + subject.validate + end + + it "returns true if the user accepts" do + allow(subject).to receive(:use_selected_mac?).and_return(true) + expect(subject.validate).to eql(true) + end + + it "returns false if the user reject" do + allow(subject).to receive(:use_selected_mac?).and_return(false) + expect(subject.validate).to eql(false) + end + end + context "and the MAC address provided is invalid" do + let(:layer2_address) { "02:00:00:00:01" } + it "returns false" do allow(Yast::Popup).to receive(:Error) expect(subject.validate).to eql(false) @@ -142,6 +169,45 @@ end end end + + describe "#store" do + context "when the layer2 support checkbox is checked" do + it "sets the builder layer2 attribute to true" do + expect(builder).to receive("layer2=").with(true) + subject.store + end + + context "and the MAC address is not empty and neither is it '00:00:00:00:00:00'" do + let(:layer2_address) { "02:00:00:00:01" } + + it "sets the builder lladdress attribute to the MAC address widget value" do + expect(builder).to receive("lladdress=").with("02:00:00:00:01") + subject.store + end + end + + context "and the MAC address is empty or '00:00:00:00:00:00'" do + it "sets the builder lladdress attribute to nil" do + expect(builder).to receive("lladdress=").with(nil) + subject.store + end + end + end + + context "when the layer2 support checkbox is not checked" do + let(:layer2_support) { false } + + it "sets the builder layer2 attribute to false" do + expect(builder).to receive("layer2=").with(false) + subject.store + end + + it "sets the builder lladdress attribute to nil" do + expect(builder).to receive("lladdress=").with(nil) + subject.store + end + end + end end describe Y2Network::Widgets::S390Layer2Support do