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

Export lvm_group for MD RAID devices #700

Merged
merged 3 commits into from Jul 31, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-storage-ng.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Jul 31 13:44:39 UTC 2018 - igonzalezsosa@suse.com

- AutoYaST: export volume group name (lvm_group) when a MD RAID
device is used as a physical volume (bsc#1103113).
- 4.0.201

-------------------------------------------------------------------
Thu Jul 26 11:16:27 UTC 2018 - snwint@suse.com

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.0.200
Version: 4.0.201
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
13 changes: 12 additions & 1 deletion src/lib/y2storage/autoinst_profile/partition_section.rb
Expand Up @@ -299,7 +299,7 @@ def init_partition_fields(partition)
@partition_nr = partition.number
@partition_type = "primary" if partition.type.is?(:primary)
@partition_id = partition_id_from(partition)
@lvm_group = partition.lvm_pv.lvm_vg.basename if partition.lvm_pv && partition.lvm_pv.lvm_vg
@lvm_group = lvm_group_name(partition)
@raid_name = partition.md.name if partition.md
end

Expand All @@ -315,6 +315,7 @@ def init_lv_fields(lv)
def init_md_fields(md)
@partition_nr = md.number if md.numeric?
@raid_options = RaidOptionsSection.new_from_storage(md)
@lvm_group = lvm_group_name(md)
end

def init_encryption_fields(partition)
Expand Down Expand Up @@ -409,6 +410,16 @@ def subvolumes_from_hashes(hashes)
subvolumes = SubvolSpecification.list_from_control_xml(hashes)
subvolumes.reject { |s| s.path == "@" }
end

# Returns the volume group associated to a given device
#
# @param device [Y2Storage::Partition,Y2Storage::Md] Partition or MD RAID device.
# @return [String,nil] Volume group; nil if it is not used as a physical volume or does
# not belong to any volume group.
def lvm_group_name(device)
return nil if device.lvm_pv.nil? || device.lvm_pv.lvm_vg.nil?
device.lvm_pv.lvm_vg.basename
end
end
end
end
28 changes: 27 additions & 1 deletion test/y2storage/autoinst_profile/partition_section_test.rb
Expand Up @@ -131,7 +131,8 @@ def section_for(name)
numeric?: numeric?,
number: 0,
encrypted?: false,
filesystem: filesystem
filesystem: filesystem,
lvm_pv: lvm_pv
)
end

Expand All @@ -147,6 +148,7 @@ def section_for(name)
end

let(:numeric?) { true }
let(:lvm_pv) { nil }

before do
allow(md).to receive(:is?) { |t| t == :md }
Expand Down Expand Up @@ -177,6 +179,30 @@ def section_for(name)
expect(section.partition_nr).to be_nil
end
end

context "when it is used as an LVM physical volume" do
let(:lvm_vg) { instance_double(Y2Storage::LvmVg, basename: "vg0") }
let(:lvm_pv) do
instance_double(
Y2Storage::LvmPv,
lvm_vg: lvm_vg
)
end

it "initializes #lvm_group" do
section = described_class.new_from_storage(md)
expect(section.lvm_group).to eq("vg0")
end

context "but it does not belong to any volume group" do
let(:lvm_vg) { nil }

it "does not initialize #lvm_group" do
section = described_class.new_from_storage(md)
expect(section.lvm_group).to be_nil
end
end
end
end

context "when filesystem is btrfs" do
Expand Down