Skip to content

Commit

Permalink
Merge ed5c3a3 into 4399f2a
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 1, 2019
2 parents 4399f2a + ed5c3a3 commit 6fda6bd
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/include/network/lan/address.rb
Expand Up @@ -28,6 +28,7 @@
#
require "y2firewall/helpers/interfaces"
require "y2network/dialogs/edit_interface"
require "y2network/boot_protocol"

module Yast
module NetworkLanAddressInclude
Expand Down Expand Up @@ -73,9 +74,9 @@ def AddressDialog(builder:)

# IP is mandatory for static configuration. Makes no sense to write static
# configuration without that.
return ret if bootproto == "static" && ipaddr.empty?
return ret if bootproto == Y2Network::BootProtocol::STATIC && ipaddr.empty?

if bootproto == "static"
if bootproto == Y2Network::BootProtocol::STATIC
update_hostname(ipaddr, builder.hostname || "")
elsif LanItems.isCurrentDHCP && !LanItems.isCurrentHotplug
# fixed bug #73739 - if dhcp is used, dont set default gw statically
Expand Down
12 changes: 12 additions & 0 deletions src/lib/y2network/boot_protocol.rb
Expand Up @@ -56,6 +56,18 @@ def dhcp?
[DHCP4, DHCP6, DHCP, DHCP_AUTOIP].include?(self)
end

# Determines whether two objects are equivalent
#
# They are equal when they refer to the same boot protocol (through the name).
#
# @param other [BootProtocol] Boot protocol to compare with
# @return [Boolean]
def ==(other)
name == other.name
end

alias_method :eql?, :==

# iBFT boot protocol
IBFT = new("ibft")
# statically assigned interface properties
Expand Down
12 changes: 12 additions & 0 deletions src/lib/y2network/ipoib_mode.rb
Expand Up @@ -51,6 +51,18 @@ def initialize(name)
@name = name
end

# Determines whether two objects are equivalent
#
# They are equal when they refer to the same IPoIB mode (through the name).
#
# @param other [IpoibMode] IPoIB mode to compare with
# @return [Boolean]
def ==(other)
name == other.name
end

alias_method :eql?, :==

DATAGRAM = new("datagram")
CONNECTED = new("connected")
# Not a mode at all but the default value that will be choose by the IB
Expand Down
16 changes: 15 additions & 1 deletion test/y2network/boot_protocol_test.rb
Expand Up @@ -22,7 +22,7 @@
require "y2network/boot_protocol"

describe Y2Network::BootProtocol do
subject { described_class.new("dhcp") }
subject(:protocol) { described_class.new("dhcp") }

describe ".all" do
it "returns all known boot protocols" do
Expand All @@ -48,4 +48,18 @@
expect(Y2Network::BootProtocol::STATIC.dhcp?).to eq false
end
end

describe "#==" do
context "when the other object refers to the same boot protocol" do
it "returns true" do
expect(protocol).to eq(described_class.new("dhcp"))
end
end

context "when the other object refers to a different boot protocol" do
it "returns false" do
expect(protocol).to_not eq(described_class.new("static"))
end
end
end
end
56 changes: 56 additions & 0 deletions test/y2network/ipoib_mode_test.rb
@@ -0,0 +1,56 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "../test_helper"

require "y2network/ipoib_mode"

describe Y2Network::IpoibMode do
subject(:mode) { described_class.new("datagram") }

describe ".all" do
it "returns all know IPoIB modes" do
expect(described_class.all).to contain_exactly(
Y2Network::IpoibMode::CONNECTED,
Y2Network::IpoibMode::DATAGRAM,
Y2Network::IpoibMode::DEFAULT
)
end
end

describe ".from_name" do
it "returns the IPoIB mode with the given mode" do
expect(described_class.from_name("datagram")).to eq(Y2Network::IpoibMode::DATAGRAM)
end
end

describe "#==" do
context "when the other object refers to the same IPoIB mode" do
it "returns true" do
expect(mode).to eq(described_class.new("datagram"))
end
end

context "when the other object refers to a different IPoIB mode" do
it "returns false" do
expect(mode).to_not eq(described_class.new("connected"))
end
end
end
end

0 comments on commit 6fda6bd

Please sign in to comment.