Skip to content

Commit

Permalink
Merge 385781c into 0831e26
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Sep 13, 2017
2 parents 0831e26 + 385781c commit a7f8baf
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 134 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config.status
config.sub
configure
configure.ac
/coverage/
install-sh
/Makefile.am
/Makefile.am.common
Expand Down
6 changes: 6 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--no-private
--markup markdown
--protected
--output-dir ./doc/autodocs
--files *.md
src/**/*.rb
1 change: 0 additions & 1 deletion src/clients/fcoe-client_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def main
# FCoE is possible. We can not start exactly the interface from imported
# data because the numeration of interfaces (eth0, eth1...) may differ.
Builtins.foreach(@detected_netcards) do |card|
vlan_interface = ""
fcoe_vlan_interface = ""
command = ""
output = {}
Expand Down
57 changes: 20 additions & 37 deletions src/include/fcoe-client/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def AdjustButtons
end

def ShowInterfaces
vlan_interface = ""
row = 0

netcards = FcoeClient.GetNetworkCards
Expand Down Expand Up @@ -314,9 +313,7 @@ def InitEditDialog(id)

# Handle
#
def HandleServicesDialog(id, event)
event = deep_copy(event)
action = Ops.get(event, "ID")
def HandleServicesDialog(_id, _event)
nil
end

Expand Down Expand Up @@ -351,6 +348,7 @@ def HandleInterfacesDialog(id, event)
card = FcoeClient.GetCurrentNetworkCard
Builtins.y2milestone("Selected card: %1", card)
dev_name = Ops.get_string(card, "dev_name", "")
vlan_interface = card.fetch("vlan_interface", "") # eg. "200"

configured_vlans = FcoeClient.IsConfigured(dev_name)

Expand All @@ -365,28 +363,22 @@ def HandleInterfacesDialog(id, event)
# text of an error popup
Popup.Error(
Builtins.sformat(
_(
"Cannot start FCoE on VLAN interface %1\n" +
_("Cannot start FCoE on VLAN interface %1\n" +
"because FCoE is already configured on\n" +
"network interface %2 itself."
),
Ops.get_string(card, "vlan_interface", ""),
dev_name
"network interface %2 itself."),
vlan_interface, dev_name
)
)
return nil
end
if Ops.get_string(card, "vlan_interface", "") == "0"
if vlan_interface == "0"
# text of an error popup
Popup.Error(
Builtins.sformat(
_(
"Cannot start FCoE on network interface %1 itself\n" +
_("Cannot start FCoE on network interface %1 itself\n" +
"because FCoE is already configured on\n" +
"VLAN interface(s) %2."
),
dev_name,
configured_vlans
"VLAN interface(s) %2."),
dev_name, configured_vlans
)
)
return nil
Expand All @@ -400,30 +392,27 @@ def HandleInterfacesDialog(id, event)
)
end

command = Builtins.sformat("fipvlan -c -s %1", dev_name)
if card["auto_vlan"] == "yes" || vlan_interface == "0"
command = Builtins.sformat("fipvlan -c -s -f '-fcoe' %1", dev_name)
else
command = Builtins.sformat("fipvlan -c -s %1", dev_name)
end

output = {}
fcoe_vlan_interface = ""
status_map = {}

ifcfg_file = Builtins.sformat(
"/etc/sysconfig/network/ifcfg-%1.%2",
dev_name,
Ops.get_string(card, "vlan_interface", "")
)
ifcfg_file = "/etc/sysconfig/network/ifcfg-#{dev_name}.#{vlan_interface}"

# headline of a popup: creating and starting Fibre Channel over Ethernet
ret = Popup.YesNoHeadline(
_("Creating and Starting FCoE on Detected VLAN Device"),
# question to the user: really create and start FCoE
Builtins.sformat(
_(
"Do you really want to create a FCoE network\n" +
_("Do you really want to create a FCoE network\n" +
"interface for discovered VLAN interface %1\n" +
"on %2 and start the FCoE initiator?"
),
Ops.get_string(card, "vlan_interface", ""),
dev_name
"on %2 and start the FCoE initiator?"),
vlan_interface, dev_name
)
)
if ret == true
Expand All @@ -450,11 +439,7 @@ def HandleInterfacesDialog(id, event)
# if /etc/sysconfig/network/ifcfg-<if>.<vlan> already exists
# call 'ifup' for the interface (creates /proc/net/vlan/<if>.<vlan>)
if FileUtils.Exists(ifcfg_file)
cmd_ifup = Builtins.sformat(
"ifup %1.%2",
dev_name,
Ops.get_string(card, "vlan_interface", "")
)
cmd_ifup = Builtins.sformat("ifup %1.%2", dev_name, vlan_interface)
Builtins.y2milestone("Executing command: %1", cmd_ifup)
output = Convert.to_map(
SCR.Execute(path(".target.bash_output"), cmd_ifup)
Expand Down Expand Up @@ -774,9 +759,7 @@ def HandleInterfacesDialog(id, event)
nil
end

def HandleConfigurationDialog(id, event)
event = deep_copy(event)
action = Ops.get(event, "ID")
def HandleConfigurationDialog(_id, _event)
nil
end

Expand Down
126 changes: 32 additions & 94 deletions src/modules/FcoeClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class FcoeClientClass < Module

FCOE_PKG_NAME = "fcoe-utils"

# Used by FcoeClientClass to keep data about an individual network interface
# (Not a real class; documents the structure of a Hash)
class Interface < Hash
# @!method [](k)
# @option k [String] 'fcoe_vlan'
# "eth1.500" or "not configured" or "not available"
# @option k [String,nil] 'vlan_interface'
# "500", or "0" for no VLAN used; yes, the name is nonsense, should be "vid"
# @option k [] ''
end

def main
Yast.import "UI"
textdomain "fcoe-client"
Expand Down Expand Up @@ -673,7 +684,6 @@ def CreateFcoeConfig(vlan_device_name, netcard)
#
def GetFcoeStatus(vlan_device_name, device_name)
status_map = {}
content = ""
file_name = ""
device = vlan_device_name

Expand Down Expand Up @@ -952,9 +962,9 @@ def IsConfigured(device_name)
deep_copy(configured_vlans)
end

#
# Detect network interface cards (hardware probe)
#
# @return [Array<Hash>] .probe.netcard output
# (except the items without dev_name)
def ProbeNetcards
if !TestMode()
netcards = Convert.convert(
Expand Down Expand Up @@ -1012,7 +1022,8 @@ def ProbeNetcards
# eth3 08:00:... Gigabit... 200 eth3.200 yes/no yes/no yes/no yes/no eth3.200
#
# Get the network cards and check Fcoe status
#
# @param netcards [Array<Hash>] .probe.netcard output
# @return [Array<Interface>]
def DetectNetworkCards(netcards)
return [] if netcards == nil

Expand Down Expand Up @@ -1223,107 +1234,34 @@ def WriteSysconfigFiles
success = true

Builtins.foreach(netcards) do |card|
if Ops.get_string(card, "fcoe_vlan", "") != @NOT_AVAILABLE &&
Ops.get_string(card, "fcoe_vlan", "") != @NOT_CONFIGURED
fcoe_vlan = card.fetch("fcoe_vlan", "")
if fcoe_vlan != @NOT_AVAILABLE &&
fcoe_vlan != @NOT_CONFIGURED
# write ifcfg-<if>.>VLAN> only if VLAN was created (not for VLAN = 0 which means
# FCoE is started on the network interface itself)
dev_name = card.fetch("dev_name", "")
if Ops.get_string(card, "vlan_interface", "") != "0"
Builtins.y2milestone(
"Writing /etc/sysconfig/network/ifcfg-%1",
Ops.get_string(card, "fcoe_vlan", "")
)
Builtins.y2milestone("Writing /etc/sysconfig/network/ifcfg-%1", fcoe_vlan)
vifcfg_path = path(".network.value") + fcoe_vlan
# write /etc/sysconfig/network/ifcfg-<fcoe-vlan-interface>, e.g. ifcfg-eth3.200
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "fcoe_vlan", "")
),
"BOOTPROTO"
),
"static"
)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "fcoe_vlan", "")
),
"STARTMODE"
),
"nfsroot"
)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "fcoe_vlan", "")
),
"ETHERDEVICE"
),
Ops.get_string(card, "dev_name", "")
)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "fcoe_vlan", "")
),
"USERCONTROL"
),
"no"
)
SCR.Write(vifcfg_path + "BOOTPROTO", "static")
SCR.Write(vifcfg_path + "STARTMODE", "nfsroot")
SCR.Write(vifcfg_path + "ETHERDEVICE", dev_name)
SCR.Write(vifcfg_path + "USERCONTROL", "no")
SCR.Write(vifcfg_path + "VLAN_ID", card.fetch("vlan_interface", ""))
end
ifcfg_file = Builtins.sformat(
"/etc/sysconfig/network/ifcfg-%1",
Ops.get_string(card, "dev_name", "")
)
ifcfg_file = "/etc/sysconfig/network/ifcfg-#{dev_name}"
Builtins.y2milestone("Writing %1", ifcfg_file)

# write /etc/sysconfig/network/ifcfg-<interface> (underlying interface), e.g. ifcfg-eth3
ifcfg_path = path(".network.value") + dev_name
if !FileUtils.Exists(ifcfg_file)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "dev_name", "")
),
"BOOTPROTO"
),
"static"
)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "dev_name", "")
),
"STARTMODE"
),
"nfsroot"
)
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "dev_name", "")
),
"NAME"
),
Ops.get_string(card, "device", "")
)
SCR.Write(ifcfg_path + "BOOTPROTO", "static")
SCR.Write(ifcfg_path + "STARTMODE", "nfsroot")
SCR.Write(ifcfg_path + "NAME", Ops.get_string(card, "device", ""))
else
# don't overwrite BOOTPROTO !!!
SCR.Write(
Ops.add(
Ops.add(
path(".network.value"),
Ops.get_string(card, "dev_name", "")
),
"STARTMODE"
),
"nfsroot"
)
SCR.Write(ifcfg_path + "STARTMODE", "nfsroot")
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/DetectNetworkCards_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env rspec
require_relative '../src/modules/FcoeClient'
require_relative "test_helper"
Yast.import "FcoeClient"

describe Yast::FcoeClientClass do
before :each do
Expand Down
3 changes: 2 additions & 1 deletion test/GetVlanInterfaces_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env rspec
require_relative '../src/modules/FcoeClient'
require_relative "test_helper"
Yast.import "FcoeClient"

describe Yast::FcoeClientClass do
before :each do
Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TESTS = \
fcoe_client_write_spec.rb \
DetectNetworkCards_spec.rb \
GetVlanInterfaces_spec.rb

Expand Down
46 changes: 46 additions & 0 deletions test/fcoe_client_write_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env rspec
require_relative "test_helper"
Yast.import "FcoeClient"

describe Yast::FcoeClientClass do
subject { Yast::FcoeClient }

describe "#ProbeNetcards" do
before do
expect(subject).to receive(:TestMode).and_return true
end

it "returns an array" do
expect(subject.ProbeNetcards).to be_an Array
end
end

describe "#WriteSysconfigFiles" do
context "odd cases" do
before do
interfaces = [
{ "fcoe_vlan" => "not available" },
{ "fcoe_vlan" => "not configured" },
]
expect(subject).to receive(:GetNetworkCards).and_return(interfaces)
end

it "smokes not" do
expect { subject.WriteSysconfigFiles }.to_not raise_error
end
end

context "for a small FCoE setup" do
before do
interfaces = [
{ "fcoe_vlan" => "eth1.500" }
]
expect(subject).to receive(:GetNetworkCards).and_return(interfaces)
end

it "smokes not" do
expect { subject.WriteSysconfigFiles }.to_not raise_error
end
end
end
end

0 comments on commit a7f8baf

Please sign in to comment.