Skip to content

Commit

Permalink
Ensure closing the opened SCR instance and do some more test mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
dzedro committed Apr 29, 2021
1 parent 689c966 commit 6a28935
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
43 changes: 27 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
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
6 changes: 5 additions & 1 deletion package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
-------------------------------------------------------------------
Tue Apr 27 13:24:40 CEST 2021 - Jozef Pupava <jpupava@suse.com>
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

-------------------------------------------------------------------
Expand Down

0 comments on commit 6a28935

Please sign in to comment.