Skip to content

Commit

Permalink
Virtual.from_connection receives only the connection object
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 3, 2019
1 parent 21ab275 commit 1bceb6e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lib/y2network/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def add_or_update_connection_config(connection_config)
return unless connection_config.virtual?
interface = interfaces.by_name(connection_config.interface)
return if interface
interfaces << VirtualInterface.from_connection(connection_config.interface, connection_config)
interfaces << VirtualInterface.from_connection(connection_config)
end

alias_method :eql?, :==
Expand Down
7 changes: 3 additions & 4 deletions src/lib/y2network/sysconfig/interfaces_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def find_connections
interface ? interface.type : nil
)
next unless connection
add_interface(name, connection) if interface.nil?
add_interface(connection) if interface.nil?
conns << connection
end
end
Expand Down Expand Up @@ -118,13 +118,12 @@ def configured_devices
# while reading the configuration. In such situations, a fake one
# should be added.
#
# @param name [String] Interface name
# @param conn [ConnectionConfig] Connection configuration related to the
# network interface
def add_interface(name, conn)
def add_interface(conn)
interface =
if conn.virtual?
VirtualInterface.from_connection(name, conn)
VirtualInterface.from_connection(conn)
else
PhysicalInterface.new(conn.name, hardware: Hwinfo.for(conn.name))
end
Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2network/virtual_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class VirtualInterface < Interface
#
# @param conn [ConnectionConfig] Connection configuration related to the
# network interface
def self.from_connection(name, conn)
new(name, type: conn.type)
def self.from_connection(conn)
new(conn.interface || conn.name, type: conn.type)
end
end
end
18 changes: 17 additions & 1 deletion test/y2network/virtual_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@

require_relative "../test_helper"
require "y2network/virtual_interface"
require "y2network/connection_config/bridge"

describe Y2Network::VirtualInterface do
subject(:interface) { described_class.new("br0") }
subject(:interface) { described_class.new("br0", type: type) }

let(:type) { Y2Network::InterfaceType::BRIDGE }

describe ".from_connection" do
let(:conn) do
Y2Network::ConnectionConfig::Bridge.new.tap { |c| c.name = "br0" }
end

it "returns a virtual interface using connection's and type" do
interface = described_class.from_connection(conn)
expect(interface).to be_a(described_class)
expect(interface.name).to eq("br0")
expect(interface.type).to eq(Y2Network::InterfaceType::BRIDGE)
end
end
end

0 comments on commit 1bceb6e

Please sign in to comment.