From ccdf5baf883272d732cf00cde3f2a7b3a6a0fc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Tue, 2 Oct 2018 10:01:09 +0100 Subject: [PATCH] wip --- src/lib/y2storage/planned/can_be_md_member.rb | 39 +++++++++++++ src/lib/y2storage/planned/disk.rb | 2 + src/lib/y2storage/planned/mixins.rb | 1 + src/lib/y2storage/planned/partition.rb | 6 +- .../proposal/autoinst_devices_creator.rb | 3 +- .../proposal/autoinst_disk_device_planner.rb | 1 + .../planned/can_be_md_member_test.rb | 57 +++++++++++++++++++ 7 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 src/lib/y2storage/planned/can_be_md_member.rb create mode 100644 test/y2storage/planned/can_be_md_member_test.rb diff --git a/src/lib/y2storage/planned/can_be_md_member.rb b/src/lib/y2storage/planned/can_be_md_member.rb new file mode 100644 index 0000000000..b81982474c --- /dev/null +++ b/src/lib/y2storage/planned/can_be_md_member.rb @@ -0,0 +1,39 @@ +# encoding: utf-8 + +# Copyright (c) [2018] 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. + +module Y2Storage + module Planned + module CanBeMdMember + # @return [String] name of the MD array to which this partition should + # be added + attr_accessor :raid_name + + # Initializations of the mixin, to be called from the class constructor. + def initialize_can_be_md_member + end + + # Checks whether the device represents an MD RAID member + def md_member? + !raid_name.nil? + end + end + end +end diff --git a/src/lib/y2storage/planned/disk.rb b/src/lib/y2storage/planned/disk.rb index 64510cac75..2bfbf6e881 100644 --- a/src/lib/y2storage/planned/disk.rb +++ b/src/lib/y2storage/planned/disk.rb @@ -34,6 +34,7 @@ class Disk < Device include Planned::CanBeMounted include Planned::CanBeEncrypted include Planned::CanBePv + include Planned::CanBeMdMember include MatchVolumeSpec # @return [Array] List of planned partitions @@ -46,6 +47,7 @@ def initialize initialize_can_be_mounted initialize_can_be_encrypted initialize_can_be_pv + initialize_can_be_md_member @partitions = [] end diff --git a/src/lib/y2storage/planned/mixins.rb b/src/lib/y2storage/planned/mixins.rb index a34e12d69d..76d4b1668d 100644 --- a/src/lib/y2storage/planned/mixins.rb +++ b/src/lib/y2storage/planned/mixins.rb @@ -23,5 +23,6 @@ require "y2storage/planned/can_be_formatted" require "y2storage/planned/can_be_mounted" require "y2storage/planned/can_be_pv" +require "y2storage/planned/can_be_md_member" require "y2storage/planned/can_be_resized" require "y2storage/planned/has_size" diff --git a/src/lib/y2storage/planned/partition.rb b/src/lib/y2storage/planned/partition.rb index dd53e5aaa3..348432db87 100644 --- a/src/lib/y2storage/planned/partition.rb +++ b/src/lib/y2storage/planned/partition.rb @@ -37,6 +37,7 @@ class Partition < Device include Planned::CanBeMounted include Planned::CanBeEncrypted include Planned::CanBePv + include Planned::CanBeMdMember include MatchVolumeSpec # @return [PartitionId] id of the partition. If nil, the final id is @@ -59,10 +60,6 @@ class Partition < Device # @return [Boolean] whether the partition must be primary attr_accessor :primary - # @return [String] name of the MD array to which this partition should - # be added - attr_accessor :raid_name - # Constructor. # # @param mount_point [string] See {#mount_point} @@ -74,6 +71,7 @@ def initialize(mount_point, filesystem_type = nil) initialize_can_be_mounted initialize_can_be_encrypted initialize_can_be_pv + initialize_can_be_md_member @mount_point = mount_point @filesystem_type = filesystem_type diff --git a/src/lib/y2storage/proposal/autoinst_devices_creator.rb b/src/lib/y2storage/proposal/autoinst_devices_creator.rb index ca29bc82ac..05e38bdf8f 100644 --- a/src/lib/y2storage/proposal/autoinst_devices_creator.rb +++ b/src/lib/y2storage/proposal/autoinst_devices_creator.rb @@ -155,7 +155,6 @@ def process_partitions(planned_devices, disk_names) # @return [Array, Array, CreatorResult>] def process_mds(planned_devices, devs_to_reuse, creator_result) mds_to_reuse, mds_to_create = planned_devices.mds.partition(&:reuse?) - # TODO: currently it is not possible to use full disks in a RAID devs_to_reuse_in_md = reusable_by_md(devs_to_reuse) creator_result.merge!(create_mds(mds_to_create, creator_result, devs_to_reuse_in_md)) mds_to_reuse.each { |i| i.reuse!(creator_result.devicegraph) } @@ -305,7 +304,7 @@ def flexible_devices(devices) # @return [Array] def reusable_by_md(planned_devices) planned_devices.select do |dev| - dev.is_a?(Planned::StrayBlkDevice) || dev.is_a?(Planned::Partition) + dev.is_a?(Planned::StrayBlkDevice) || dev.is_a?(Planned::Partition) || dev.is_a?(Planned::Disk) end end end diff --git a/src/lib/y2storage/proposal/autoinst_disk_device_planner.rb b/src/lib/y2storage/proposal/autoinst_disk_device_planner.rb index adac0d5235..6141b852fb 100644 --- a/src/lib/y2storage/proposal/autoinst_disk_device_planner.rb +++ b/src/lib/y2storage/proposal/autoinst_disk_device_planner.rb @@ -85,6 +85,7 @@ def planned_for_full_disk(drive, part) planned_disk = Y2Storage::Planned::Disk.new device_config(planned_disk, part, drive) planned_disk.lvm_volume_group_name = part.lvm_group + planned_disk.raid_name = part.raid_name add_device_reuse(planned_disk, drive.device, part) [planned_disk] diff --git a/test/y2storage/planned/can_be_md_member_test.rb b/test/y2storage/planned/can_be_md_member_test.rb new file mode 100644 index 0000000000..f36b088d18 --- /dev/null +++ b/test/y2storage/planned/can_be_md_member_test.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env rspec +# encoding: utf-8 + +# Copyright (c) [2018] 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_relative "../spec_helper" +require "y2storage" + +describe Y2Storage::Planned::CanBeMdMember do + + # Dummy class to test the mixin + class MdMemberDevice < Y2Storage::Planned::Device + include Y2Storage::Planned::CanBeMdMember + + def initialize + super + initialize_can_be_md_member + end + end + + subject(:planned) { MdMemberDevice.new } + + describe "#md_member?" do + context "when the device has a RAID name" do + before do + planned.raid_name = "/dev/md0" + end + + it "returns true" do + expect(planned.md_member?).to eq(true) + end + end + + context "when the device has a RAID name" do + it "returns false" do + expect(planned.md_member?).to eq(false) + end + end + end +end