Skip to content

Commit

Permalink
Merge pull request #965 from yast/proxy_settings
Browse files Browse the repository at this point in the history
Write proxy settings at the end of the First Stage and export https_proxy
  • Loading branch information
teclator committed Jun 10, 2021
2 parents cb5fac0 + f03cce3 commit 10a0d2d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 12 deletions.
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Jun 8 08:28:28 UTC 2021 - Knut Anderssen <kanderssen@suse.com>

- Export also the https_proxy environment variable when a proxy
config is given through linuxrc (bsc#1185016)
- 4.3.40

-------------------------------------------------------------------
Mon Jun 7 13:19:09 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
6 changes: 3 additions & 3 deletions package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.3.39
Version: 4.3.40
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down Expand Up @@ -77,8 +77,8 @@ Requires: yast2-packager >= 4.2.22
Requires: yast2-bootloader
# use in startup scripts
Requires: initviocons
# Proxy settings for 2nd stage (bnc#764951)
Requires: yast2-proxy
# Use of Proxy.to_target (bsc#1185016).
Requires: yast2-proxy >= 4.3.3
# Systemd default target and services. This version supports
# writing settings in the first installation stage.
Requires: yast2-services-manager >= 3.2.1
Expand Down
30 changes: 21 additions & 9 deletions src/lib/installation/clients/proxy_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
#
module Yast
class ProxyFinishClient < Client
include Yast::Logger

def main
textdomain "installation"

Yast.import "Stage"
Yast.import "Proxy"

@ret = nil
@func = ""
Expand Down Expand Up @@ -63,17 +66,14 @@ def main
"when" => [:installation, :update, :autoinst]
}
elsif @func == "Write"
if Stage.initial
@proxy = Convert.to_string(SCR.Read(path(".etc.install_inf.ProxyURL")))
if write_to_target?
proxy_settings = Proxy.Export

if !@proxy.nil?
Builtins.y2milestone("setting proxy to %1", @proxy)
log.info("Writing proxy settings to the target system: #{proxy_settings.inspect}")

# maybe use Proxy module
SCR.Write(path(".sysconfig.proxy.HTTP_PROXY"), @proxy)
SCR.Write(path(".sysconfig.proxy.FTP_PROXY"), @proxy)
SCR.Write(path(".sysconfig.proxy"), nil)
end
Proxy.Import(proxy_settings)
Proxy.WriteSysconfig
Proxy.WriteCurlrc
end
else
Builtins.y2error("unknown function: %1", @func)
Expand All @@ -84,5 +84,17 @@ def main
Builtins.y2milestone("proxy_finish finished")
deep_copy(@ret)
end

private

# Whether the configuration should be written to the target system or not
#
# @return [Boolean]
def write_to_target?
return false unless Stage.initial

# In case of AutoYaST the configuration could have been imported but not written yet
Proxy.modified || Proxy.to_target
end
end
end
1 change: 1 addition & 0 deletions startup/common/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function set_proxy() {
# ---
if [ "$ProxyURL" ] ; then
export http_proxy="$ProxyURL"
export https_proxy="$ProxyURL"
export ftp_proxy="$ProxyURL"
fi
}
Expand Down
85 changes: 85 additions & 0 deletions test/lib/clients/proxy_finish_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#! /usr/bin/env rspec

require_relative "./../../test_helper"

require "installation/clients/proxy_finish"

describe Yast::ProxyFinishClient do
let(:client) { described_class.new }
let(:func) { "Info" }
let(:parm) { nil }
let(:args) { [] }
let(:func) { args[0] }
let(:parms) { args[1] }

before do
allow(Yast::WFM).to receive(:Args).and_return(args)
allow(Yast::WFM).to receive(:Args).with(0).and_return(args[0])
allow(Yast::WFM).to receive(:Args).with(1).and_return(args[1])
end

context "when the client is called with 'Info' argument" do
let(:args) { ["Info"] }

it "returns a hash" do
expect(client.main).to be_a(Hash)
end

it "returns 1 step with 'Saving proxy configuration...' title" do
result = client.main
expect(result["steps"]).to eql(1)
expect(result["title"]).to eql("Saving proxy configuration...")
end

it "returns that the step is valid for :installation, :update and :autoinst modes" do
expect(client.main["when"]).to include(:installation, :update, :autoinst)
end
end

context "when the client is called with the 'Write' argument" do
let(:initial_stage) { true }
let(:to_target) { false }
let(:modified) { false }
let(:args) { ["Write"] }
let(:config) { { "http_proxy" => "http://proxy.example.com:3128/" } }

before do
allow(Yast::Stage).to receive(:initial).and_return(initial_stage)
allow(Yast::Proxy).to receive(:to_target).and_return(to_target)
allow(Yast::Proxy).to receive(:Export).and_return(config)
allow(Yast::Proxy).to receive(:modified).and_return(modified)
end

context "when running on the first stage" do
context "and the proxy settings were not written to the inst-sys during the installation" do
it "does nothing" do
expect(Yast::Proxy).to_not receive(:WriteSysconfig)
expect(Yast::Proxy).to_not receive(:WriteCurlrc)
client.main
end
end

context "and the proxy settings have been modified but not written yet" do
let(:modified) { true }

it "writes the current sysconfig and curlrc configuration to the target system" do
expect(Yast::Proxy).to receive(:Import).with(config)
expect(Yast::Proxy).to receive(:WriteSysconfig)
expect(Yast::Proxy).to receive(:WriteCurlrc)
client.main
end
end

context "and the proxy settings were written to the inst-sys during the installation" do
let(:to_target) { true }

it "writes the current sysconfig and curlrc configuration to the target system" do
expect(Yast::Proxy).to receive(:Import).with(config)
expect(Yast::Proxy).to receive(:WriteSysconfig)
expect(Yast::Proxy).to receive(:WriteCurlrc)
client.main
end
end
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def stub_module(name)
stub_module("ProfileLocation")
# we cannot depend on this module (circular dependency)
stub_module("NtpClient")
stub_module("Proxy")

if ENV["COVERAGE"]
require "simplecov"
Expand Down

0 comments on commit 10a0d2d

Please sign in to comment.