Skip to content

Commit

Permalink
Merge pull request #533 from yast/relnotes-ay-master
Browse files Browse the repository at this point in the history
Really use directory.yast
  • Loading branch information
mvidner committed Mar 8, 2017
2 parents 146c8ee + 7c36a09 commit 7dd20a0
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 56 deletions.
6 changes: 6 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Mar 8 16:11:59 CET 2017 - mvidner@suse.cz

- Really use the directory.yast file (fate#322372)
- 3.2.26

-------------------------------------------------------------------
Thu Mar 6 13:33:41 UTC 2017 - mfilka@suse.com

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


Name: yast2-installation
Version: 3.2.25
Version: 3.2.26
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
115 changes: 63 additions & 52 deletions src/lib/installation/clients/inst_download_release_notes.rb
Expand Up @@ -38,54 +38,33 @@ class InstDownloadReleaseNotesClient < Client
28 => "Operation timeout."
}.freeze

# Download of index of release notes for a specific product
# @param url_base URL pointing to directory with the index
# @param proxy the proxy URL to be passed to curl
# Download *url* to *filename*
# May set InstData.stop_relnotes_download on download failure.
#
# @return true when successful
def download_release_notes_index(url_base, proxy)
url_index = url_base + "/directory.yast2"
log.info("Index with available files: #{url_index}")
filename = Builtins.sformat("%1/directory.yast", SCR.Read(path(".target.tmpdir")))
# download the index with much shorter time-out
# @return [Boolean,nil] true: success, false: failure, nil: failure+dont retry
def curl_download(url, filename, proxy_args:, max_time: 300)
cmd = Builtins.sformat(
"/usr/bin/curl --location --verbose --fail --max-time 30 --connect-timeout 15 %1 '%2' --output '%3' > '%4/%5' 2>&1",
proxy,
url_index,
"/usr/bin/curl --location --verbose --fail --max-time %6 --connect-timeout 15 %1 '%2' --output '%3' > '%4/%5' 2>&1",
proxy_args,
url,
String.Quote(filename),
String.Quote(Directory.logdir),
"curl_log"
"curl_log",
max_time
)
ret = SCR.Execute(path(".target.bash"), cmd)
log.info("Downloading release notes index: #{cmd} returned #{ret}")
if ret == 0
log.info("Release notes index downloaded successfully")
index_file = File.read(filename)
if index_file.nil? || index_file.empty?
log.info("Release notes index empty, not filtering further downloads")
return nil
else
rn_filter = index_file.split("\n")
log.info("Index of RN files at the server: #{rn_filter}")
return rn_filter
end
elsif CURL_GIVE_UP_RETURN_CODES.key? ret
log.info "Communication with server for release notes download failed ( #{CURL_GIVE_UP_RETURN_CODES[ret]} ), skipping further attempts."
log.info("#{cmd} returned #{ret}")
reason = CURL_GIVE_UP_RETURN_CODES[ret]
if !reason.nil?
log.info "Communication with server failed (#{reason}), skipping further attempts."
InstData.stop_relnotes_download = true
return nil
else
log.info "Downloading index failed, trying all files according to selected language"
return nil
end
ret == 0
end

# Download all release notes mentioned in Product::relnotesurl_all
#
# @return true when successful
def download_release_notes
filename_templ = UI.TextMode ? "/RELEASE-NOTES.%1.txt" : "/RELEASE-NOTES.%1.rtf"

# Get proxy settings (if any)
# @return [String] to be interpolated in a .target.bash command, unquoted
def curl_proxy_args
proxy = ""
# proxy should be set by inst_install_inf if set via Linuxrc
Proxy.Read
Expand All @@ -107,6 +86,49 @@ def download_release_notes
proxy << " --proxy-user '#{user_pass}'" unless user_pass.empty?
end
end
proxy
end

# Download of index of release notes for a specific product
# @param url_base URL pointing to directory with the index
# @param proxy the proxy URL to be passed to curl
#
# May set InstData.stop_relnotes_download on download failure.
# @return [Array<String>,nil] filenames, nil if not found
def download_release_notes_index(url_base, proxy)
url_index = url_base + "/directory.yast"
log.info("Index with available files: #{url_index}")
filename = Builtins.sformat("%1/directory.yast", SCR.Read(path(".target.tmpdir")))
# download the index with much shorter time-out
ok = curl_download(url_index, filename, proxy_args: proxy, max_time: 30)

if ok
log.info("Release notes index downloaded successfully")
index_file = File.read(filename)
if index_file.nil? || index_file.empty?
log.info("Release notes index empty, not filtering further downloads")
return nil
else
rn_filter = index_file.split("\n")
log.info("Index of RN files at the server: #{rn_filter}")
return rn_filter
end
elsif ok.nil?
return nil
else
log.info "Downloading index failed, trying all files according to selected language"
return nil
end
end

# Download release notes for all selected and installed products
#
# @return true when successful
def download_release_notes
filename_templ = UI.TextMode ? "/RELEASE-NOTES.%1.txt" : "/RELEASE-NOTES.%1.rtf"

# Get proxy settings (if any)
proxy = curl_proxy_args

# installed may mean old (before upgrade) in initial stage
# product may not yet be selected although repo is already added
Expand Down Expand Up @@ -166,24 +188,13 @@ def download_release_notes
end

# download release notes now
cmd = Builtins.sformat(
"/usr/bin/curl --location --verbose --fail --max-time 300 --connect-timeout 15 %1 '%2' --output '%3' > '%4/%5' 2>&1",
proxy,
url,
String.Quote(filename),
String.Quote(Directory.logdir),
"curl_log"
)
ret = SCR.Execute(path(".target.bash"), cmd)
log.info("Downloading release notes: #{cmd} returned #{ret}")
if ret == 0
ok = curl_download(url, filename, proxy_args: proxy)
if ok
log.info("Release notes downloaded successfully")
InstData.release_notes[product["short_name"]] = SCR.Read(path(".target.string"), filename)
InstData.downloaded_release_notes << product["short_name"]
break
elsif CURL_GIVE_UP_RETURN_CODES.key? ret
log.info "Communication with server for release notes download failed ( #{CURL_GIVE_UP_RETURN_CODES[ret]} ), skipping further attempts."
InstData.stop_relnotes_download = true
elsif ok.nil?
break
else
InstData.failed_release_notes << url
Expand All @@ -206,14 +217,14 @@ def init_ui

def main
Yast.import "UI"
Yast.import "Product"
Yast.import "Language"
Yast.import "Proxy"
Yast.import "Directory"
Yast.import "InstData"
Yast.import "Stage"
Yast.import "GetInstArgs"
Yast.import "Wizard"
Yast.import "Mode"

textdomain "installation"

Expand Down
57 changes: 56 additions & 1 deletion test/lib/inst_download_release_notes_test.rb 100644 → 100755
Expand Up @@ -59,6 +59,17 @@
expect(client.main).to eq(:auto)
end

context "when running AutoYaST" do
before do
allow(Yast::Mode).to receive(:auto).and_return(true)
end

it "does not download the release notes" do
expect(client).to_not receive(:download_release_notes)
client.main
end
end

context "when release notes are downloaded correctly" do
let(:curl_code) { 0 }

Expand Down Expand Up @@ -166,7 +177,7 @@

context "when called twice" do
let(:language) { "en" }
let(:curl_code) { 22 }
let(:curl_code) { CURL_NOT_FOUND_CODE }

it "does not try to download again already failed release notes" do
expect(Yast::SCR).to receive(:Execute).once
Expand All @@ -185,4 +196,48 @@
end
end
end

describe "#curl_proxy_args" do
before do
stub_const("Yast::Proxy", double("proxy"))
allow(Yast::Proxy).to receive(:Read)
end

it "returns an empty string when no proxy is needed" do
expect(Yast::Proxy).to receive(:enabled).and_return(false)
expect(client.curl_proxy_args).to eq ""
end

context "when a proxy is needed " do
before do
expect(Yast::Proxy).to receive(:enabled).and_return(true)
expect(Yast::Proxy).to receive(:http).twice
.and_return("http://proxy.example.com")
test = {
"HTTP" => {
"tested" => true,
"exit" => 0
}
}
expect(Yast::Proxy).to receive(:RunTestProxy).and_return(test)

end

it "returns correct args for an unauthenticated proxy" do
allow(Yast::Proxy).to receive(:user).and_return("")
allow(Yast::Proxy).to receive(:pass).and_return("")

expect(client.curl_proxy_args)
.to eq "--proxy http://proxy.example.com"
end

it "returns correct args for an authenticated proxy" do
allow(Yast::Proxy).to receive(:user).and_return("baggins")
allow(Yast::Proxy).to receive(:pass).and_return("thief")

expect(client.curl_proxy_args)
.to eq "--proxy http://proxy.example.com --proxy-user 'baggins:thief'"
end
end
end
end
2 changes: 1 addition & 1 deletion test/ssh_config_test.rb
@@ -1,4 +1,4 @@
#! /usr/bin/rspec
#! /usr/bin/env rspec
# Copyright (c) 2016 SUSE LLC.
# All Rights Reserved.

Expand Down
2 changes: 1 addition & 1 deletion test/ssh_importer_test.rb
@@ -1,4 +1,4 @@
#! /usr/bin/rspec
#! /usr/bin/env rspec
# Copyright (c) 2016 SUSE LLC.
# All Rights Reserved.

Expand Down
Empty file modified test/system_role_handlers_test.rb 100644 → 100755
Empty file.

0 comments on commit 7dd20a0

Please sign in to comment.