Skip to content

Commit

Permalink
Merge pull request #1187 from yast/ay_write_nm_config
Browse files Browse the repository at this point in the history
AutoYaST: write profile config to NM
  • Loading branch information
teclator committed Mar 26, 2021
2 parents f407274 + e806dd5 commit 9a96a0b
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 128 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Mar 18 12:59:31 UTC 2021 - Knut Anderssen <kanderssen@suse.com>

- AutoYaST: Write NetworkManager configuration according to the
profile (bsc#1181701)
- 4.3.62

-------------------------------------------------------------------
Wed Mar 17 18:26:34 UTC 2021 - Knut Anderssen <kanderssen@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.3.61
Version: 4.3.62
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
9 changes: 2 additions & 7 deletions src/lib/network/clients/save_network.rb
Expand Up @@ -346,14 +346,9 @@ def configure_target

# Sets default network service
def set_network_service
if Mode.autoinst
NetworkAutoYast.instance.set_network_service
return
end

log.info("Setting network service according to product preferences")

log.info("Setting target system network service")
backend = Y2Network::ProposalSettings.instance.network_service

# NetworkServices caches the selected backend. That is, it assumes the
# state in the inst-sys and the chroot is the same but that is not true
# at all specially in a live installation where NM is the backend by
Expand Down
16 changes: 8 additions & 8 deletions src/lib/network/network_autoconfiguration.rb
Expand Up @@ -31,16 +31,16 @@ class NetworkAutoconfiguration
include Singleton
include Logger

Yast.import "Lan"
Yast.import "NetworkInterfaces"
Yast.import "NetworkService"
Yast.import "Package"
Yast.import "DNS"
Yast.import "Arch"
Yast.import "Host"

BASH_PATH = Path.new(".target.bash")

def initialize
Yast.import "Lan"
Yast.import "Package"
Yast.import "DNS"
Yast.import "Arch"
Yast.import "Host"
end

# Checks if any of available interfaces is configured and active
#
# returns [Boolean] true when at least one interface is active
Expand Down
29 changes: 10 additions & 19 deletions src/lib/network/network_autoyast.rb
Expand Up @@ -22,6 +22,7 @@
require "y2network/autoinst/s390_devices_reader"
require "y2network/interface_config_builder"
require "y2network/s390_device_activator"
require "y2network/proposal_settings"

module Yast
# Provides functionality for network AutoYaST client(s)
Expand Down Expand Up @@ -72,24 +73,8 @@ def merge_configs(conf)
conf
end

# Sets network service for target
def set_network_service
return if !Mode.autoinst

log.info("Setting network service according to AY profile")

use_network_manager = Lan.yast_config&.backend?(:network_manager)

if use_network_manager && Lan.yast_config.backend.available?
log.info("- using NetworkManager")
else
log.info("- using wicked")
log.warn("- NetworkManager requested but not available") if use_network_manager
Lan.yast_config&.backend = :wicked
end

NetworkService.use(Lan.yast_config&.backend&.id)
NetworkService.EnableDisableNow
def use_network_manager?
Y2Network::ProposalSettings.instance.network_service == :network_manager
end

# Writes the autoyast network configuration according to the already
Expand All @@ -101,7 +86,13 @@ def set_network_service
# @return [Boolean] true when written
def configure_lan
log.info("NetworkAutoYast: Lan configuration")
return false if Lan.autoinst.before_proposal

backend = Y2Network::ProposalSettings.instance.network_service
Yast::Lan.yast_config.backend = backend

# We need to ensure the config translation is written to the target
# system
return false if !use_network_manager? && Lan.autoinst.before_proposal

# force a write only as it is run at the end of the installation and it
# is already chrooted in the target system where restarting services or
Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2network/autoinst/config.rb
Expand Up @@ -36,6 +36,8 @@ class Config
# @return [Boolean] controls whether a bridge configuration for
# virtualization network should be proposed or not
attr_accessor :virt_bridge_proposal
# @return [Boolean] returns whether the network is managed by NM or not
attr_accessor :managed

# Constructor
#
Expand All @@ -53,6 +55,7 @@ def initialize(opts = {})
@keep_install_network = ay_options.fetch(:keep_install_network, true)
@ip_check_timeout = ay_options.fetch(:ip_check_timeout, -1)
@virt_bridge_proposal = ay_options.fetch(:virt_bridge_proposal, true)
@managed = ay_options[:managed]
end

# Return whether the network should be copied at the end
Expand Down
7 changes: 5 additions & 2 deletions src/lib/y2network/autoinst/config_reader.rb
Expand Up @@ -28,7 +28,7 @@
require "y2network/autoinst_profile/networking_section"
require "y2network/wicked/interfaces_reader"

Yast.import "Lan"
Yast.import "Stage"

module Y2Network
module Autoinst
Expand Down Expand Up @@ -70,7 +70,10 @@ def config
end
end

config.backend = section.managed ? :network_manager : :wicked
# During the first stage of an autoinstallation we are not able to
# switch to NetworkManager and in case of setup_before_proposal the
# config should be written to the inst-sys (:wicked).
config.backend = (!Yast::Stage.initial && section.managed) ? :network_manager : :wicked

config
end
Expand Down
20 changes: 14 additions & 6 deletions src/lib/y2network/proposal_settings.rb
Expand Up @@ -42,7 +42,7 @@ def initialize
Yast.import "PackagesProposal"
Yast.import "Lan"

@selected_backend = nil
@selected_backend = autoinst_backend
@virt_bridge_proposal = autoinst_disabled_proposal? ? false : true
end

Expand Down Expand Up @@ -123,12 +123,14 @@ def virtual_proposal_required?
# depending on the backend selected during the proposal and the packages
# installed
def network_service
case current_backend
when :network_manager
network_manager_installed? ? :network_manager : :wicked
else
:wicked
if current_backend == :network_manager
return :network_manager if network_manager_installed?

log.info("NetworkManager is the selected service but it is not installed")
log.info("- using wicked")
end

:wicked
end

class << self
Expand All @@ -149,6 +151,12 @@ def create_instance

private

def autoinst_backend
return if Yast::Lan.autoinst.managed.nil?

Yast::Lan.autoinst.managed ? :network_manager : :wicked
end

# Convenience method to check whether the bridge configuration proposal for
# configuration was disabled in the AutoYaST profile.
def autoinst_disabled_proposal?
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Lan.rb
Expand Up @@ -731,8 +731,7 @@ def read_config
#
# @see Y2Network::ConfigWriter
def write_config(only: nil)
target = :wicked if Mode.auto
yast_config.write(original: system_config, target: target, only: only)
yast_config.write(original: system_config, only: only)
# Force a refresh of the system_config bsc#1162987
add_config(:system, yast_config.copy)
end
Expand Down Expand Up @@ -795,7 +794,8 @@ def autoinst_settings(section)
start_immediately: section.start_immediately,
keep_install_network: section.keep_install_network,
ip_check_timeout: section.strict_ip_check_timeout,
virt_bridge_proposal: section.virt_bridge_proposal
virt_bridge_proposal: section.virt_bridge_proposal,
managed: section.managed
}.reject { |_k, v| v.nil? }
end

Expand Down
2 changes: 1 addition & 1 deletion test/lan_test.rb
Expand Up @@ -554,7 +554,7 @@

it "writes the current yast_config passing the system config as the original" do
expect(Yast::Lan.yast_config).to receive(:write)
.with(original: system_config, target: nil, only: nil)
.with(original: system_config, only: nil)
subject.write_config
end

Expand Down

0 comments on commit 9a96a0b

Please sign in to comment.