From 60c694b3c7976f03a25edc7df6949524e009a7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Fri, 21 Sep 2018 08:15:00 +0100 Subject: [PATCH] Avoid hanging Yast when tries to deactivate a DASD in use Instead, an error message is shown to the user, including the details when they are available. Related to bsc#1091797 --- src/modules/DASDController.rb | 18 ++++++++++- test/dasd_controller_test.rb | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/modules/DASDController.rb b/src/modules/DASDController.rb index b8079c66..960cefc9 100644 --- a/src/modules/DASDController.rb +++ b/src/modules/DASDController.rb @@ -29,6 +29,7 @@ # Representation of the configuration of controller. # Input and output routines. require "yast" +require "yast2/popup" require "shellwords" module Yast @@ -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( @@ -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 diff --git a/test/dasd_controller_test.rb b/test/dasd_controller_test.rb index 0c819abb..f067b0fa 100755 --- a/test/dasd_controller_test.rb +++ b/test/dasd_controller_test.rb @@ -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