Skip to content

Commit

Permalink
Merge pull request #727 from yast/proposal_settings
Browse files Browse the repository at this point in the history
Permit to choose between NetworkManger and wicked correctly
  • Loading branch information
teclator committed Feb 19, 2019
2 parents fed3197 + 13e5874 commit 87918f8
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 18 deletions.
10 changes: 10 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Tue Feb 19 09:31:26 UTC 2019 - knut.anderssen@suse.com

- Installation proposal (bsc#1124478, bsc#1124498):
- Do not offer NetworkManager when the package is not available
- Respect the network backend selected in the proposal at the end
of the installation
- Removed the hostname write (127.0.0.2) from the summary
- 4.1.40

-------------------------------------------------------------------
Tue Feb 12 13:21:39 CET 2019 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.1.39
Version: 4.1.40
Release: 0
BuildArch: noarch

Expand Down
19 changes: 15 additions & 4 deletions src/lib/network/clients/network_proposal.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "cgi"
require "installation/proposal_client"
require "y2network/proposal_settings"

module Yast
# Proposal client for Network configuration
Expand Down Expand Up @@ -53,8 +54,10 @@ def ask_user(args)
private

def preformatted_proposal
return lan_summary unless settings.network_manager_available?

proposal_text = switch_backend_link
proposal_text.prepend(Yast::Lan.Summary("proposal")) if wicked_backend?
proposal_text.prepend(lan_summary) if wicked_backend?
proposal_text
end

Expand Down Expand Up @@ -88,22 +91,30 @@ def launch_network_configuration(args)
end

def switch_to_wicked
Yast::NetworkService.use_wicked
settings.enable_wicked!
:next
end

def switch_to_network_manager
Yast::NetworkService.use_network_manager
settings.enable_network_manager!
:next
end

def wicked_backend?
Yast::NetworkService.wicked?
settings.backend != :network_manager
end

# TODO: move to HTML.ycp
def Hyperlink(href, text)
Builtins.sformat("<a href=\"%1\">%2</a>", href, CGI.escapeHTML(text))
end
end

def lan_summary
Yast::Lan.Summary("proposal")
end

def settings
Y2Network::ProposalSettings.instance
end
end
4 changes: 3 additions & 1 deletion src/lib/network/clients/save_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "network/install_inf_convertor"
require "network/network_autoconfiguration"
require "network/network_autoyast"
require "y2network/proposal_settings"

require "cfa/generic_sysconfig"

Expand Down Expand Up @@ -296,7 +297,8 @@ def set_network_service

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

if Lan.UseNetworkManager
case Y2Network::ProposalSettings.instance.backend
when :network_manager
log.info("- using NetworkManager")
NetworkService.use_network_manager
else
Expand Down
129 changes: 129 additions & 0 deletions src/lib/y2network/proposal_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# encoding: utf-8
#
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "y2packager/package"

module Y2Network
# Class that stores the proposal settings for network during installation.
class ProposalSettings
include Yast::Logger
include Yast::I18n

# @return [Boolean] network service to be used after the installation
attr_accessor :backend

# Constructor
def initialize
Yast.import "Arch"
Yast.import "ProductFeatures"
Yast.import "PackagesProposal"
Yast.import "Lan"

@backend = use_network_manager? ? :network_manager : :wicked

log.info("The default proposed network backend is: #{@backend}")

@backend
end

# Adds the NetworkManager package to the {Yast::PackagesProposal} and sets
# NetworkManager as the backend to be used
def enable_network_manager!
Yast::PackagesProposal.AddResolvables("network", :package, ["NetworkManager"])
Yast::PackagesProposal.RemoveResolvables("network", :package, ["wicked"])

log.info "Enabling NetworkManager"
self.backend = :network_manager
end

# Add the wicked package to the {Yast::PackagesProposal} and sets wicked
# as the backend to be used
def enable_wicked!
Yast::PackagesProposal.AddResolvables("network", :package, ["wicked"])
Yast::PackagesProposal.RemoveResolvables("network", :package, ["NetworkManager"])

log.info "Enabling Wicked"
self.backend = :wicked
end

# Convenience method to obtain whether the NetworkManager package is
# available or not.
#
# @return [Boolean] false if no package available, true otherwise
def network_manager_available?
p = Y2Packager::Package.find("NetworkManager").first
if p.nil?
log.info("The NetworkManager package is not available")
return false
end
log.info("The NetworkManager package status: #{p.status}")
true
end

class << self
# Singleton instance
def instance
@instance ||= create_instance
end

# Enforce a new clean instance
def create_instance
@instance = new
end

# Make sure only .instance and .create_instance can be used to
# create objects
private :new, :allocate
end

private

# Convenienve method that verify if Network Manager should be used or not
# according to the control file defaults and package availability.
#
# @return [Boolean] true if should be used; false otherwise
def use_network_manager?
return false unless network_manager_available?

network_manager_default?
end

# Determine whether NetworkManager should be selected by default according
# to the product control file
#
# @return [Boolean] true if NM should be enabled; false otherwise
def network_manager_default?
case Yast::ProductFeatures.GetStringFeature("network", "network_manager")
when ""
# compatibility: use the boolean feature
# (defaults to false)
Yast::ProductFeatures.GetBooleanFeature("network", "network_manager_is_default")
when "always"
true
when "laptop"
laptop = Yast::Arch.is_laptop
log.info("Is a laptop: #{laptop}")
laptop
end
end
end
end
6 changes: 0 additions & 6 deletions src/modules/DNS.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,6 @@ def Summary
)
)
end
if !@write_hostname
summary = Summary.AddListItem(
summary,
_("Hostname will not be written to /etc/hosts")
)
end

# if (has_dhcp && NetworkConfig::DHCP["DHCLIENT_MODIFY_RESOLV_CONF"]:false) {
# Summary text
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def main

# Lan::Read (`cache) will do nothing if initialized already.
@initialized = false

@backend = nil
end

#------------------
Expand Down

0 comments on commit 87918f8

Please sign in to comment.