Skip to content

Commit

Permalink
Merge 04b5d8f into f23335c
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Aug 2, 2022
2 parents f23335c + 04b5d8f commit 5633454
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 67 deletions.
8 changes: 8 additions & 0 deletions package/yast2-fcoe-client.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Jul 21 10:07:04 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

- Use yast2-network to write the sysconfig files in order to be
aware of the new connections added during the installation
(bsc#1199554).
- 4.3.2

-------------------------------------------------------------------
Fri Feb 18 11:47:53 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

Expand Down
4 changes: 3 additions & 1 deletion package/yast2-fcoe-client.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-fcoe-client
Version: 4.3.1
Version: 4.3.2
Release: 0
Summary: YaST2 - Configuration of Fibre Channel over Ethernet
Group: System/YaST
Expand All @@ -28,10 +28,12 @@ Source0: %{name}-%{version}.tar.bz2

BuildRequires: perl-XML-Writer update-desktop-files yast2
BuildRequires: yast2-devtools >= 4.2.2
BuildRequires: yast2-network >= 4.3.85
BuildRequires: rubygem(%{rb_default_ruby_abi}:rspec)

# Yast2::Systemd::Service
Requires: yast2 >= 4.1.3
Requires: yast2-network >= 4.3.85
Requires: fcoe-utils
Requires: yast2-ruby-bindings >= 1.0.0

Expand Down
53 changes: 12 additions & 41 deletions src/modules/FcoeClient.rb
Expand Up @@ -32,6 +32,7 @@

require "yast"
require "yast2/systemd/socket"
require "y2network/fcoe_conn_generator"

module Yast
class FcoeClientClass < Module
Expand Down Expand Up @@ -77,6 +78,7 @@ def main
Yast.import "NetworkService"
Yast.import "String"
Yast.import "FileUtils"
Yast.import "Lan"

# Data

Expand Down Expand Up @@ -1225,50 +1227,19 @@ def WriteFcoeConfig
success
end

# Writes the network configuration for the FCoE Vlan interface and the related parent device
#
# Write ifcfg-files in /etc/sysconfig/network (for FCoE VLAN interface and underlying interface)
# using network.scr from yast2/library/network
#
# @return [Boolean] whether it wrote the ifcfg files for netcards or not
def WriteSysconfigFiles
netcards = GetNetworkCards()
success = true
netcards = GetNetworkCards().select { |c| fcoe_vlan?(c) }
return true if netcards.empty?

netcards.each do |card|
fcoe_vlan = fcoe_vlan(card)
# write ifcfg-<if>.<VLAN> only if VLAN was created (not for VLAN = 0 which means
# FCoE is started on the network interface itself)
next if fcoe_vlan.nil?

dev_name = card.fetch("dev_name", "")
vid = card.fetch("vlan_interface", "")
if vid != "0"
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(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", vid)
end
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
SCR.Write(ifcfg_path + "STARTMODE", "nfsroot")
# don't overwrite BOOTPROTO !!!
if !FileUtils.Exists(ifcfg_file)
SCR.Write(ifcfg_path + "BOOTPROTO", "static")
SCR.Write(ifcfg_path + "NAME", card.fetch("device", ""))
end
end
# This is very important- it flushes the cache, and stores the configuration on the disk
success = SCR.Write(path(".network"), nil)
if !success
Builtins.y2error("Error writing /etc/sysconfig/network/ifcfg-files")
end
success
Yast::Lan.read_config(report: false) unless Yast::Lan.yast_config
conn_generator = Y2Network::FcoeConnGenerator.new(Yast::Lan.yast_config)
netcards.each { |card| conn_generator.update_connections_for(card) }
Yast::Lan.write_config(only: [:connections])

true
end

#
Expand Down
38 changes: 13 additions & 25 deletions test/fcoe_client_write_spec.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env rspec
require_relative "test_helper"
Yast.import "FcoeClient"
Yast.import "Lan"

describe Yast::FcoeClientClass do
subject { Yast::FcoeClient }
Expand All @@ -16,8 +17,13 @@
end

describe "#WriteSysconfigFiles" do
let(:config) { stub_const("Y2Network::Config", double.as_null_object) }

before do
allow(subject).to receive(:GetNetworkCards).and_return(interfaces)
allow(Yast::Lan).to receive(:yast_config).and_return(config)
allow(Yast::Lan).to receive(:read_config)
allow(Yast::Lan).to receive(:write_config)
end


Expand All @@ -30,13 +36,8 @@
]
end

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

it "writes nothing into /etc/sysconfig/network" do
expect(Yast::SCR).to_not receive(:Write)
.with(path_matching(/^\.network\..*/), anything)
it "does not modify the network configuration" do
expect(Yast::Lan).to_not receive(:write_config)

subject.WriteSysconfigFiles
end
Expand All @@ -52,31 +53,18 @@
end

before do
allow(Yast::SCR).to receive(:Write).and_return(true)
allow(Yast::FileUtils).to receive(:Exists).and_return(false)
end

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

it "writes the sysconfig configuration for the interface and its FCoE VLAN" do
expect(Yast::SCR).to receive(:Write)
.with(path_matching(/^\.network\.value\.\"eth1.500-fcoe\"\.*/), anything)
expect(Yast::SCR).to receive(:Write)
.with(path_matching(/^\.network\.value\.\"eth1\"\.*/), anything)
# A final call is also needed to flush the content
expect(Yast::SCR).to receive(:Write).with(Yast::Path.new(".network"), nil)
it "calls the FCoE connection generator to add or update the device and VLAN connections" do
expect_any_instance_of(Y2Network::FcoeConnGenerator)
.to receive(:update_connections_for).once.with(interfaces[1])

subject.WriteSysconfigFiles
end

it "writes nothing in /etc/sysconfig/network for interfaces without FCoE VLAN" do
allow(Yast::SCR).to receive(:Write) do |path, value|
# All calls to SCR.Write must contain a path starting with ".network.value.\"eth1"
# or exactly the path ".network" (for flushing)
expect(path.to_s).to match("(^\.network$)|(^\.network\.value\.\"eth1(\.|\"))")
end
it "writes the modified network connections configuration" do
expect(Yast::Lan).to receive(:write_config).with(only: [:connections])

subject.WriteSysconfigFiles
end
Expand Down

0 comments on commit 5633454

Please sign in to comment.