Skip to content

Commit

Permalink
Define needed packages for each supported backend
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 29, 2022
1 parent b032c22 commit d4891b3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 45 deletions.
6 changes: 6 additions & 0 deletions src/lib/y2network/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Backend
include Yast::I18n
include Yast2::Equatable

PACKAGES = [].freeze

# @return [Symbol] backend id
attr_reader :id

Expand Down Expand Up @@ -87,5 +89,9 @@ def self.by_id(id)
def available?
Yast::NetworkService.is_backend_available(id)
end

def packages
self.class.const_get(:PACKAGES)
end
end
end
2 changes: 2 additions & 0 deletions src/lib/y2network/backends/netconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Y2Network
module Backends
# This class represents the Netconfig backend
class Netconfig < Backend
PACKAGES = "sysconfig-netconfig".freeze

def initialize
textdomain "network"
super(:netconfig)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2network/backends/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Y2Network
module Backends
# This class represents the NetworkManager backend
class NetworkManager < Backend
PACKAGES = ["NetworkManager"].freeze

def initialize
textdomain "network"
super(:network_manager)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2network/backends/wicked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Y2Network
module Backends
# This class represents the wicked backend
class Wicked < Backend
PACKAGES = ["wicked"].freeze

def initialize
textdomain "network"
super(:wicked)
Expand Down
8 changes: 5 additions & 3 deletions src/modules/Lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,12 @@ def ProposeVirtualized
# @return [Array] of packages needed when writing the config
def Packages
pkgs = []
backend = yast_config&.backend

if yast_config&.backend?(:network_manager)
pkgs << "NetworkManager" if !Package.Installed("NetworkManager")
elsif !Package.Installed("wpa_supplicant")
return pkgs unless backend
backend.packages.each { |p| pkgs << p if !Package.Installed(p) }

if (backend.id == :wicked) && !Package.Installed("wpa_supplicant")
# we have to add wpa_supplicant when wlan is in game, wicked relies on it
wlan_present = yast_config.interfaces.any? do |iface|
iface.type == Y2Network::InterfaceType::WIRELESS
Expand Down
85 changes: 43 additions & 42 deletions test/lan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
require_relative "test_helper"

require "yast"
require "y2network/backend"
require "y2network/config"
require "y2network/config"
require "y2network/routing"
require "y2network/interface_config_builder"
Expand All @@ -33,64 +35,63 @@
subject { Yast::Lan }

let(:system_config) { Y2Network::Config.new(interfaces: [], source: :wicked) }
let(:backend) { :wicked }
let(:backend_id) { :wicked }
let(:backend) { Y2Network::Backend.by_id(backend_id) }

describe "#Packages" do
let(:backend_installed) { false }

let(:yast_config) do
Y2Network::Config.new(source: :autoinst).tap do |config|
config.backend = backend
config.backend = backend_id
end
end

before(:each) do
Yast::Lan.add_config(:yast, yast_config)
allow(Yast::Package).to receive(:Installed).and_return(backend_installed)
end

context "When NetworkManager is not going to be installed" do
context "When wicked is going to be installed" do
let(:wlan0) { Y2Network::Interface.new("wlan0", type: Y2Network::InterfaceType::WIRELESS) }
let(:interfaces) { Y2Network::InterfacesCollection.new([wlan0]) }
let(:config) { double(interfaces: interfaces, backend: backend) }

before(:each) do
allow(Yast::Package)
.to receive(:Installed)
.with("wpa_supplicant")
.at_least(:once)
.and_return(false)

allow(config)
.to receive(:backend?)
.and_return(false)
allow(config)
.to receive(:backend?)
.with(backend)
.and_return(true)
allow(Yast::Lan)
.to receive(:yast_config)
.and_return(config)
end
let(:yast_config) { double(interfaces: interfaces, backend: backend) }

context "and a wlan0 interface is present but wpa_supplicant is not installed" do
before do
allow(Yast::Package)
.to receive(:Installed)
.with("wpa_supplicant")
.at_least(:once)
.and_return(false)

allow(yast_config)
.to receive(:backend?)
.and_return(false)
allow(yast_config)
.to receive(:backend?)
.with(backend_id)
.and_return(true)
end

it "always proposes wpa_supplicant" do
allow(Yast::Package)
.to receive(:Installed)
.with("wpa_supplicant")
.and_return(false)
it "proposes wpa_supplicant to be installed" do
allow(Yast::Package)
.to receive(:Installed)
.with("wpa_supplicant")
.and_return(false)

expect(Yast::Lan.Packages).to include "wpa_supplicant"
expect(Yast::Lan.Packages).to include "wpa_supplicant"
end
end
end

context "When NetworkManager is selected for the target" do
let(:backend) { :network_manager }

it "lists NetworkManager package" do
expect(yast_config).to receive(:backend?).with(:network_manager).and_call_original
expect(Yast::Package)
.to receive(:Installed)
.with("NetworkManager")
.at_least(:once)
.and_return(false)
expect(Yast::Lan.Packages).to include "NetworkManager"
let(:backend_id) { :network_manager }

context "and the NetworkManager package is not installed" do
it "lists NetworkManager package" do
expect(Yast::Lan.Packages).to include "NetworkManager"
end
end
end
end
Expand Down Expand Up @@ -486,12 +487,12 @@
end

describe "#Export" do
let(:backend) { :wicked }
let(:backend_id) { :wicked }
let(:yast_config) do
Y2Network::Config.new(source: :autoinst).tap do |config|
config.hostname.static = "yasties"
config.hostname.dhcp_hostname = :any
config.backend = backend
config.backend = backend_id
end
end

Expand All @@ -509,7 +510,7 @@
end

context "when NetworkManager is the network service" do
let(:backend) { :network_manager }
let(:backend_id) { :network_manager }

it "exports the managed attribute as true" do
expect(subject.Export).to include("managed" => true)
Expand Down

0 comments on commit d4891b3

Please sign in to comment.