Skip to content

Commit

Permalink
Added proposal settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Feb 15, 2019
1 parent 0c7c531 commit 6cbabbc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
11 changes: 8 additions & 3 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 @@ -88,22 +89,26 @@ 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 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
76 changes: 76 additions & 0 deletions src/lib/y2network/proposal_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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"

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

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

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

@backend = Yast::Lan.UseNetworkManager ? :network_manager : :wicked
end

# Services

# Add the NetworkManager package to be installed and sets NetworkManager as
# the backend to be used
def enable_network_manager!
Yast::PackagesProposal.AddResolvables("NetworkManager", :package, ["NetworkManager"])

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

def enable_wicked!
Yast::PackagesProposal.AddResolvables("wicked", :package, ["wicked"])

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

class << self
# Singleton instance
def instance
create_instance unless @instance
@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
end
end
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
10 changes: 6 additions & 4 deletions test/network_proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
let(:proposal) { subject.make_proposal({}) }

before do
allow(Yast::NetworkService).to receive(:wicked?).and_return(using_wicked)
allow(Yast::Lan).to receive(:UseNetworkManager).and_return(!using_wicked)
Y2Network::ProposalSettings.create_instance
end

it "returns a hash describing the proposal" do
Expand Down Expand Up @@ -63,6 +64,7 @@
end

describe "#ask_user" do
let(:settings) { Y2Network::ProposalSettings.instance }
let(:chosen_id) { "" }
let(:args) do
{
Expand Down Expand Up @@ -103,8 +105,8 @@
expect(Yast::WFM).to_not receive(:CallFuntion).with("inst_lan", anything)
end

it "changes the netwotk backend to wicked" do
expect(Yast::NetworkService).to receive(:use_wicked)
it "changes the network backend to wicked" do
expect(settings).to receive(:enable_wicked!)

subject.ask_user(args)
end
Expand All @@ -122,7 +124,7 @@
end

it "changes the netwotk backend to NetworkManager" do
expect(Yast::NetworkService).to receive(:use_network_manager)
expect(settings).to receive(:enable_network_manager!)

subject.ask_user(args)
end
Expand Down

0 comments on commit 6cbabbc

Please sign in to comment.