Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into improve_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 6, 2020
2 parents a38a873 + 7e29861 commit ef4d883
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 16 deletions.
9 changes: 9 additions & 0 deletions package/autoyast2.changes
Expand Up @@ -7,6 +7,15 @@ Wed May 6 14:59:26 UTC 2020 - Josef Reidinger <jreidinger@suse.com>
-- Add type specification with 't' shortcut
- 4.3.0

-------------------------------------------------------------------
Wed May 6 08:47:13 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

- ayast_setup: Do not add a 'networking' section to the profile
when it is not defined explicitly as it is not needed anymore
since keeping the configured network is the default option during
autoconfiguration (bsc#1170821)
- 4.2.35

-------------------------------------------------------------------
Tue Apr 1 11:51:35 UTC 2020 - schubi@suse.de

Expand Down
29 changes: 14 additions & 15 deletions src/lib/autoinstall/clients/ayast_setup.rb
Expand Up @@ -34,6 +34,8 @@ module Y2Autoinstall
module Clients
module AyastSetup
include Yast::Logger
include Yast::I18n

Ops = Yast::Ops
SCR = Yast::SCR
WFM = Yast::WFM
Expand All @@ -57,6 +59,7 @@ def Setup
["software", "post-packages"],
[]
)

postPackages = Builtins.filter(postPackages) do |p|
!Yast::PackageSystem.Installed(p)
end
Expand All @@ -68,27 +71,13 @@ def Setup
[]
)

# the following is needed since 10.3
# otherwise the already configured network gets removed
if !Builtins.haskey(Profile.current, "networking")
Profile.current = Builtins.add(
Profile.current,
"networking",
"keep_install_network" => true
)
end

if @dopackages
Yast::Pkg.TargetInit("/", false)
WFM.CallFunction("inst_rpmcopy", [])
end
WFM.CallFunction("inst_autoconfigure", [])

# Restarting autoyast-initscripts.service in order to run
# init-scripts in the installed system.
cmd = "systemctl restart autoyast-initscripts.service"
ret = SCR.Execute(path(".target.bash_output"), cmd)
log.info "command \"#{cmd}\" returned #{ret}"
restart_initscripts
nil
end

Expand Down Expand Up @@ -119,6 +108,16 @@ def openFile(options)
Setup()
true
end

private

def restart_initscripts
# Restarting autoyast-initscripts.service in order to run
# init-scripts in the installed system.
cmd = "systemctl restart autoyast-initscripts.service"
ret = SCR.Execute(path(".target.bash_output"), cmd)
log.info "command \"#{cmd}\" returned #{ret}"
end
end
end
end
82 changes: 81 additions & 1 deletion test/lib/clients/ayast_setup_test.rb
Expand Up @@ -21,7 +21,23 @@
require_relative "../../test_helper"
require "autoinstall/clients/ayast_setup"

describe Y2Autoinstall::Clients::AyastSetup do
require "yast"

module Yast
class DummyClient < Module
include Y2Autoinstall::Clients::AyastSetup
attr_accessor :dopackages
end
end

Yast.import "Profile"

describe "Y2Autoinstall::Clients::AyastSetup" do
let(:subject) { Yast::DummyClient.new }
let(:profile) { { "software" => { "post-packages" => packages } } }
let(:packages) { ["vim"] }
let(:dopackages) { false }

let(:client) do
instance_double(Y2Autoinstall::Clients::AyastSetup, Setup: true)
end
Expand All @@ -31,4 +47,68 @@
expect(client.Setup).to eq true
end
end

describe "#Setup" do
before do
Yast::Profile.current = profile
allow(Yast::AutoInstall).to receive(:Save)
allow(Yast::WFM).to receive(:CallFunction)
allow(Yast::Mode).to receive(:SetMode)
allow(Yast::Stage).to receive(:Set)
allow(Yast::PackageSystem).to receive(:Installed).and_return(true)
allow(Yast::Pkg).to receive(:TargetInit)
allow(subject).to receive(:restart_initscripts)
subject.dopackages = dopackages
end

it "saves the current profile if modified" do
expect(Yast::AutoInstall).to receive(:Save)

subject.Setup
end

it "calls the inst_autopost client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_autopost", [])

subject.Setup
end

context "when dopackages is enabled" do
let(:dopackages) { true }

it "installs given post installation packages / patterns when not installed yet" do
expect(Yast::PackageSystem).to receive(:Installed).and_return(false)
expect(Yast::AutoinstSoftware).to receive(:addPostPackages).with(["vim"])
expect(Yast::WFM).to receive(:CallFunction).with("inst_rpmcopy", [])

subject.Setup
end
end

context "when dopackages is disabled" do
it "does not try to install given post installation packages / patterns" do
expect(Yast::WFM).to_not receive(:CallFunction).with("inst_rpmcopy", [])

subject.Setup
end
end

it "runs inst_autoconfigure client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_autoconfigure", [])

subject.Setup
end

it "restarts AutoYaST initscripts" do
expect(subject).to receive(:restart_initscripts)

subject.Setup
end

it "does not add a networking section when it is not defined in the profile" do
expect(Yast::Profile.current.keys).to_not include("networking")
subject.Setup
expect(Yast::Profile.current.keys).to_not include("networking")
end
end
end

0 comments on commit ef4d883

Please sign in to comment.