Skip to content

Commit

Permalink
Added IpoibMode as suggested in CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jul 24, 2019
1 parent 7e4db26 commit 5497b56
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/lib/y2network/connection_config/infiniband.rb
Expand Up @@ -25,13 +25,8 @@ module ConnectionConfig
#
# @see https://www.kernel.org/doc/Documentation/infiniband/ipoib.txt
class Infiniband < Base
# @return [String] transport mode ("datagram" or "connected")
# @return [IpoibMode] transport mode
attr_accessor :ipoib_mode

# Constructor
def initialize
@ipoib_mode = ""
end
end
end
end
60 changes: 60 additions & 0 deletions src/lib/y2network/ipoib_mode.rb
@@ -0,0 +1,60 @@
# 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 "yast"

module Y2Network
# This class represents the supported IPoIB transport modes.
class IpoibMode
class << self
# Returns all the existing modes
#
# @return [Array<IpoibMode>]
def all
@all ||= IpoibMode.constants
.map { |c| IpoibMode.const_get(c) }
.select { |c| c.is_a?(IpoibMode) }
end

# Returns the transport mode with a given name
#
# @param name [String]
# @return [IpoibMode,nil] Ipoib mode or nil if not found
def from_name(name)
all.find { |t| t.name == name }
end
end

# @return [String] Returns mode name
attr_reader :name

# Constructor
#
# @param name [String] mode name
def initialize(name)
@name = name
end

DATAGRAM = new("datagram")
CONNECTED = new("connected")
# Not a mode at all but the default value that will be choose by the IB
# driver (bnc#1086454)
DEFAULT = new("")
end
end
Expand Up @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "y2network/sysconfig/connection_config_readers/base"
require "y2network/ipoib_mode"

module Y2Network
module Sysconfig
Expand All @@ -29,7 +30,7 @@ class Infiniband < Base

# @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config
def update_connection_config(conn)
conn.ipoib_mode = file.ipoib_mode
conn.ipoib_mode = IpoibMode.from_name(file.ipoib_mode.to_s)
end
end
end
Expand Down
Expand Up @@ -29,7 +29,7 @@ class Infiniband < Base

# @see Y2Network::ConnectionConfigWriters::Base#update_file
def update_file(conn)
file.ipoib_mode = conn.ipoib_mode
file.ipoib_mode = conn.ipoib_mode.name
end
end
end
Expand Down
Expand Up @@ -41,7 +41,7 @@
it "returns a infiniband connection config object" do
infiniband_conn = handler.connection_config
expect(infiniband_conn.interface).to eq("ib0")
expect(infiniband_conn.ipoib_mode).to eq("datagram")
expect(infiniband_conn.ipoib_mode).to eq(Y2Network::IpoibMode::DATAGRAM)
expect(infiniband_conn.ip_configs.map(&:address)).to eq([ip_address])
expect(infiniband_conn.bootproto).to eq(Y2Network::BootProtocol::STATIC)
end
Expand Down
Expand Up @@ -22,6 +22,7 @@
require "y2network/sysconfig/connection_config_writers/infiniband"
require "y2network/startmode"
require "y2network/boot_protocol"
require "y2network/ipoib_mode"
require "y2network/connection_config/infiniband"
require "y2network/connection_config/ip_config"

Expand Down Expand Up @@ -58,7 +59,7 @@ def file_content(scr_root, file)
name: "ib0",
interface: "ib0",
description: "",
ipoib_mode: "datagram",
ipoib_mode: Y2Network::IpoibMode::CONNECTED,
ip_configs: ip_configs,
startmode: Y2Network::Startmode.create("auto"),
bootproto: Y2Network::BootProtocol::STATIC
Expand All @@ -71,7 +72,7 @@ def file_content(scr_root, file)
it "writes the 'ipoib_mode' attribute" do
handler.write(conn)
expect(file).to have_attributes(
ipoib_mode: "datagram"
ipoib_mode: "connected"
)
end
end
Expand Down

0 comments on commit 5497b56

Please sign in to comment.