Skip to content

Commit

Permalink
Merge 23b1e78 into 0602ce8
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Apr 12, 2021
2 parents 0602ce8 + 23b1e78 commit ba98334
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Apr 12 12:05:02 UTC 2021 - Knut Anderssen <kanderssen@suse.com>

- 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 <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.3.64
Version: 4.3.65
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
58 changes: 42 additions & 16 deletions src/lib/y2network/widgets/s390_common.rb
Expand Up @@ -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.")
Expand All @@ -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
Expand Down Expand Up @@ -326,11 +362,6 @@ def help
"<p>Select <b>Enable Layer 2 Support</b> if this card has been " \
"configured with layer 2 support.</p>"
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
Expand All @@ -356,12 +387,7 @@ def label
# @see CWM::AbstractWidget
def help
_("<p>Enter the <b>Layer 2 MAC Address</b> if this card has been " \
"configured with layer 2 support.</p>")
end

# @see CWM::AbstractWidget
def store
@settings.lladdress = value
"configured with layer 2 support <b>(optional)</b>.</p>")
end
end
end
Expand Down
70 changes: 68 additions & 2 deletions test/y2network/widgets/s390_common_test.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ba98334

Please sign in to comment.