Skip to content

Commit

Permalink
Partitioner: button to activate crypt devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Feb 18, 2019
1 parent 5b14c69 commit f8f1596
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 45 deletions.
20 changes: 18 additions & 2 deletions src/lib/y2partitioner/widgets/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def handle(event)
return nil unless action
return nil unless warning_accepted?(action) && availability_ensured?(action)

Yast::WFM.call(action.client)
reprobe
Yast::WFM.call(action.client) if action.client
reprobe(activate: action.activate)
:redraw
end

Expand Down Expand Up @@ -183,6 +183,8 @@ def initialize(id, label, icon, client, pkgs)

# Sorted list of actions
ALL = [
new(:crypt, N_("Provide Crypt &Passwords..."), "yast-encrypted", nil,
["cryptsetup"]),
new(:iscsi, N_("Configure &iSCSI..."), "yast-iscsi-client", "iscsi-client",
["yast2-iscsi-client"]),
new(:fcoe, N_("Configure &FCoE..."), "fcoe", "fcoe-client",
Expand All @@ -202,6 +204,10 @@ def initialize(id, label, icon, client, pkgs)
# are indexed in this constant in order to reuse the existing
# translations from yast2-storage
WARNING_TEXTS = {
crypt: N_(
"Rescanning crypt devices cancels all current changes.\n" \
"Really activate crypt devices?"
),
iscsi: N_(
"Calling iSCSI configuration cancels all current changes.\n" \
"Really call iSCSI configuration?"
Expand Down Expand Up @@ -275,6 +281,16 @@ def warning_text
def supported?
S390_IDS.include?(id) ? Yast::Arch.s390 : true
end

# Value for the 'activate' argument of {Reprobe#reprobe}
#
# For most cases this returns nil, which implies simply honoring the
# default behavior.
#
# @return [Boolean, nil]
def activate
id == :crypt ? true : nil
end
end
end
end
Expand Down
22 changes: 15 additions & 7 deletions src/lib/y2partitioner/widgets/reprobe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ module Reprobe
# @raise [Y2Partitioner::ForcedAbortError] When there is an error during probing
# and the user decides to abort, or probed devicegraph contains errors and the
# user decides to not sanitize.
def reprobe
#
# @param activate [Boolean, nil] whether to perform an activation, if nil
# the (re)activation will be done only during installation
def reprobe(activate: nil)
textdomain "storage"

# By default, (re)activation is only done during installation.
# In installed systems, activation is only triggered for actions that
# explicitly force it.
activate = !!Yast::Stage.initial if activate.nil?

Yast::Popup.Feedback("", _("Rescanning disks...")) do
raise Y2Partitioner::ForcedAbortError unless activate_and_probe?
raise Y2Partitioner::ForcedAbortError unless activate_and_probe?(activate)

probed = storage_manager.probed
staging = storage_manager.staging
Expand All @@ -59,13 +68,12 @@ def storage_manager

# Performs storage reactivation (if needed) and reprobing
#
# @note Activation is only done during installation, never in an already
# installed system
#
# @param activate [Boolean] whether to perform a reactivation of devices
# before the reprobing
# @return [Boolean] false if something went wrong
def activate_and_probe?
def activate_and_probe?(activate)
success = true
success &&= storage_manager.activate if Yast::Stage.initial
success &&= storage_manager.activate if activate
success &&= storage_manager.probe
success
end
Expand Down
12 changes: 12 additions & 0 deletions test/support/partitioner_reprobe_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@
end
end
end

RSpec.shared_examples "activation" do
it "runs activation (again)" do
expect(manager).to receive(:activate).and_return true
subject.handle(*handle_args)
end

it "raises an exception if activation fails" do
allow(manager).to receive(:activate).and_return false
expect { subject.handle(*handle_args) }.to raise_error(Y2Partitioner::ForcedAbortError)
end
end
102 changes: 66 additions & 36 deletions test/y2partitioner/widgets/configure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ def menu_button_item_ids(button)
context "if all the possible clients are available" do
let(:missing_clients) { [] }

it "returns a menu button with buttons for iSCI, FCoE, DASD, zFCP and XPRAM" do
it "returns a menu button with buttons for crypt, iSCI, FCoE, DASD, zFCP and XPRAM" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe, :dasd, :zfcp, :xpram)
expect(menu_button_item_ids(term))
.to contain_exactly(:crypt, :iscsi, :fcoe, :dasd, :zfcp, :xpram)
end
end

Expand All @@ -77,17 +78,18 @@ def menu_button_item_ids(button)
it "returns a menu button with buttons only for the available clients" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:fcoe, :zfcp, :xpram)
expect(menu_button_item_ids(term)).to contain_exactly(:crypt, :fcoe, :zfcp, :xpram)
expect(menu_button_item_ids(term)).to_not include(:iscsi, :dasd)
end
end

context "if no client is available" do
let(:missing_clients) { all_clients }

it "returns an empty term" do
it "returns a menu button with 'Crypt Passwords' as the only option" do
term = widget.contents
expect(term.value).to eq :Empty
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to eq [:crypt]
end
end
end
Expand All @@ -98,10 +100,10 @@ def menu_button_item_ids(button)
context "if all the possible clients are available" do
let(:missing_clients) { [] }

it "returns a menu button with buttons for iSCI and FCoE" do
it "returns a menu button with buttons for crypt, iSCI and FCoE" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe)
expect(menu_button_item_ids(term)).to contain_exactly(:crypt, :iscsi, :fcoe)
end
end

Expand All @@ -111,17 +113,18 @@ def menu_button_item_ids(button)
it "returns a menu button with buttons only for the available clients" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to eq [:fcoe]
expect(menu_button_item_ids(term)).to eq [:crypt, :fcoe]
expect(menu_button_item_ids(term)).to_not include(:iscsi)
end
end

context "if no client is available" do
let(:missing_clients) { all_clients }

it "returns an empty term" do
it "returns a menu button with 'Crypt Passwords' as the only option" do
term = widget.contents
expect(term.value).to eq :Empty
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to eq [:crypt]
end
end
end
Expand All @@ -136,20 +139,22 @@ def menu_button_item_ids(button)
context "if all the possible clients are available" do
let(:missing_clients) { [] }

it "returns a menu button with buttons for all clients (iSCI, FCoE, DASD, zFCP and XPRAM)" do
it "returns a menu button with buttons for all actions" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe, :dasd, :zfcp, :xpram)
expect(menu_button_item_ids(term))
.to contain_exactly(:crypt, :iscsi, :fcoe, :dasd, :zfcp, :xpram)
end
end

context "if some clients are not available" do
let(:missing_clients) { ["iscsi-client", "dasd"] }

it "returns a menu button with buttons for all clients (iSCI, FCoE, DASD, zFCP and XPRAM)" do
it "returns a menu button with buttons for all actions" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe, :dasd, :zfcp, :xpram)
expect(menu_button_item_ids(term))
.to contain_exactly(:crypt, :iscsi, :fcoe, :dasd, :zfcp, :xpram)
end
end
end
Expand All @@ -160,20 +165,20 @@ def menu_button_item_ids(button)
context "if all the possible clients are available" do
let(:missing_clients) { [] }

it "returns a menu button with buttons for all supported clients (iSCI and FCoE)" do
it "returns a menu button with buttons for all supported actions (crypt, iSCI and FCoE)" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe)
expect(menu_button_item_ids(term)).to contain_exactly(:crypt, :iscsi, :fcoe)
end
end

context "if some clients are not available" do
let(:missing_clients) { ["iscsi-client"] }

it "returns a menu button with buttons for all supported clients (iSCI and FCoE)" do
it "returns a menu button with buttons for all supported actions (crypt, iSCI and FCoE)" do
term = widget.contents
expect(term.value).to eq :MenuButton
expect(menu_button_item_ids(term)).to contain_exactly(:iscsi, :fcoe)
expect(menu_button_item_ids(term)).to contain_exactly(:crypt, :iscsi, :fcoe)
end
end
end
Expand Down Expand Up @@ -240,27 +245,35 @@ def event_for(id)
context "if the user accepts the warning" do
let(:accepted) { true }

it "calls the corresponding YaST client" do
expect(Yast::WFM).to receive(:call).with("iscsi-client")
widget.handle(event)
end
context "for an action performed via a separate client" do
let(:event) { event_for(:iscsi) }

include_examples "reprobing"
it "calls the corresponding YaST client" do
expect(Yast::WFM).to receive(:call).with("iscsi-client")
widget.handle(event)
end

it "runs activation again" do
expect(manager).to receive(:activate).and_return true
widget.handle(event)
include_examples "reprobing"
include_examples "activation"
end

it "raises an exception if activation fails" do
allow(manager).to receive(:activate).and_return false
expect { subject.handle(event) }.to raise_error(Y2Partitioner::ForcedAbortError)
context "for activation of crypt devices" do
let(:event) { event_for(:crypt) }

it "does not call any additional YaST client" do
expect(Yast::WFM).to_not receive(:call)
widget.handle(event)
end

include_examples "reprobing"
include_examples "activation"
end
end
end

context "in an already installed system" do
let(:install) { false }
let(:handle_args) { [event] }

include_examples "show configure warning"

Expand Down Expand Up @@ -292,16 +305,33 @@ def event_for(id)
context "if the packages were installed or already there" do
let(:installed_pkgs) { true }

it "calls the corresponding YaST client" do
expect(Yast::WFM).to receive(:call).with("iscsi-client")
widget.handle(event)
context "for an action performed via a separate client" do
let(:event) { event_for(:iscsi) }

it "calls the corresponding YaST client" do
expect(Yast::WFM).to receive(:call).with("iscsi-client")
widget.handle(event)
end

include_examples "reprobing"

it "does not run activation" do
expect(manager).to_not receive(:activate)
widget.handle(event)
end
end

include_examples "reprobing"
context "for activation of crypt devices" do
let(:event) { event_for(:crypt) }
before { allow(manager).to receive(:activate).and_return true }

it "does not run activation" do
expect(manager).to_not receive(:activate)
widget.handle(event)
it "does not call any additional YaST client" do
expect(Yast::WFM).to_not receive(:call)
widget.handle(event)
end

include_examples "reprobing"
include_examples "activation"
end
end
end
Expand Down

0 comments on commit f8f1596

Please sign in to comment.