Skip to content

Commit

Permalink
Merge pull request #1159 from dzedro/reboot_timeout
Browse files Browse the repository at this point in the history
Use linuxrc option reboot_timeout to configure the timeout before reboot
  • Loading branch information
teclator committed Apr 29, 2021
2 parents 166f96d + 6a28935 commit 793a453
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 29 deletions.
50 changes: 34 additions & 16 deletions library/general/src/modules/Linuxrc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,33 @@ def main
def ReadInstallInf
return if !@install_inf.nil?

@install_inf = {}
# don't read anything if the file doesn't exist
if SCR.Read(path(".target.size"), "/etc/install.inf") == -1
Builtins.y2error("Reading install.inf, but file doesn't exist!!!")
return
end
entries = SCR.Dir(path(".etc.install_inf"))
if entries.nil?
Builtins.y2error("install.inf is empty")
return
end
Builtins.foreach(entries) do |e|
val = Convert.to_string(
SCR.Read(Builtins.add(path(".etc.install_inf"), e))
)
Ops.set(@install_inf, e, val)
# skip from chroot
old_SCR = WFM.SCRGetDefault
new_SCR = WFM.SCROpen("chroot=/:scr", false)
WFM.SCRSetDefault(new_SCR)

begin
@install_inf = {}
# don't read anything if the file doesn't exist
if SCR.Read(path(".target.size"), "/etc/install.inf") == -1
Builtins.y2error("Reading install.inf, but file doesn't exist!!!")
return
end
entries = SCR.Dir(path(".etc.install_inf"))
if entries.nil?
Builtins.y2error("install.inf is empty")
return
end
Builtins.foreach(entries) do |e|
val = Convert.to_string(
SCR.Read(Builtins.add(path(".etc.install_inf"), e))
)
Ops.set(@install_inf, e, val)
end
ensure
# close and chroot back
WFM.SCRSetDefault(old_SCR)
WFM.SCRClose(new_SCR)
end

nil
Expand Down Expand Up @@ -142,6 +153,12 @@ def text
InstallInf("Textmode") == "1"
end

def reboot_timeout
return nil unless InstallInf("reboot_timeout")

InstallInf("reboot_timeout").to_i
end

# end of install.inf reading routines

# Write /etc/yast.inf during installation
Expand Down Expand Up @@ -287,6 +304,7 @@ def disable_remote(services)
publish function: :keys, type: "list <string> ()"
publish function: :value_for, type: "string (string)"
publish function: :disable_remote, type: "list <string> ()"
publish function: :reboot_timeout, type: "integer ()"

private

Expand Down
12 changes: 12 additions & 0 deletions library/general/test/linuxrc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,16 @@ def load_install_inf(defaults_replacement = {})
end
end
end

describe "#reboot_timeout" do
it "returns integer value if 'reboot_timeout' is found in install.inf" do
load_install_inf("reboot_timeout" => "15")
expect(subject.reboot_timeout).to eq(15)
end

it "returns nil if 'reboot_timeout' is not found in install.inf" do
load_install_inf({})
expect(subject.reboot_timeout).to eq(nil)
end
end
end
25 changes: 13 additions & 12 deletions library/system/test/fs_snapshot_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,23 @@

described_class.clean("test")
end
end

context "in initial stage before SCR switched" do
it "use path on mounted target system" do
Yast.import "Installation"
Yast::Installation.destdir = "/mnt"
context "in initial stage before SCR switched" do
it "use path on mounted target system" do
Yast.import "Installation"
Yast::Installation.destdir = "/mnt"

Yast.import "Stage"
allow(Yast::Stage).to receive(:initial).and_return(true)
Yast.import "Stage"
allow(Yast::Stage).to receive(:initial).and_return(true)
allow(Yast::WFM).to receive(:scr_chrooted?).and_return(false)

expect(Yast::SCR).to receive(:Execute).with(
path(".target.remove"),
"/mnt/var/lib/YaST2/pre_snapshot_test.id"
)
expect(Yast::SCR).to receive(:Execute).with(
path(".target.remove"),
"/mnt/var/lib/YaST2/pre_snapshot_test.id"
)

described_class.clean("test")
described_class.clean("test")
end
end
end
end
5 changes: 5 additions & 0 deletions library/system/test/fs_snapshot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def logger
end

describe ".configured?" do
let(:chrooted) { true }

before do
allow(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"), FIND_CONFIG)
.and_return("stdout" => "", "exit" => find_code)
allow(Yast::WFM).to receive(:scr_chrooted?).and_return chrooted
end

context "when snapper's configuration does not exist" do
Expand All @@ -44,6 +47,8 @@ def logger
end

context "in initial stage before scr switched" do
let(:chrooted) { false }

let(:find_code) { 0 }
before do
Yast.import "Installation"
Expand Down
11 changes: 11 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-------------------------------------------------------------------
Thu Apr 29 13:24:40 CEST 2021 - Jozef Pupava <jpupava@suse.com>

- Add linuxrc option "reboot_timeout" to configure the timeout
before reboot (bsc#1122493 poo#89716)
- Linuxrc: Ensure the new opened SCR instace is closed when reading
the /etc/install.inf file (bsc#1122493, bsc#1157476)
- Ensure /etc/install.inf is not read from the target system but
from the local one. (bsc#1122493, bsc#1157476)
- 4.1.81

-------------------------------------------------------------------
Mon Dec 21 10:27:21 UTC 2020 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

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


Name: yast2
Version: 4.1.80
Version: 4.1.81

Release: 0
Summary: YaST2 - Main Package
Expand Down

0 comments on commit 793a453

Please sign in to comment.