Skip to content

Commit

Permalink
Avoid hanging Yast when tries to deactivate a DASD in use
Browse files Browse the repository at this point in the history
Instead, an error message is shown to the user, including the details
when they are available.

Related to bsc#1091797
  • Loading branch information
dgdavid committed Sep 21, 2018
1 parent 5bf2152 commit 60c694b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/modules/DASDController.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Representation of the configuration of controller.
# Input and output routines.
require "yast"
require "yast2/popup"
require "shellwords"

module Yast
Expand Down Expand Up @@ -532,6 +533,21 @@ def ReportActivationError(channel, ret)
channel
)
)
when 16
# https://bugzilla.suse.com/show_bug.cgi?id=1091797#c8
details = []
details << "Stdout:\n #{ret["stdout"]}" unless ret["stdout"].to_s.empty?
details << "Stderr:\n #{ret["stderr"]}" unless ret["stderr"].to_s.empty?
headline = _("Error: channel in use")
# TRANSLATORS: error report, %1 is device identification
message = Builtins.sformat(_("%1 DASD is in use and cannot be deactivated."), channel)

if details.empty?
Report.Error(message)
else
message << "\n\n#{_("See the details for more info.")}"
Yast2::Popup.show(message, headline: headline, details: details.join("\n\n"))
end
else
Report.Error(
Builtins.sformat(
Expand Down Expand Up @@ -589,7 +605,7 @@ def ActivateDisk(channel, diag)
# @param [Boolean] diag boolean Activate DIAG or not
def DeactivateDisk(channel, diag)
command = Builtins.sformat(
"/sbin/dasd_configure '%1' %2 %3",
"/sbin/dasd_configure '%1' %2 %3 < /dev/null",
channel,
0,
diag ? 1 : 0
Expand Down
59 changes: 59 additions & 0 deletions test/dasd_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,65 @@
describe "Yast::DASDController" do
subject { Yast::DASDController }

describe "#DeactivateDisk" do
let(:channel) { "0.0.0160" }
let(:diagnose) { false }
let(:exit_code) { 0 }
let(:command_result) { { "exit" => exit_code } }

before do
allow(Yast::Report).to receive(:Error)
allow(Yast2::Popup).to receive(:show)
allow(Yast::SCR).to receive(:Execute).and_return(command_result)
allow(Yast::SCR).to receive(:Read)
.with(Yast.path(".probe.disk")).once
.and_return(load_data("probe_disk_dasd.yml"))

subject.ProbeDisks()
end

it "redirects output to /dev/null" do
expect(Yast::SCR).to receive(:Execute)
.with(anything, /\/sbin\/dasd_configure .* < \/dev\/null/)

subject.DeactivateDisk(channel, diagnose)
end

context "when disk is being in use" do
let(:exit_code) { 16 }

it "returns nil" do
expect(subject.DeactivateDisk(channel, diagnose)).to be_nil
end

context "and there are details to show" do
let(:command_result) do
{
"exit" => exit_code,
"stderr" => "Warning: ECKD DASD 0.0.0150 is in use!\n" \
"The following resources may be affected:\n" \
"- Mount point /mnt\n",
"stdout" => "Continue with operation? (yes/no)"
}
end

it "reports an error with details" do
expect(Yast2::Popup).to receive(:show).with(anything, hash_including(:headline, :details))

subject.DeactivateDisk(channel, diagnose)
end
end

context "and there are not details to show" do
it "reports an error" do
expect(Yast::Report).to receive(:Error).with(/in use/)

subject.DeactivateDisk(channel, diagnose)
end
end
end
end

describe "#IsAvailable" do
it "returns true if .probe.disk contains DASDs" do
expect(Yast::SCR).to receive(:Read).with(Yast.path(".probe.disk")).once
Expand Down

0 comments on commit 60c694b

Please sign in to comment.