Skip to content

Commit

Permalink
Merge pull request #1182 from mchf/bnc1180085-lanitems-cleanup
Browse files Browse the repository at this point in the history
LanItems cleanup - part#1
  • Loading branch information
mchf committed Mar 16, 2021
2 parents 972b808 + a0df5c9 commit e5627e9
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 51 deletions.
5 changes: 2 additions & 3 deletions src/include/network/lan/cmdline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def initialize_network_lan_cmdline(_include_target)
Yast.import "CommandLine"
Yast.import "Lan"
Yast.import "Report"
Yast.import "LanItems"
end

def validateId(options, config)
Expand Down Expand Up @@ -120,7 +119,7 @@ def AddHandler(options)
builder.name = options.fetch("name")
update_builder_from_options!(builder, options)

LanItems.Commit(builder)
builder.save
ListHandler({})

true
Expand All @@ -144,7 +143,7 @@ def EditHandler(options)
builder.name = interface.name
update_builder_from_options!(builder, options)

LanItems.Commit(builder)
builder.save
ShowHandler(options)
true
rescue InvalidOption => e
Expand Down
14 changes: 2 additions & 12 deletions src/include/network/lan/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def initialize_network_lan_complex(include_target)
Yast.import "TablePopup"
Yast.import "CWMTab"
Yast.import "Stage"
Yast.import "LanItems"
Yast.import "Systemd"

Yast.include include_target, "network/routines.rb"
Expand Down Expand Up @@ -156,12 +155,7 @@ def delete_interface
# Commit changes to internal structures
# @return always `next
def Commit(builder:)
# 1) update NetworkInterfaces with corresponding devmap
# FIXME: new item in NetworkInterfaces was created from handleOverview by
# calling Lan.Add and named in HardwareDialog via NetworkInterfaces.Name=
# - all that stuff can (should) be moved here to have it isolated at one place
# and later moved to Interface object
LanItems.Commit(builder)
builder.save

:next
end
Expand All @@ -172,10 +166,6 @@ def ReadDialog
Wizard.RestoreHelp(Ops.get_string(@help, "read", ""))
Lan.AbortFunction = -> { PollAbort() }
ret = Lan.Read(:cache)
# Currently just a smoketest for new config storage -
# something what should replace Lan module in the bright future
# TODO: find a suitable place for this config storage
Y2Network::Config.from(:wicked)

if Lan.HaveXenBridge
if !Popup.ContinueCancel(
Expand Down Expand Up @@ -219,7 +209,7 @@ def input_done?(ret)

return Popup.ConfirmAbort(:painless) if Stage.initial

return ReallyAbort() if LanItems.GetModified
return ReallyAbort() if Lan.yast_config != Lan.system_config

true
end
Expand Down
1 change: 0 additions & 1 deletion src/lib/network/clients/network_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class NetworkProposal < ::Installation::ProposalClient
def initialize
Yast.import "UI"
Yast.import "Lan"
Yast.import "LanItems"

textdomain "installation"

Expand Down
3 changes: 1 addition & 2 deletions src/lib/network/network_autoconfiguration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NetworkAutoconfiguration
include Logger

Yast.import "Lan"
Yast.import "LanItems"
Yast.import "NetworkInterfaces"
Yast.import "NetworkService"
Yast.import "Package"
Expand Down Expand Up @@ -164,7 +163,7 @@ def setup_dhcp(card)
builder.boot_protocol = Y2Network::BootProtocol::DHCP
builder.startmode = Y2Network::Startmode.create("auto")

LanItems.Commit(builder)
builder.save
end

def delete_config(interface)
Expand Down
2 changes: 0 additions & 2 deletions src/lib/y2network/clients/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

Yast.import "Lan"
Yast.import "Progress"
Yast.import "Map"
Yast.import "LanItems"

module Y2Network
module Clients
Expand Down
1 change: 0 additions & 1 deletion src/lib/y2network/dialogs/edit_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
require "y2network/widgets/hardware_tab.rb"
require "y2network/widgets/wireless_tab.rb"

Yast.import "LanItems"
Yast.import "Label"

module Y2Network
Expand Down
7 changes: 1 addition & 6 deletions src/lib/y2network/hwinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ class Hwinfo
class << self
# Creates a new instance containing hardware information for a given interface
#
# It retrieves the information from two sources:
#
# * hardware (through {Yast::LanItems} for the time being),
# * from existing udev rules.
# It retrieves the information from existing udev rules.
#
# @todo Probably, this logic should be moved to a separate class.
#
Expand Down Expand Up @@ -99,8 +96,6 @@ def reset

# Returns hardware information for the given device
#
# It relies on the {Yast::LanItems} module.
#
# @param name [String] Interface's name
# @return [Hwinfo,nil] Hardware info or nil if not found
def hwinfo_from_hardware(name)
Expand Down
5 changes: 0 additions & 5 deletions src/lib/y2network/interface_config_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
module Y2Network
# Collects data from the UI until we have enough of it to create a
# {Y2Network::ConnectionConfig::Base} object.
#
# {Yast::LanItemsClass#Commit Yast::LanItems.Commit(builder)} use it.
class InterfaceConfigBuilder
include Yast::Logger
extend Forwardable
Expand Down Expand Up @@ -107,9 +105,6 @@ def newly_added?
end

# saves builder content to backend
# @ TODO now still LanItems actively query config attribute and write it
# down, so here mainly workarounds, but ideally this save should change
# completely backend
def save
@connection_config.name = name
@connection_config.interface = name
Expand Down
14 changes: 14 additions & 0 deletions src/lib/y2network/interface_config_builders/ctc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ module InterfaceConfigBuilders
class Ctc < InterfaceConfigBuilder
extend Forwardable

Yast.import "NetworkConfig"

def initialize(config: nil)
super(type: InterfaceType::CTC, config: config)
end

def save
# TODO: no one knows whether this ctc specific thing is still needed
wfi = Yast::NetworkConfig.Config["WAIT_FOR_INTERFACES"].to_i

Yast::NetworkConfig.Config["WAIT_FOR_INTERFACES"] = [wfi, WAIT_FOR_INTERFACES].max

super
end

WAIT_FOR_INTERFACES = 40
private_constant :WAIT_FOR_INTERFACES

def_delegators :@connection_config,
:read_channel, :read_channel=,
:write_channel, :write_channel=,
Expand Down
3 changes: 0 additions & 3 deletions src/lib/y2network/interface_config_builders/vlan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
require "yast"
require "y2network/interface_config_builder"

Yast.import "LanItems"
Yast.import "NetworkInterfaces"

module Y2Network
module InterfaceConfigBuilders
class Vlan < InterfaceConfigBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/interfaces_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Y2Network
#
# Objects of this class are able to keep a list of interfaces and perform simple queries
# on such a list. In the end should implement methods for mass operations over network
# interfaces like old LanItems::find_dhcp_ifaces.
# interfaces
#
# @example Finding an interface by its name
# interfaces = Y2Network::InterfacesCollection.new([eth0, wlan0])
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/widgets/slave_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module SlaveItems
include Yast::I18n

# Builds content for slave configuration dialog (used e.g. when configuring
# bond slaves) according the given list of item_ids (see LanItems::Items)
# bond slaves)
#
# @param [Array<String>] slaves list of device names
# @param [Array<String>] enslaved_ifaces list of device names of already enslaved devices
Expand Down
8 changes: 5 additions & 3 deletions test/cmdline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/interface_config_builder"

require_relative "test_helper"

class DummyClass < Yast::Module
Expand Down Expand Up @@ -125,7 +127,7 @@ def initialize
end

it "commits the new configuration" do
expect(Yast::LanItems).to receive(:Commit).with(anything)
expect_any_instance_of(Y2Network::InterfaceConfigBuilder).to receive(:save)
subject.AddHandler(options)
end

Expand All @@ -152,7 +154,7 @@ def initialize

context "when a valid configuration is providen" do
it "commits the configuration changes" do
expect(Yast::LanItems).to receive(:Commit).with(anything)
expect_any_instance_of(Y2Network::InterfaceConfigBuilder).to receive(:save)
subject.EditHandler(options)
end

Expand All @@ -178,7 +180,7 @@ def initialize

context "when a valid configuration is providen" do
it "removes given interface" do
expect(Yast::LanItems).to receive(:Commit).with(anything)
expect_any_instance_of(Y2Network::InterfaceConfigBuilder).to receive(:save)
subject.EditHandler(options)
end

Expand Down
29 changes: 18 additions & 11 deletions test/complex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def initialize
describe "#input_done?" do
BOOLEAN_PLACEHOLDER = "placeholder (true or false)".freeze

let(:wicked_config) { Y2Network::Config.new(source: :wicked) }
let(:nm_config) { Y2Network::Config.new(source: :network_manager) }

context "when not running in installer" do
before(:each) do
allow(Yast::Stage)
Expand All @@ -50,23 +53,27 @@ def initialize
end

it "returns true for input equal to :abort in case of no user modifications" do
allow(Yast::LanItems)
.to receive(:GetModified)
.and_return(false)
allow(Yast::Lan)
.to receive(:yast_config)
.and_return(wicked_config)
allow(Yast::Lan)
.to receive(:system_config)
.and_return(wicked_config)

expect(subject.input_done?(:abort)).to eql true
end

it "asks user for abort confirmation for input equal to :abort and user did modifications" do
allow(Yast::LanItems)
.to receive(:GetModified)
.and_return(true)
it "asks for confirmation in case of a user modification" do
allow(Yast::Lan)
.to receive(:yast_config)
.and_return(wicked_config)
allow(Yast::Lan)
.to receive(:system_config)
.and_return(nm_config)

expect(subject)
.to receive(:ReallyAbort)
.and_return(BOOLEAN_PLACEHOLDER)
expect(subject).to receive(:ReallyAbort)

expect(subject.input_done?(:abort)).to eql BOOLEAN_PLACEHOLDER
subject.input_done?(:abort)
end
end

Expand Down
40 changes: 40 additions & 0 deletions test/y2network/interface_config_builders/ctc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,44 @@
expect(subject.type).to eq Y2Network::InterfaceType::CTC
end
end

describe "#save" do
let(:network_config) { { "WAIT_FOR_INTERFACES" => wfi } }
let(:yast_config) { Y2Network::Config.new(source: :wicked) }

around do |test|
orig_config = Yast::NetworkConfig.Config
Yast::NetworkConfig.Config = network_config

test.call

Yast::NetworkConfig.Config = orig_config
end

before(:each) do
allow(Yast::Lan).to receive(:yast_config).and_return(yast_config)
end

# 40 is magic number found in the code
context "When WAIT_FOR_INTERFACES is < 40" do
let(:wfi) { 10 }

it "sets minimal WAIT_FOR_INTERFACES to a reasonable default" do
expect { subject.save }
.to change { Yast::NetworkConfig.Config["WAIT_FOR_INTERFACES"] }
.from(wfi)
.to(40)
end
end

context "When WAIT_FOR_INTERFACES is >= 40" do
let(:wfi) { 50 }

it "sets keeps WAIT_FOR_INTERFACES it is" do
subject.save
expect(Yast::NetworkConfig.Config["WAIT_FOR_INTERFACES"])
.to eql wfi
end
end
end
end

0 comments on commit e5627e9

Please sign in to comment.