Skip to content

Commit

Permalink
Merge pull request #785 from yast/reboot_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jul 20, 2021
2 parents 799705b + a64b99b commit c8576e3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
8 changes: 8 additions & 0 deletions package/autoyast2.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Tue Jul 20 14:45:51 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

- Fixed handling of the "final_reboot" and "final_halt" options,
add the custom scripts only once and avoid displaying
a warning popup during installation (bsc#1188356)
- 4.3.88

-------------------------------------------------------------------
Fri Jul 16 15:27:30 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.3.87
Version: 4.3.88
Release: 0
Summary: YaST2 - Automated Installation
License: GPL-2.0-only
Expand Down
30 changes: 18 additions & 12 deletions src/modules/Profile.rb
Expand Up @@ -131,11 +131,9 @@ def generalCompat
Builtins.remove(Ops.get_map(@current, "general", {}), "clock")
)
end
if Ops.get_boolean(@current, ["general", "mode", "final_halt"], false)
script = {
"filename" => "zzz_halt",
"source" => "shutdown -h now"
}
if Ops.get_boolean(@current, ["general", "mode", "final_halt"], false) &&
!Ops.get_list(@current, ["scripts", "init-scripts"], []).include?(HALT_SCRIPT)

Ops.set(@current, "scripts", {}) if !Builtins.haskey(@current, "scripts")
if !Builtins.haskey(
Ops.get_map(@current, "scripts", {}),
Expand All @@ -148,15 +146,13 @@ def generalCompat
["scripts", "init-scripts"],
Builtins.add(
Ops.get_list(@current, ["scripts", "init-scripts"], []),
script
HALT_SCRIPT
)
)
end
if Ops.get_boolean(@current, ["general", "mode", "final_reboot"], false)
script = {
"filename" => "zzz_reboot",
"source" => "shutdown -r now"
}
if Ops.get_boolean(@current, ["general", "mode", "final_reboot"], false) &&
!Ops.get_list(@current, ["scripts", "init-scripts"], []).include?(REBOOT_SCRIPT)

Ops.set(@current, "scripts", {}) if !Builtins.haskey(@current, "scripts")
if !Builtins.haskey(
Ops.get_map(@current, "scripts", {}),
Expand All @@ -169,7 +165,7 @@ def generalCompat
["scripts", "init-scripts"],
Builtins.add(
Ops.get_list(@current, ["scripts", "init-scripts"], []),
script
REBOOT_SCRIPT
)
)
end
Expand Down Expand Up @@ -658,6 +654,16 @@ def needed_second_stage_packages

private

REBOOT_SCRIPT = {
"filename" => "zzz_reboot",
"source" => "shutdown -r now"
}.freeze

HALT_SCRIPT = {
"filename" => "zzz_halt",
"source" => "shutdown -h now"
}.freeze

def add_autoyast_packages
@current["software"] ||= {}
@current["software"]["packages"] ||= []
Expand Down
37 changes: 37 additions & 0 deletions test/profile_test.rb
Expand Up @@ -28,6 +28,12 @@ def patterns_list
items_list("patterns")
end

def reboot_scripts
Yast::Profile.current["scripts"]["init-scripts"].select do |s|
s["filename"] == "zzz_reboot"
end
end

describe "#softwareCompat" do
before do
Yast::Profile.current = profile
Expand Down Expand Up @@ -120,6 +126,37 @@ def patterns_list
end
end

describe "#generalCompat" do
before do
Yast::Profile.current = profile
end

context "when a custom reboot script is not present" do
let(:profile) { { "general" => { "mode" => { "final_reboot" => true } } } }

it "adds a reboot script for the 'final_reboot' flag" do
Yast::Profile.generalCompat
expect(reboot_scripts).to_not be_empty
end
end

# the first stage adds a custom script for the "final_reboot" flag,
# ensure the second stage does not add it again (bsc#1188356)
context "when a custom reboot script is present" do
let(:profile) do
{ "general" => { "mode" => { "final_reboot" => true } },
"scripts" => { "init-scripts" => [
{ "filename" => "zzz_reboot", "source" => "shutdown -r now" }
] } }
end

it "does not duplicate the reboot script" do
Yast::Profile.generalCompat
expect(reboot_scripts.size).to eq(1)
end
end
end

describe "#Import" do
let(:profile) { {} }

Expand Down

0 comments on commit c8576e3

Please sign in to comment.