Skip to content

Commit

Permalink
Fixed relurl settings (#517)
Browse files Browse the repository at this point in the history
* fixed relurl settings
  • Loading branch information
schubi2 committed Aug 6, 2019
1 parent e8c6b5f commit d50f7a8
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 67 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Aug 5 15:38:18 CEST 2019 - schubi@suse.de

- Fixed downloading of AutoYaST configuration file with "relurl"
(bsc#1138117).
- 4.2.6

-------------------------------------------------------------------
Thu Jul 18 15:05:10 UTC 2019 - Jan Engelhardt <jengelh@inai.de>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.2.5
Version: 4.2.6
Release: 0
Summary: YaST2 - Automated Installation
License: GPL-2.0-only
Expand Down
17 changes: 17 additions & 0 deletions src/modules/AutoinstConfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,23 @@ def ParseCmdLine(profile_location)
@user = parsed_url["user"] || ""
@pass = parsed_url["pass"] || ""

if @scheme == "relurl" || @scheme == "file"
# "relurl": No host information has been given here. So a part of the path or the
# complete path has been stored in the host variable while parsing it.
# This will be reverted.
#
# "file": Normally the file is defined with 3 slashes like file:///autoinst.xml
# in order to define an empty host entry. But that will be often overseen
# by the user. So we will support file://autoinst.xml too:
log.info "correcting #{@scheme}://#{@host}/#{@filepath} to empty host entry"
if !@host.empty? && !@filepath.empty?
@filepath = File.join( @host, @filepath)
else
@filepath = @host unless @host.empty?
end
@host = ""
end

@remoteProfile = !["default", "file", "floppy", "usb", "device"].include?(@scheme)

log.info "urltok = #{URL.HidePassword(profile_location)}"
Expand Down
83 changes: 17 additions & 66 deletions src/modules/ProfileLocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def main
Yast.import "Report"
Yast.import "Label"
Yast.import "URL"
Yast.import "InstURL"

Yast.include self, "autoinstall/autoinst_dialogs.rb"
Yast.include self, "autoinstall/io.rb"
Expand Down Expand Up @@ -57,76 +58,26 @@ def Process
is_directory = false

if AutoinstConfig.scheme == "relurl"
# FIXME:
# file # local file
url_str = InstURL.installInf2Url("")
log.info( "installation path from install.inf: #{url_str}" )

AutoinstConfig.scheme = Convert.to_string(
SCR.Read(path(".etc.install_inf.InstMode"))
)
if AutoinstConfig.scheme == "hd" || AutoinstConfig.scheme == "harddisk" ||
AutoinstConfig.scheme == "disk"
part = Convert.to_string(SCR.Read(path(".etc.install_inf.Partition")))
AutoinstConfig.scheme = "device"
AutoinstConfig.host = part
AutoinstConfig.filepath = Ops.add(
Ops.add(
Convert.to_string(SCR.Read(path(".etc.install_inf.Serverdir"))),
"/"
),
AutoinstConfig.filepath
)
else
if AutoinstConfig.scheme == "cd" || AutoinstConfig.scheme == "cdrom"
if !url_str.empty?
url = URL.Parse(url_str)
AutoinstConfig.scheme = url["scheme"]
AutoinstConfig.host = url["host"]
AutoinstConfig.filepath = File.join( url["path"], AutoinstConfig.filepath)

if ["cd", "cdrom"].include? AutoinstConfig.scheme
AutoinstConfig.scheme = "file"
end
if Ops.greater_than(Builtins.size(AutoinstConfig.filepath), 0)
AutoinstConfig.filepath = Ops.add(
Ops.add(
Ops.add(
Ops.add(
Convert.to_string(
SCR.Read(path(".etc.install_inf.Serverdir"))
),
"/"
),
AutoinstConfig.host
),
"/"
),
AutoinstConfig.filepath
)
else
AutoinstConfig.filepath = Ops.add(
Ops.add(
Convert.to_string(SCR.Read(path(".etc.install_inf.Serverdir"))),
"/"
),
AutoinstConfig.host
)
end
if Convert.to_string(SCR.Read(path(".etc.install_inf.Server"))) != nil
AutoinstConfig.host = Convert.to_string(
SCR.Read(path(".etc.install_inf.Server"))
)
end
end

Builtins.y2milestone(
"relurl for profile changed to: %1://%2%3",
AutoinstConfig.scheme,
AutoinstConfig.host,
AutoinstConfig.filepath
)
SCR.Write(
path(".etc.install_inf.ayrelurl"),
Builtins.sformat(
"%1://%2/%3",
AutoinstConfig.scheme,
AutoinstConfig.host,
AutoinstConfig.filepath
)
)
SCR.Write(path(".etc.install_inf"), nil)
ayrelurl = "#{AutoinstConfig.scheme}://#{AutoinstConfig.host}/#{AutoinstConfig.filepath}"
log.info( "relurl for profile changed to: #{ayrelurl}" )
SCR.Write( path(".etc.install_inf.ayrelurl"), ayrelurl )
SCR.Write(path(".etc.install_inf"), nil)
else
log.warn( "Cannot evaluate ZyppRepoURL from /etc/install.inf" )
end
elsif AutoinstConfig.scheme == "label"
# autoyast=label://my_home//autoinst.xml in linuxrc:
# AY is searching for a partition with the label "my_home". This partition
Expand Down
64 changes: 64 additions & 0 deletions test/AutoinstConfig_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,70 @@
expect(subject.pass).to eq("woo")
end
end

context "when \"relurl\" is defined" do
let(:autoyast_profile_url) { "relurl://auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("relurl")
expect(subject.filepath).to eq("auto-installation.xml")
end
end

context "when \"relurl\" is defined and sub-pathes are defined" do
let(:autoyast_profile_url) { "relurl://sub_path/auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("relurl")
expect(subject.filepath).to eq("sub_path/auto-installation.xml")
end
end

context "when \"file:\/\/\" is defined" do
context "when no sub path is defined" do
let(:autoyast_profile_url) { "file://auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("file")
expect(subject.filepath).to eq("auto-installation.xml")
end
end

context "when sub path is defined" do
let(:autoyast_profile_url) { "file://sub-path/auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("file")
expect(subject.filepath).to eq("sub-path/auto-installation.xml")
end
end
end

context "when \"file:///\" is defined (old format)" do
context "when no sub path is defined" do
let(:autoyast_profile_url) { "file:///auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("file")
expect(subject.filepath).to eq("/auto-installation.xml")
end
end

context "when sub path is defined" do
let(:autoyast_profile_url) { "file:///sub-path/auto-installation.xml" }
it "sets host and filename correctly" do
expect(subject.ParseCmdLine(autoyast_profile_url)).to eq(true)
expect(subject.host).to eq("")
expect(subject.scheme).to eq("file")
expect(subject.filepath).to eq("/sub-path/auto-installation.xml")
end
end
end
end

describe "#profile_path" do
Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TESTS = \
AutoinstGeneral_test.rb \
AutoinstPartPlan_test.rb \
AutoinstSoftware_test.rb \
ProfileLocation_test.rb \
autoinst_storage_test.rb \
profile_test.rb \
Y2ModuleConfig_test.rb \
Expand Down
31 changes: 31 additions & 0 deletions test/ProfileLocation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env rspec

require_relative "test_helper"

Yast.import "ProfileLocation"

describe "Yast::ProfileLocation" do

subject { Yast::ProfileLocation }

describe "#Process" do

context "when scheme is \"relurl\"" do
before do
Yast::AutoinstConfig.scheme = "relurl"
Yast::AutoinstConfig.xml_tmpfile = "/tmp/123"
Yast::AutoinstConfig.filepath = "autoinst.xml"
allow(Yast::InstURL).to receive(:installInf2Url).and_return(
"http://download.opensuse.org/distribution/leap/15.1/repo/oss/")
end

it "downloads AutoYaST configuration file with absolute path" do
expect(subject).to receive(:Get).with("http",
"download.opensuse.org",
"/distribution/leap/15.1/repo/oss/autoinst.xml",
"/tmp/123")
subject.Process
end
end
end
end

0 comments on commit d50f7a8

Please sign in to comment.