Skip to content

Commit

Permalink
Merge pull request #691 from ancorgs/partition_type_merge
Browse files Browse the repository at this point in the history
Merge into master: offer only correct regions to create partitions
  • Loading branch information
ancorgs committed Jul 19, 2018
2 parents 5defcc2 + cf8926f commit ac474af
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
7 changes: 7 additions & 0 deletions package/yast2-storage-ng.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Jul 18 19:00:11 UTC 2018 - ancor@suse.com

- Partitioner: when creating a partition, use only regions of
the selected type: primary, logical or extended (bsc#1097634).
- 4.0.198

-------------------------------------------------------------------
Wed Jul 18 11:38:39 UTC 2018 - ancor@suse.com

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

Name: yast2-storage-ng
Version: 4.0.197
Version: 4.0.198
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
6 changes: 3 additions & 3 deletions src/lib/y2partitioner/dialogs/partition_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def initialize(controller)
textdomain "storage"
@disk_name = controller.disk_name
@controller = controller
# FIXME: the available regions should be filtered based on controller.type
@regions = controller.unused_slots.map(&:region)
@optimal_regions = controller.unused_optimal_slots.map(&:region)
type = controller.type
@regions = controller.unused_slots.select { |s| s.possible?(type) }.map(&:region)
@optimal_regions = controller.unused_optimal_slots.select { |s| s.possible?(type) }.map(&:region)

raise ArgumentError, "No region to make a partition in" if @optimal_regions.empty?
end
Expand Down
62 changes: 53 additions & 9 deletions test/y2partitioner/dialogs/partition_size_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,70 @@

let(:controller) do
pt = Y2Partitioner::Actions::Controllers::Partition.new(disk)
pt.region = region
pt.custom_size = Y2Storage::DiskSize.MiB(1)
pt.type = partition_type
pt
end
let(:disk) { "/dev/sda" }
let(:region) { Y2Storage::Region.create(2000, 1000, Y2Storage::DiskSize.new(1500)) }
let(:slot) { double("PartitionSlot", region: region) }
let(:regions) { [region] }
let(:optimal_regions) { [region] }

let(:region_prim1) { Y2Storage::Region.create(2000, 1000, Y2Storage::DiskSize.new(1500)) }
let(:region_log) { Y2Storage::Region.create(3001, 1000, Y2Storage::DiskSize.new(1500)) }
let(:region_prim2) { Y2Storage::Region.create(4001, 1000, Y2Storage::DiskSize.new(1500)) }
let(:slot_prim1) { double("PartitionSlot", region: region_prim1) }
let(:slot_log) { double("PartitionSlot", region: region_log) }
let(:slot_prim2) { double("PartitionSlot", region: region_prim2) }

let(:partition_type) { Y2Storage::PartitionType::LOGICAL }
let(:regions) { [region_log] }
let(:optimal_regions) { [region_log] }

before do
allow(slot_prim1).to receive(:possible?) do |type|
type != Y2Storage::PartitionType::LOGICAL
end
allow(slot_prim2).to receive(:possible?) do |type|
type != Y2Storage::PartitionType::LOGICAL
end
allow(slot_log).to receive(:possible?) do |type|
type == Y2Storage::PartitionType::LOGICAL
end
end

describe Y2Partitioner::Dialogs::PartitionSize do
subject { described_class.new(controller) }
subject(:dialog) { described_class.new(controller) }

before do
allow(Y2Partitioner::Dialogs::PartitionSize::SizeWidget)
.to receive(:new).and_return(term(:Empty))
allow(controller).to receive(:unused_slots).and_return [slot]
allow(controller).to receive(:unused_optimal_slots).and_return [slot]
allow(controller).to receive(:unused_slots).and_return [slot_prim1, slot_log, slot_prim2]
allow(controller).to receive(:unused_optimal_slots).and_return [slot_prim1, slot_log, slot_prim2]
end

include_examples "CWM::Dialog"

describe "#content" do
context "when creating a primary partition" do
let(:partition_type) { Y2Storage::PartitionType::PRIMARY }

it "offers only the regions of the primary slots" do
expect(Y2Partitioner::Dialogs::PartitionSize::SizeWidget).to receive(:new)
.with(controller, [region_prim1, region_prim2], [region_prim1, region_prim2])

dialog.contents
end
end

context "when creating a logical partition" do
let(:partition_type) { Y2Storage::PartitionType::LOGICAL }

it "offers only the region of the logical slot" do
expect(Y2Partitioner::Dialogs::PartitionSize::SizeWidget).to receive(:new)
.with(controller, [region_log], [region_log])

dialog.contents
end
end
end
end

describe Y2Partitioner::Dialogs::PartitionSize::SizeWidget do
Expand Down Expand Up @@ -170,7 +214,7 @@
let(:entered_start) { 2200 }
let(:entered_end) { 2500 }

subject { described_class.new(controller, regions, region) }
subject { described_class.new(controller, regions, region_log) }

include_examples "CWM::CustomWidget"

Expand Down

0 comments on commit ac474af

Please sign in to comment.