Skip to content

Commit

Permalink
Replace FakeInterface with PhysicalInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 2, 2019
1 parent b252618 commit 9b9b756
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/lib/y2network/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ def initialize(name, type: InterfaceType::ETHERNET)
@name = name
@description = ""
@type = type
# TODO: move renaming logic to physical interfaces only
@renaming_mechanism = :none
# @hardware and @name should not change during life of the object
@hardware = Hwinfo.for(name)

init(name)
end
Expand Down
22 changes: 22 additions & 0 deletions src/lib/y2network/physical_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,33 @@
# find current contact information at www.suse.com.

require "y2network/interface"
require "y2network/hwinfo"

module Y2Network
# Physical interface class (ethernet, wireless, infiniband...)
class PhysicalInterface < Interface
# @return [String]
attr_accessor :ethtool_options

# Constructor
#
# @param name [String] Interface name (e.g., "eth0")
# @param type [InterfaceType] Interface type
# @param hardware [Hwinfo] Hardware information
def initialize(name, type: InterfaceType::ETHERNET, hardware: nil)
super(name, type: type)
# @hardware and @name should not change during life of the object
@hardware = hardware || Hwinfo.for(name)
end

# Determines whether the interface is present (attached)
#
# It relies in the hardware information
#
# @return [Boolean]
# @see Interface#present?
def present?
@hardware.present?
end
end
end
10 changes: 7 additions & 3 deletions src/lib/y2network/sysconfig/interfaces_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
require "y2network/interface_type"
require "y2network/virtual_interface"
require "y2network/physical_interface"
require "y2network/fake_interface"
require "y2network/sysconfig/connection_config_reader"
require "y2network/interfaces_collection"
require "y2network/connection_configs_collection"
Expand Down Expand Up @@ -144,8 +143,13 @@ def configured_devices
# @param conn [ConnectionConfig] Connection configuration related to the
# network interface
def add_interface(name, conn)
interface_class = conn.virtual? ? VirtualInterface : FakeInterface
@interfaces << interface_class.from_connection(name, conn)
interface =
if conn.virtual?
VirtualInterface.from_connection(name, conn)
else
PhysicalInterface.new(conn.name, hardware: Hwinfo.for(conn.name))
end
@interfaces << interface
end

# Detects the renaming mechanism used by the interface
Expand Down
5 changes: 3 additions & 2 deletions test/y2network/sysconfig/interfaces_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
end

context "and it is not a virtual connection" do
it "creates a fake interface" do
it "creates a not present physical interface" do
eth1 = reader.interfaces.by_name("eth1")
expect(eth1).to be_a Y2Network::FakeInterface
expect(eth1).to be_a Y2Network::PhysicalInterface
expect(eth1).to_not be_present
end
end
end
Expand Down

0 comments on commit 9b9b756

Please sign in to comment.