Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 2, 2018
1 parent 91e17d0 commit ccdf5ba
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 6 deletions.
39 changes: 39 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions src/lib/y2storage/planned/disk.rb
Expand Up @@ -34,6 +34,7 @@ class Disk < Device
include Planned::CanBeMounted
include Planned::CanBeEncrypted
include Planned::CanBePv
include Planned::CanBeMdMember
include MatchVolumeSpec

# @return [Array<Planned::Partition>] List of planned partitions
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2storage/planned/mixins.rb
Expand Up @@ -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"
6 changes: 2 additions & 4 deletions src/lib/y2storage/planned/partition.rb
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/lib/y2storage/proposal/autoinst_devices_creator.rb
Expand Up @@ -155,7 +155,6 @@ def process_partitions(planned_devices, disk_names)
# @return [Array<Array<Planned::Md>, Array<Planned::Md>, 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) }
Expand Down Expand Up @@ -305,7 +304,7 @@ def flexible_devices(devices)
# @return [Array<Planned::Device>]
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
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2storage/proposal/autoinst_disk_device_planner.rb
Expand Up @@ -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]
Expand Down
57 changes: 57 additions & 0 deletions 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

0 comments on commit ccdf5ba

Please sign in to comment.