Skip to content

Commit

Permalink
Merge pull request #1139 from yast/merge-sle-15-sp1
Browse files Browse the repository at this point in the history
Merge SLE-15-SP1
  • Loading branch information
imobachgs committed Feb 10, 2021
2 parents 51ab70f + b4d77b1 commit e914214
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 48 deletions.
6 changes: 3 additions & 3 deletions library/packages/test/y2packager/resolvable_test.rb
Expand Up @@ -28,7 +28,7 @@ def accept_unsigned_file(file, _repo)

# the testing repositories are not signed, temporarily allow using unsigned files
Yast::Pkg.CallbackAcceptUnsignedFile(
Yast::fun_ref(
Yast.fun_ref(
signature_checker.method(:accept_unsigned_file),
"boolean (string, integer)"
)
Expand Down Expand Up @@ -75,8 +75,8 @@ def accept_unsigned_file(file, _repo)
expect(res.size).to eq(2)
# in the same version "15.2-0"
res.each do |r|
expect(r.name) == "SLES"
expect(r.version) == "15.2-0"
expect(r.name).to eq("SLES")
expect(r.version).to eq("15.2-0")
end
end

Expand Down
6 changes: 3 additions & 3 deletions library/system/src/lib/yast2/fs_snapshot.rb
Expand Up @@ -75,8 +75,8 @@ class FsSnapshot
"/usr/bin/snapper --no-dbus --root=%{root} --csvout list-configs " \
"--columns config,subvolume | /usr/bin/grep \"^root,\" >/dev/null".freeze

CREATE_SNAPSHOT_CMD = "/usr/lib/snapper/installation-helper --step 5 --root-prefix=%{root} " \
"--snapshot-type %{snapshot_type} --description %{description}".freeze
CREATE_SNAPSHOT_CMD = "/usr/bin/snapper --no-dbus --root=%{root} create "\
"--type %{snapshot_type} --description %{description}".freeze

LIST_SNAPSHOTS_CMD =
"/usr/bin/snapper --no-dbus --root=%{root} --utc --csvout list --disable-used-space " \
Expand Down Expand Up @@ -331,7 +331,7 @@ def create(snapshot_type, description, previous: nil, cleanup: nil, important: f
out = Yast::SCR.Execute(Yast::Path.new(".target.bash_output"), cmd)

if out["exit"] == 0
find(out["stdout"].to_i) # The CREATE_SNAPSHOT_CMD returns the number of the new snapshot.
all.last
else
log.error "Snapshot could not be created: #{cmd} returned: #{out}"
raise SnapshotCreationFailed
Expand Down
6 changes: 4 additions & 2 deletions library/system/src/lib/yast2/fs_snapshot_store.rb
Expand Up @@ -26,6 +26,8 @@ module Yast2
# Goal of this module is to provide easy to use api to store id of pre
# snapshots, so post snapshots can be then easy to make.
module FsSnapshotStore
class IOError < StandardError; end

# Stores pre snapshot with given id and purpose
# @param[String] purpose of snapshot like "upgrade"
# @raise[RuntimeError] if writing to file failed
Expand All @@ -42,7 +44,7 @@ def self.save(purpose, snapshot_id)
snapshot_id.to_s
)

raise "Failed to write Pre Snapshot id for #{purpose} to store. See logs." unless result
raise IOError, "Failed to write Pre Snapshot id for #{purpose} to store. See logs." unless result
end

# Loads id of pre snapshot for given purpose
Expand All @@ -55,7 +57,7 @@ def self.load(purpose)
snapshot_path(purpose)
)

raise "Failed to read Pre Snapshot id for #{purpose} from store. See logs." if !content || content !~ /^\d+$/
raise IOError, "Failed to read Pre Snapshot id for #{purpose} from store. See logs." if !content || content !~ /^\d+$/

content.to_i
end
Expand Down
6 changes: 3 additions & 3 deletions library/system/test/fs_snapshot_store_test.rb
Expand Up @@ -29,7 +29,7 @@
"42"
).and_return(nil)

expect { described_class.save("test", 42) }.to raise_error(/Failed to write/)
expect { described_class.save("test", 42) }.to raise_error(Yast2::FsSnapshotStore::IOError)
end
end

Expand All @@ -49,7 +49,7 @@
"/var/lib/YaST2/pre_snapshot_test.id"
).and_return(nil)

expect { described_class.load("test") }.to raise_error(/Failed to read/)
expect { described_class.load("test") }.to raise_error(Yast2::FsSnapshotStore::IOError)
end

it "raises exception if file content is not number" do
Expand All @@ -58,7 +58,7 @@
"/var/lib/YaST2/pre_snapshot_test.id"
).and_return("blabla\n")

expect { described_class.load("test") }.to raise_error(/Failed to read/)
expect { described_class.load("test") }.to raise_error(Yast2::FsSnapshotStore::IOError)
end
end

Expand Down
56 changes: 20 additions & 36 deletions library/system/test/fs_snapshot_test.rb
Expand Up @@ -27,7 +27,7 @@ def logger
described_class.log
end

let(:dummy_snapshot) { double("snapshot") }
let(:dummy_snapshot) { double("snapshot", number: 2) }

before do
# reset configured cache
Expand Down Expand Up @@ -168,14 +168,15 @@ def logger
end

describe ".create_single" do
CREATE_SINGLE_SNAPSHOT = "/usr/lib/snapper/installation-helper --step 5 "\
"--root-prefix=/ --snapshot-type single --description some-description".freeze
CREATE_SINGLE_SNAPSHOT = "/usr/bin/snapper --no-dbus "\
"--root=/ create --type single --description some-description".freeze
OPTION_CLEANUP_NUMBER = " --cleanup number".freeze
OPTION_IMPORTANT = " --userdata \"important=yes\"".freeze

before do
allow(Yast2::FsSnapshot).to receive(:configured?).and_return(configured)
allow(Yast2::FsSnapshot).to receive(:create_snapshot?).with(:single).and_return(create_snapshot)
allow(Yast2::FsSnapshot).to receive(:all).and_return([dummy_snapshot])
end

context "when snapper is configured" do
Expand All @@ -190,7 +191,7 @@ def logger
end

context "when snapshot creation fails" do
let(:output) { { "stdout" => "", "exit" => 1 } }
let(:output) { { "exit" => 1 } }

it "logs the error and returns nil" do
expect(logger).to receive(:error).with(/Snapshot could not be created/)
Expand All @@ -200,23 +201,19 @@ def logger
end

context "when snapshot creation is successful" do
let(:output) { { "stdout" => "2", "exit" => 0 } }
let(:output) { { "exit" => 0 } }

it "returns the created snapshot" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_single("some-description")
expect(snapshot).to be(dummy_snapshot)
end
end

context "when a cleanup strategy is set" do
let(:output) { { "stdout" => "2", "exit" => 0 } }
let(:output) { { "exit" => 0 } }
let(:snapshot_command) { CREATE_SINGLE_SNAPSHOT + OPTION_CLEANUP_NUMBER }

it "creates a snapshot with that strategy" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_single("some-description", cleanup: :number)
expect(snapshot).to be(dummy_snapshot)
end
Expand All @@ -227,8 +224,6 @@ def logger
let(:snapshot_command) { CREATE_SINGLE_SNAPSHOT + OPTION_IMPORTANT }

it "creates a snapshot marked as important" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_single("some-description", important: true)
expect(snapshot).to be(dummy_snapshot)
end
Expand All @@ -239,8 +234,6 @@ def logger
let(:snapshot_command) { CREATE_SINGLE_SNAPSHOT + OPTION_IMPORTANT + OPTION_CLEANUP_NUMBER }

it "creates a snapshot with that strategy that is marked as important" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_single("some-description", cleanup: :number, important: true)
expect(snapshot).to be(dummy_snapshot)
end
Expand Down Expand Up @@ -268,12 +261,13 @@ def logger
end

describe ".create_pre" do
CREATE_PRE_SNAPSHOT = "/usr/lib/snapper/installation-helper --step 5 "\
"--root-prefix=/ --snapshot-type pre --description some-description".freeze
CREATE_PRE_SNAPSHOT = "/usr/bin/snapper --no-dbus "\
"--root=/ create --type pre --description some-description".freeze

before do
allow(Yast2::FsSnapshot).to receive(:configured?).and_return(configured)
allow(Yast2::FsSnapshot).to receive(:create_snapshot?).with(:around).and_return(create_snapshot)
allow(Yast2::FsSnapshot).to receive(:all).and_return([dummy_snapshot])
end

context "when snapper is configured" do
Expand All @@ -288,7 +282,7 @@ def logger
end

context "when snapshot creation fails" do
let(:output) { { "stdout" => "", "exit" => 1 } }
let(:output) { { "exit" => 1 } }

it "logs the error and returns nil" do
expect(logger).to receive(:error).with(/Snapshot could not be created/)
Expand All @@ -301,8 +295,6 @@ def logger
let(:output) { { "stdout" => "2", "exit" => 0 } }

it "returns the created snapshot" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_pre("some-description")
expect(snapshot).to be(dummy_snapshot)
end
Expand All @@ -313,8 +305,6 @@ def logger
let(:snapshot_command) { CREATE_PRE_SNAPSHOT + OPTION_CLEANUP_NUMBER }

it "creates a pre snapshot with that strategy" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_pre("some-description", cleanup: :number)
expect(snapshot).to be(dummy_snapshot)
end
Expand All @@ -325,8 +315,6 @@ def logger
let(:snapshot_command) { CREATE_PRE_SNAPSHOT + OPTION_IMPORTANT }

it "creates a pre snapshot marked as important" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_pre("some-description", important: true)
expect(snapshot).to be(dummy_snapshot)
end
Expand All @@ -337,8 +325,6 @@ def logger
let(:snapshot_command) { CREATE_PRE_SNAPSHOT + OPTION_IMPORTANT + OPTION_CLEANUP_NUMBER }

it "creates a pre snapshot with that strategy that is marked as important" do
expect(described_class).to receive(:find).with(2)
.and_return(dummy_snapshot)
snapshot = described_class.create_pre("some-description", important: true, cleanup: :number)
expect(snapshot).to be(dummy_snapshot)
end
Expand Down Expand Up @@ -366,9 +352,9 @@ def logger
end

describe ".create_post" do
CREATE_POST_SNAPSHOT = "/usr/lib/snapper/installation-helper --step 5 "\
"--root-prefix=/ --snapshot-type post --description some-description "\
"--pre-num 2".freeze
CREATE_POST_SNAPSHOT = "/usr/bin/snapper --no-dbus "\
"--root=/ create --type post --description some-description "\
"--pre-num 1".freeze

before do
allow(Yast2::FsSnapshot).to receive(:configured?).and_return(configured)
Expand All @@ -379,29 +365,27 @@ def logger
let(:configured) { true }
let(:create_snapshot) { true }

let(:pre_snapshot) { double("snapshot", snapshot_type: :pre, number: 2) }
let(:pre_snapshot) { double("snapshot", snapshot_type: :pre, number: 1) }
let(:snapshots) { [pre_snapshot] }
let(:output) { { "stdout" => "3", "exit" => 0 } }
let(:output) { { "exit" => 0 } }

before do
allow(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"), CREATE_POST_SNAPSHOT)
.and_return(output)
allow(Yast2::FsSnapshot).to receive(:all)
.and_return(snapshots)
.and_return([pre_snapshot])
allow(Yast2::FsSnapshot).to receive(:all)
.and_return([pre_snapshot, dummy_snapshot])
end

context "when previous snapshot exists" do
let(:snapshots) { [pre_snapshot] }

context "when snapshot creation is successful" do
it "returns the created snapshot" do
allow(Yast2::FsSnapshot).to receive(:find).with(pre_snapshot.number)
.and_return(pre_snapshot)
expect(Yast2::FsSnapshot).to receive(:find).with(3)
.and_return(dummy_snapshot)
expect(described_class.create_post("some-description", pre_snapshot.number))
.to be(dummy_snapshot)
.to eq(dummy_snapshot)
end
end

Expand Down
9 changes: 9 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Wed Feb 10 07:51:10 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Do not use the 'installation-helper' binary to create snapshots
during installation or offline upgrade (bsc#1180142).
- Add a new exception to properly handle exceptions
when reading/writing snapshots numbers (related to bsc#1180142).
- 4.2.92

-------------------------------------------------------------------
Wed Jan 20 09:28:51 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

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


Name: yast2
Version: 4.2.91
Version: 4.2.92

Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit e914214

Please sign in to comment.