Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into preserve_old_label
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 20, 2019
2 parents 3020794 + d9af0d7 commit 24edc2e
Show file tree
Hide file tree
Showing 47 changed files with 2,607 additions and 530 deletions.
25 changes: 25 additions & 0 deletions package/yast2-storage-ng.changes
@@ -1,3 +1,28 @@
-------------------------------------------------------------------
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

- Partitioner: allow to edit bcache devices (part of fate#325346).
- 4.1.62

-------------------------------------------------------------------
Tue Feb 19 13:39:49 UTC 2019 - Stefan Hundhammer <shundhammer@suse.com>

- Added help texts for guided setup (bsc#1121801)
- 4.1.61

-------------------------------------------------------------------
Mon Feb 18 14:54:15 CET 2019 - aschnell@suse.com

- AutoYaST: handle device_order for MD RAIDs during installation
(bsc#1083542)
- 4.1.60

-------------------------------------------------------------------
Thu Feb 14 17:03:05 UTC 2019 - Stefan Hundhammer <shundhammer@suse.com>

Expand Down
10 changes: 5 additions & 5 deletions package/yast2-storage-ng.spec
Expand Up @@ -16,7 +16,7 @@
#

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

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -26,8 +26,8 @@ Source: %{name}-%{version}.tar.bz2
Requires: yast2 >= 4.1.11
# for AbortException and handle direct abort
Requires: yast2-ruby-bindings >= 4.0.6
# Probing Flash-only Bcache devices
Requires: libstorage-ng-ruby >= 4.1.81
# Bcache#remove_bcache_cset
Requires: libstorage-ng-ruby >= 4.1.89
# communicate with udisks
Requires: rubygem(ruby-dbus)
# Y2Packager::Repository
Expand All @@ -36,8 +36,8 @@ Requires: yast2-packager >= 3.3.7
Requires: findutils

BuildRequires: update-desktop-files
# Probing Flash-only Bcache devices
BuildRequires: libstorage-ng-ruby >= 4.1.81
# Bcache#remove_bcache_cset
BuildRequires: libstorage-ng-ruby >= 4.1.89
BuildRequires: yast2-ruby-bindings
BuildRequires: yast2-devtools
# yast2-xml dependency is added by yast2 but ignored in the
Expand Down
138 changes: 27 additions & 111 deletions src/lib/y2partitioner/actions/add_bcache.rb
Expand Up @@ -20,150 +20,66 @@
# find current contact information at www.suse.com.

require "yast"
require "yast/i18n"
require "yast2/popup"
require "y2storage/bcache"
require "y2partitioner/actions/base"
require "y2partitioner/actions/controllers/bcache"
require "y2partitioner/dialogs/bcache"
require "y2partitioner/device_graphs"
require "y2partitioner/ui_state"

module Y2Partitioner
module Actions
# Action for adding a bcache device
class AddBcache
include Yast::I18n

# Action for adding a bcache device, see {Actions::Base}
class AddBcache < Base
def initialize
textdomain "storage"
end

# Runs a dialog for adding a bcache and also modifies the device graph if the user
# confirms the dialog.
#
# @return [Symbol] :back, :finish
def run
return :back unless validate
super

dialog = Dialogs::Bcache.new(suitable_backing_devices, suitable_caching_devices)

create_device(dialog) if dialog.run == :next
textdomain "storage"

:finish
@controller = Controllers::Bcache.new
end

private

# Validations before performing the action
#
# @note The action can be performed is there are no errors (see #errors).
# Only the first error is shown.
#
# @return [Boolean]
def validate
current_errors = errors
return true if current_errors.empty?

Yast2::Popup.show(current_errors.first, headline: :error)
false
end
# @return [Controllers::Bcache]
attr_reader :controller

# List of errors that avoid to create a Bcache
#
# @see Actions::Base#errors
#
# @return [Array<String>]
def errors
[no_backing_devices_error].compact
(super + [no_backing_devices_error]).compact
end

# Error when there is no suitable backing devices for creating a Bcache
#
# @return [String, nil] nil if there are devices.
# @return [String, nil] nil if there are suitable backing devices.
def no_backing_devices_error
return nil if suitable_backing_devices.any?
return nil if suitable_backing_devices?

# TRANSLATORS: Error message.
_("There are not enough suitable unused devices to create a Bcache.")
end

# Creates a bcache device according to the user input
#
# @param dialog [Dialogs::Bcache]
def create_device(dialog)
backing = dialog.backing_device

raise "Invalid result #{dialog.inspect}. Backing not found." unless backing

bcache = backing.create_bcache(Y2Storage::Bcache.find_free_name(device_graph))

apply_options(bcache, dialog.options)

attach(bcache, dialog.caching_device) if dialog.caching_device
end

# Applies options to the bcache device
#
# Right now, the dialog only allows to indicate the cache mode.
#
# @param bcache [Y2Storage::Bcache]
# @param options [Hash<Symbol, Object>]
def apply_options(bcache, options)
options.each_pair do |key, value|
bcache.public_send(:"#{key}=", value)
end
end

# Attaches the selected caching to the bcache
#
# @param bcache [Y2Storage::Bcache]
# @param caching [Y2Storage::BcacheCset, Y2Storage::BlkDevice, nil]
def attach(bcache, caching)
return if caching.nil?

if !caching.is?(:bcache_cset)
caching.remove_descendants
caching = caching.create_bcache_cset
end

bcache.attach_bcache_cset(caching)
end

# Device graph in which the action operates on
# Opens a dialog to create a Bcache
#
# @return [Y2Storage::Devicegraph]
def device_graph
DeviceGraphs.instance.current
end

# Suitable devices to be used as backing device
# The Bcache is created only if the dialog is accepted.
#
# @return [Array<Y2Storage::BlkDevice>]
def suitable_backing_devices
usable_blk_devices
end
# @see Actions::Base#perform_action
def perform_action
dialog = Dialogs::Bcache.new(controller)

# Suitable devices to be used for caching
#
# @return [Array<Y2Storage::BcacheCset, Y2Storage::BlkDevice>]
def suitable_caching_devices
existing_caches + usable_blk_devices
end
return unless dialog.run == :next

# Block devices that can be used as backing or caching device
#
# @return [Array<Y2Storage::BlkDevice>]
def usable_blk_devices
device_graph.blk_devices.select do |dev|
dev.component_of.empty? &&
(dev.filesystem.nil? || dev.filesystem.mount_point.nil?) &&
(!dev.respond_to?(:partitions) || dev.partitions.empty?) &&
# do not allow nested bcaches, see doc/bcache.md
([dev] + dev.ancestors).none? { |a| a.is?(:bcache, :bcache_cset) }
end
controller.create_bcache(dialog.backing_device, dialog.caching_device, dialog.options)
UIState.instance.select_row(controller.bcache)
end

# Currently existing caching sets
# Whether there is suitable backing devices
#
# @return [Array<Y2Storage::BcacheCset>]
def existing_caches
device_graph.bcache_csets
# @return [Boolean]
def suitable_backing_devices?
controller.suitable_backing_devices.any?
end
end
end
Expand Down
89 changes: 89 additions & 0 deletions src/lib/y2partitioner/actions/base.rb
@@ -0,0 +1,89 @@
# encoding: utf-8

# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "yast/i18n"
require "yast2/popup"

require "abstract_method"

module Y2Partitioner
module Actions
# Base class for actions that can be performed by the Expert Partitioner
#
# This base class is mainly intended to one-step actions. For more complex actions,
# see {TransactionWizard}.
class Base
include Yast::I18n

def initialize
textdomain "storage"
end

# Runs a dialog for adding a bcache and also modifies the device graph if the user
# confirms the dialog.
#
# @return [Symbol] :back, :finish
def run
return :back unless run?

perform_action

:finish
end

private

# Performs the action, see {#run}
#
# This method should be defined by derived classes.
abstract_method :perform_action

# Checks whether the action can be performed
#
# @return [Boolean]
def run?
validate
end

# Validations before performing the action
#
# @note The action can be performed if there are no errors (see #errors).
# Only the first error is shown.
#
# @return [Boolean]
def validate
current_errors = errors
return true if current_errors.empty?

Yast2::Popup.show(current_errors.first, headline: :error)
false
end

# List of errors that avoid to perform the action
#
# @return [Array<String>] translated error messages
def errors
[]
end
end
end
end

0 comments on commit 24edc2e

Please sign in to comment.