Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partitioner: button to activate crypt devices #849

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package/yast2-storage-ng.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Feb 19 14:40:11 UTC 2019 - ancor@suse.com

- Partitioner: new option "Provide Crypt Passwords" (bsc#1113515).
- 4.1.63

-------------------------------------------------------------------
Tue Feb 19 14:15:16 UTC 2019 - jlopez@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-storage-ng.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-storage-ng
Version: 4.1.62
Version: 4.1.63
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
293 changes: 204 additions & 89 deletions src/lib/y2partitioner/widgets/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,30 @@ def contents
# @return [:redraw, nil] :redraw when some configuration client was
# executed; nil otherwise.
def handle(event)
action = Action.find(event["ID"])
action = find_action(event["ID"])

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

# @macro seeAbstractWidget
def help
# TRANSLATORS: help text for the Partitioner
_(
"<p>The <b>Configure</b> button offers several options to activate devices " \
"that were not detected by the initial system analysis. After activating the " \
"devices of the choosen technology, the system will be rescanned and all the " \
"information about storage devices will be refreshed. " \
"Thus, the <b>Provide Crypt Passwords</b> option is also useful when no " \
"encryption is involved, to activate devices of other technologies like LVM " \
"or Multipath.</p>"
)
end

private

# @return [Array<Yast::WidgetTerm>]
Expand Down Expand Up @@ -108,11 +122,11 @@ def actions
@actions ||=
if Yast::Stage.initial
# In the inst-sys, check which clients are available
Action.supported.select { |action| Yast::WFM.ClientExists(action.client) }
supported_actions.reject(&:client_missing?)
else
# In the installed system, we don't care if the client is there or not
# as the user will be prompted to install the pkg anyway (in #handle).
Action.supported
supported_actions
end
end

Expand Down Expand Up @@ -156,124 +170,225 @@ def check_and_install_pkgs?(action)
ret
end

# Sorted list of actions
def supported_actions
@supported_actions ||= [
CryptAction.new(_("Provide Crypt &Passwords..."), "yast-encrypted"),
IscsiAction.new(_("Configure &iSCSI..."), "yast-iscsi-client"),
FcoeAction.new(_("Configure &FCoE..."), "fcoe"),
DasdAction.new(_("Configure &DASD..."), "yast-dasd"),
ZfcpAction.new(_("Configure &zFCP..."), "yast-zfcp"),
XpramAction.new(_("Configure &XPRAM..."), "yast-xpram")
].select(&:supported?)
end

# Action with the given id
#
# @param id [Symbol]
# @return [Action]
def find_action(id)
supported_actions.find { |action| action.id == id }
end

# Each one of the configuration actions offered by the widget and that
# corresponds to a YaST client
# (usually) corresponds to a YaST client
class Action
include Yast::I18n
extend Yast::I18n

textdomain "storage"

# Constructor
#
# @param id [Symbol] see {#id}
# @param label [String] string marked for translation to be used by {#label}
# @param label [String] see {#label}
# @param icon [String] see {#icon}
# @param client [String] see {#client}
# @param pkgs [Array<String>] see {#pkgs}
def initialize(id, label, icon, client, pkgs)
def initialize(label, icon)
textdomain "storage"

@id = id
@label = label
@icon = icon
@client = client
@pkgs = pkgs
end

# Sorted list of actions
ALL = [
new(:iscsi, N_("Configure &iSCSI..."), "yast-iscsi-client", "iscsi-client",
["yast2-iscsi-client"]),
new(:fcoe, N_("Configure &FCoE..."), "fcoe", "fcoe-client",
["yast2-fcoe-client"]),
new(:dasd, N_("Configure &DASD..."), "yast-dasd", "dasd",
["yast2-s390"]),
new(:zfcp, N_("Configure &zFCP..."), "yast-zfcp", "zfcp",
["yast2-s390"]),
new(:xpram, N_("Configure &XPRAM..."), "yast-xpram", "xpram",
["yast2-s390"])
].freeze
private_constant :ALL

# Texts for {#warning_text}
# @return [Symbol] identifier for the action to use in the UI
def id
@id ||= self.class.name.split("::").last.to_sym
end

# @return [String] Internationalized label
attr_reader :label

# @return [String] name of the icon to display next to the label
attr_reader :icon

# Internationalized text to be displayed as a warning before executing the action
#
# Although all texts are almost identical, the whole literal strings are used
# on each subclass in order to reuse the existing translations from yast2-storage
#
# @return [String]
def warning_text
""
end

# Name of the YaST client implementing the action
#
# @return [Symbol, nil] nil if no separate client needs to be called
def client
nil
end

# Names of the packages needed to run the action
#
# @return [Array<String>]
def pkgs
[]
end

# Whether the action is supported in the current system
#
# Although all texts are almost identical, the whole literal strings
# are indexed in this constant in order to reuse the existing
# translations from yast2-storage
WARNING_TEXTS = {
iscsi: N_(
# @return [Boolean]
def supported?
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
nil
end

# Whether the client needed to run the action is missing
#
# @return [Boolean]
def client_missing?
return false unless client

!Yast::WFM.ClientExists(client)
end
end

# Specific class for the activation action
class CryptAction < Action
# @see Action#warning_text
def warning_text
_(
"Rescanning crypt devices cancels all current changes.\n" \
"Really activate crypt devices?"
)
end

# @see Action#pkgs
def pkgs
["cryptsetup"]
end

# @see Action#activate
def activate
true
end
end

# Specific action for running the iSCSI configuration client
class IscsiAction < Action
# @see Action#warning_text
def warning_text
_(
"Calling iSCSI configuration cancels all current changes.\n" \
"Really call iSCSI configuration?"
),
fcoe: N_(
)
end

# @see Action#client
def client
"iscsi-client"
end

# @see Action#pkgs
def pkgs
["yast2-iscsi-client"]
end
end

# Specific action for running the FCoE configuration client
class FcoeAction < Action
# @see Action#warning_text
def warning_text
_(
"Calling FCoE configuration cancels all current changes.\n" \
"Really call FCoE configuration?"
),
dasd: N_(
"Calling DASD configuration cancels all current changes.\n" \
"Really call DASD configuration?"
),
fzcp: N_(
"Calling zFCP configuration cancels all current changes.\n" \
"Really call zFCP configuration?"
),
xpram: N_(
"Calling XPRAM configuration cancels all current changes.\n" \
"Really call XPRAM configuration?"
)
}
end

# Actions that can only be executed on s390 systems
S390_IDS = [:dasd, :zfcp, :xpram].freeze
private_constant :S390_IDS
# @see Action#client
def client
"fcoe-client"
end

# Action with the given id
#
# @param id [Symbol]
# @return [Action]
def self.find(id)
ALL.find { |action| action.id == id }
# @see Action#pkgs
def pkgs
["yast2-fcoe-client"]
end
end

# Actions that are supported in the current system
#
# @return [Array<Action>]
def self.supported
ALL.select(&:supported?)
# Common base class for all the actions that are specific for S390
class S390Action < Action
# @see Action#pkgs
def pkgs
["yast2-s390"]
end

# @return [Symbol] identifier for the action
attr_reader :id
# @see Action#supported?
def supported?
Yast::Arch.s390
end
end

# @return [String] name of the icon to display next to the label
attr_reader :icon
# Specific action for running the DASD activation client
class DasdAction < S390Action
# @see Action#warning_text
def warning_text
_(
"Calling DASD configuration cancels all current changes.\n" \
"Really call DASD configuration?"
)
end

# @return [Symbol] name of the YaST client implementing the action
attr_reader :client
# @see Action#client
def client
"dasd"
end
end

# @return [Array<String>] name of the packages needed to run the action
attr_reader :pkgs
# Specific action for running the zFCP configuration client
class ZfcpAction < S390Action
# @see Action#warning_text
def warning_text
_(
"Calling zFCP configuration cancels all current changes.\n" \
"Really call zFCP configuration?"
)
end

# Internationalized label
#
# @return [String]
def label
_(@label)
# @see Action#client
def client
"zfcp"
end
end

# Internationalized text to be displayed as a warning before executing the action
#
# @return [String]
# Specific action for running the XPRAM configuration client
class XpramAction < S390Action
# @see Action#warning_text
def warning_text
_(WARNING_TEXTS[id])
_(
"Calling XPRAM configuration cancels all current changes.\n" \
"Really call XPRAM configuration?"
)
end

# Whether the action is supported in the current system
#
# @return [Boolean]
def supported?
S390_IDS.include?(id) ? Yast::Arch.s390 : true
# @see Action#client
def client
"xpram"
end
end
end
Expand Down
Loading