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 2694762 + b2e2703 commit be80d03
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 25 deletions.
7 changes: 7 additions & 0 deletions package/yast2-storage-ng.changes
Expand Up @@ -3,6 +3,13 @@ Wed Feb 20 11:55:30 UTC 2019 - jreidinger@suse.com

- filesystem label is kept when using existing partitioning
(bsc#108722)
- 4.1.65

-------------------------------------------------------------------
Wed Feb 20 09:35:48 UTC 2019 - José Iván López González <jlopez@suse.com>

- Partitioner: add new tab in Bcache section to show all caching
set devices (part of fate#325346).
- 4.1.64

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

Name: yast2-storage-ng
Version: 4.1.64
Version: 4.1.65
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
208 changes: 197 additions & 11 deletions src/lib/y2partitioner/widgets/pages/bcaches.rb
@@ -1,6 +1,6 @@
# encoding: utf-8

# Copyright (c) [2018] SUSE LLC
# Copyright (c) [2018-2019] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -19,42 +19,120 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "cwm/widget"
require "y2partitioner/icons"
require "y2partitioner/ui_state"
require "y2partitioner/widgets/pages/devices_table"
require "y2partitioner/widgets/bcache_add_button"
require "y2partitioner/widgets/device_buttons_set"
require "y2partitioner/widgets/configurable_blk_devices_table"

module Y2Partitioner
module Widgets
module Pages
# A Page for bcache devices and its partitions. It contains a {ConfigurableBlkDevicesTable}
class Bcaches < DevicesTable
include Yast::I18n

# A Page for bcache devices
#
# It contains two tabs: one tab with a list of bcache devices and another
# tab with the list of caching sets.
class Bcaches < CWM::Page
# Constructor
#
# @param bcaches [Array<Y2Storage::Bcache>]
# @param pager [CWM::TreePager]
def initialize(bcaches, pager)
textdomain "storage"

super(pager)
@bcaches = bcaches
@pager = pager
end

# @macro seeAbstractWidget
def label
UIState.instance.bcache_label
end

# @macro seeCustomWidget
def contents
@contents ||= VBox(
Left(
HBox(
Image(icon, ""),
Heading(label)
)
),
tabs
)
end

# @macro seeAbstractWidget
def init
# Start always in the first tab
tabs.switch_page(tabs.initial_page)
end

private

# @return [Array<Y2Storage::BlkDevice>]
# Page icon
#
# @return [String]
def icon
Icons.small_icon(Icons::BCACHE)
end

# Tabs to show
#
# @return [Array<CWM::Tab>]
def tabs
@tabs ||= Tabs.new(
BcachesTab.new(@bcaches, @pager),
BcacheCsetsTab.new(@pager)
)
end
end

# A Tab for the list of bcache devices
class BcachesTab < CWM::Tab
# @return [Array<Y2Storage::Bcache>]
attr_reader :bcaches

# @see DevicesTable
def icon
Icons::BCACHE
# @return [CWM::TreePager]
attr_reader :pager

# Constructor
#
# @param bcaches [Array<Y2Storage::Bcache>]
# @param pager [CWM::TreePager]
def initialize(bcaches, pager)
@bcaches = bcaches
@pager = pager
end

# @macro seeAbstractWidget
def label
_("Bcache Devices")
end

# @macro seeCustomWidget
def contents
@contents ||=
VBox(
table,
Left(device_buttons),
Right(table_buttons)
)
end

# Table to list all bcache devices and their partitions
#
# @return [Widgets::ConfigurableBlkDevicesTable]
def table
@table ||= ConfigurableBlkDevicesTable.new(devices, pager, device_buttons)
end

# Widget with the dynamic set of buttons for the selected row
#
# @return [DeviceButtonsSet]
def device_buttons
@device_buttons ||= DeviceButtonsSet.new(pager)
end

# @see DevicesTable
Expand All @@ -72,6 +150,114 @@ def devices
end
end
end

# A Tab for the list of caching set devices
class BcacheCsetsTab < CWM::Tab
# @return [CWM::TreePager]
attr_reader :pager

# Constructor
#
# @param pager [CWM::TreePager]
def initialize(pager)
@pager = pager
end

# @macro seeAbstractWidget
def label
_("Caching Set Devices")
end

# @macro seeCustomWidget
def contents
@contents ||= VBox(table)
end

# Table to list all caching set devices
#
# @return [BcacheCsetsTable]
def table
@table ||= BcacheCsetsTable.new(devices, pager)
end

# Returns all caching set devices
#
# @return [Array<Y2Storage::BcacheCset>]
def devices
DeviceGraphs.instance.current.bcache_csets
end
end

# Table for caching set devices
class BcacheCsetsTable < ConfigurableBlkDevicesTable
# Constructor
#
# @param devices [Array<Y2Storage::BcacheCsets>] see {#devices}
# @param pager [CWM::Pager] see {#pager}
# @param buttons_set [DeviceButtonsSet] see {#buttons_set}
def initialize(devices, pager, buttons_set = nil)
textdomain "storage"

super
show_columns(:caching_device, :size, :uuid, :used_by)
end

# Column label
#
# @return [String]
def caching_device_title
# TRANSLATORS: table column label.
_("Caching Device")
end

# Column label
#
# @return [String]
def uuid_title
# TRANSLATORS: table column label.
_("UUID")
end

# Column label
#
# @return [String]
def used_by_title
# TRANSLATORS: table column label.
_("Used By")
end

# Column value
#
# @param device [Y2Storage::BcacheCset]
# @return [String] e.g., "/dev/sda1"
def caching_device_value(device)
device.blk_devices.first.name
end

# Column value
#
# @param device [Y2Storage::BcacheCset]
# @return [String] e.g., "2.00 GiB"
def size_value(device)
device.blk_devices.first.size.to_human_string
end

# Column value
#
# @param device [Y2Storage::BcacheCset]
# @return [String] e.g., "111222333-444-55"
def uuid_value(device)
device.uuid
end

# Column value
#
# @param device [Y2Storage::BcacheCset]
# @return [String] e.g., "/dev/bcache0, /dev/bcache1"
def used_by_value(device)
device.bcaches.map(&:name).join(", ")
end
end
end
end
end
61 changes: 52 additions & 9 deletions test/y2partitioner/widgets/pages/bcaches_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env rspec
# encoding: utf-8

# Copyright (c) [2018] SUSE LLC
# Copyright (c) [2018-2019] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -44,18 +44,61 @@

describe "#contents" do
let(:widgets) { Yast::CWM.widgets_in_contents([subject]) }
let(:table) { widgets.detect { |i| i.is_a?(Y2Partitioner::Widgets::BlkDevicesTable) } }
let(:bcaches_and_parts) do
(device_graph.bcaches + device_graph.bcaches.map(&:partitions)).flatten.compact

it "shows a bcache devices tab" do
expect(Y2Partitioner::Widgets::Pages::BcachesTab).to receive(:new)
subject.contents
end

it "shows a caching set devices tab" do
expect(Y2Partitioner::Widgets::Pages::BcacheCsetsTab).to receive(:new)
subject.contents
end
end

describe Y2Partitioner::Widgets::Pages::BcachesTab do
subject { described_class.new(bcaches, pager) }

include_examples "CWM::Tab"

describe "#contents" do
let(:widgets) { Yast::CWM.widgets_in_contents([subject]) }

it "shows a table with the bcache devices and their partitions" do
table = widgets.detect { |i| i.is_a?(Y2Partitioner::Widgets::BlkDevicesTable) }

expect(table).to_not be_nil

devices = table.items.map { |i| i[1] }

expect(devices).to contain_exactly("/dev/bcache0", "/dev/bcache1", "/dev/bcache2",
"/dev/bcache0p1", "/dev/bcache2p1")
end
end
end

describe Y2Partitioner::Widgets::Pages::BcacheCsetsTab do
subject { described_class.new(pager) }

include_examples "CWM::Tab"

describe "#contents" do
before do
vda1 = device_graph.find_by_name("/dev/vda1")
vda1.create_bcache_cset
end

let(:widgets) { Yast::CWM.widgets_in_contents([subject]) }

it "shows a table with the caching set devices" do
table = widgets.detect { |i| i.is_a?(Y2Partitioner::Widgets::BlkDevicesTable) }

it "shows a table with the bcache devices and their partitions" do
expect(table).to_not be_nil
expect(table).to_not be_nil

devices_name = bcaches_and_parts.map(&:name)
items_name = table.items.map { |i| i[1] }
devices = table.items.map { |i| i[1] }

expect(items_name.sort).to eq(devices_name.sort)
expect(devices).to contain_exactly("/dev/vdb", "/dev/vda1")
end
end
end
end
8 changes: 4 additions & 4 deletions test/y2storage/fake_device_factory_test.rb
Expand Up @@ -24,12 +24,12 @@

describe Y2Storage::FakeDeviceFactory do
describe ".load_yaml_file" do
let(:staging) do
environment = Storage::Environment.new(true, Storage::ProbeMode_NONE, Storage::TargetMode_DIRECT)
storage = Storage::Storage.new(environment)
storage.staging
before do
Y2Storage::StorageManager.create_test_instance
end

let(:staging) { Y2Storage::StorageManager.instance.probed.to_storage_value }

let(:io) { StringIO.new(input) }

context "when yaml contains a simple dasd and partition setup" do
Expand Down

0 comments on commit be80d03

Please sign in to comment.