Skip to content

Commit

Permalink
Merge pull request #432 from yast/fix_execute
Browse files Browse the repository at this point in the history
Fix execute
  • Loading branch information
jreidinger committed Feb 2, 2016
2 parents 57c8148 + 777c11c commit 6514ef6
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 38 deletions.
74 changes: 38 additions & 36 deletions library/system/src/lib/yast2/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,50 @@ class Execute
# use y2log by default
Cheetah.default_options = { logger: Y2Logger.instance }

class << self
# Runs arguments with respect of changed root in installation.
# @see Cheetah.run for parameters
# @raise Cheetah::ExecutionFailed
def on_target(*args)
root = "/"
root = Yast::Installation.destdir if Yast::WFM.scr_chrooted?
extend Yast::I18n
textdomain "base"

if args.last.is_a? Hash
args.last[:chroot] = root
else
args.push(chroot: root)
end
# Runs arguments with respect of changed root in installation.
# @see Cheetah.run for parameters
# @raise Cheetah::ExecutionFailed
def self.on_target(*args)
root = "/"
root = Yast::Installation.destdir if Yast::WFM.scr_chrooted?

popup_error { Cheetah.run(*args) }
if args.last.is_a? ::Hash
args.last[:chroot] = root
else
args.push(chroot: root)
end

# Runs arguments without changed root.
# @see Cheetah.run for parameters
# @raise Cheetah::ExecutionFailed
def locally(*args)
popup_error { Cheetah.run(*args) }
end
popup_error { Cheetah.run(*args) }
end

# Runs arguments without changed root.
# @see Cheetah.run for parameters
# @raise Cheetah::ExecutionFailed
def self.locally(*args)
popup_error { Cheetah.run(*args) }
end

private
def self.popup_error(&block)
block.call
rescue Cheetah::ExecutionFailed => e
Yast.import "Report"

def popup_error(&block)
block.call
rescue Cheetah::ExecutionFailed => e
Yast.import "Report"
Yast::Report.Error(
_(
"Execution of command \"%{command}\" failed.\n"\
"Exit code: %{exitcode}\n"\
"Error output: %{stderr}"
) % {
command: e.commands.inspect,
exitcode: e.status.exitstatus,
stderr: e.stderr
}
)
end
Yast::Report.Error(
_(
"Execution of command \"%{command}\" failed.\n"\
"Exit code: %{exitcode}\n"\
"Error output: %{stderr}"
) % {
command: e.commands.inspect,
exitcode: e.status.exitstatus,
stderr: e.stderr
}
)
end

private_class_method :popup_error
end
end
4 changes: 3 additions & 1 deletion library/system/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
TESTS = \
execute_test.rb \
kernel_test.rb \
hw_detection_test.rb \
fs_snapshot_test.rb \
fs_snapshot_store_test.rb
fs_snapshot_store_test.rb \
proc_cmdline_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
48 changes: 48 additions & 0 deletions library/system/test/execute_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env rspec

require_relative "test_helper"
require "yast2/execute"

Yast.import "Report"

describe Yast::Execute do
it "sets yast logger as cheetah logger" do
expect(Cheetah.default_options[:logger]).to eq Yast::Y2Logger.instance
end

describe ".locally" do
it "passes arguments directly to cheetah" do
expect(Cheetah).to receive(:run).with("ls", "-a")

Yast::Execute.locally("ls", "-a")
end

it "report error if command execution failed" do
expect(Yast::Report).to receive(:Error)
Yast::Execute.locally("false")
end

it "returns nil if command execution failed" do
expect(Yast::Execute.locally("false")).to eq nil
end
end

describe ".on_target" do
it "adds to passed arguments chroot option if scr chrooted" do
Yast::Installation.destdir = "/mnt"
allow(Yast::WFM).to receive(:scr_chrooted?).and_return(true)
expect(Cheetah).to receive(:run).with("ls", "-a", chroot: "/mnt")

Yast::Execute.on_target("ls", "-a")
end

it "report error if command execution failed" do
expect(Yast::Report).to receive(:Error)
Yast::Execute.on_target("false")
end

it "returns nil if command execution failed" do
expect(Yast::Execute.on_target("false")).to eq nil
end
end
end
7 changes: 7 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Feb 1 15:31:07 UTC 2016 - jreidinger@suse.com

- Yast::Execute do not crash for missing '_' method (found during
FATE#317701)
- 3.1.172

-------------------------------------------------------------------
Mon Feb 1 08:31:17 UTC 2016 - jreidinger@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: 3.1.171
Version: 3.1.172
Release: 0
Url: https://github.com/yast/yast-yast2

Expand Down

0 comments on commit 6514ef6

Please sign in to comment.