Skip to content

Commit

Permalink
Merge 2b74d04 into 8010eef
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Aug 6, 2019
2 parents 8010eef + 2b74d04 commit 9eddcac
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib/y2storage/free_disk_space.rb
Expand Up @@ -34,6 +34,10 @@ class FreeDiskSpace
# @return [DiskSize]
attr_reader :disk

# there is Partition#disk vs. Partition#partitionable
# mirror this here
alias_method :partitionable, :disk

# @!attribute region
# @return [Region]
attr_reader :region
Expand Down
Expand Up @@ -350,7 +350,7 @@ def add_or_mark_growing_space(free_spaces, partition)
if result.none?(&:growing?)
# Use partition.region as starting point. After all, the exact start
# and end positions are not that relevant for our purposes.
new_space = FreeDiskSpace.new(partition.disk, partition.region)
new_space = FreeDiskSpace.new(partition.partitionable, partition.region)
new_space.growing = true
new_space.exists = false
result << new_space
Expand All @@ -370,7 +370,8 @@ def add_or_mark_growing_space(free_spaces, partition)
# @param partition [Partition] partition to be resized
# @return [Boolean]
def space_right_after_partition?(free_space, partition)
free_space.disk == partition.disk && free_space.region.start == partition.region.end + 1
free_space.partitionable == partition.partitionable &&
free_space.region.start == partition.region.end + 1
end

# All planned partitions to consider when resizing an existing partition
Expand Down
71 changes: 71 additions & 0 deletions test/data/devicegraphs/windows-pc-raid1.xml
@@ -0,0 +1,71 @@
<?xml version="1.0"?>
<Devicegraph>
<Devices>
<Disk>
<sid>42</sid>
<name>/dev/sdb</name>
<region>
<length>125829120</length>
<block-size>512</block-size>
</region>
</Disk>
<Disk>
<sid>43</sid>
<name>/dev/sda</name>
<region>
<length>125829120</length>
<block-size>512</block-size>
</region>
</Disk>
<Md>
<sid>44</sid>
<name>/dev/md0</name>
<region>
<length>125761536</length>
<block-size>512</block-size>
</region>
<md-level>RAID1</md-level>
</Md>
<Gpt>
<sid>45</sid>
</Gpt>
<Partition>
<sid>46</sid>
<name>/dev/md0p1</name>
<region>
<start>2048</start>
<length>125757440</length>
<block-size>512</block-size>
</region>
<type>primary</type>
<id>258</id>
</Partition>
<Ntfs>
<sid>47</sid>
</Ntfs>
</Devices>
<Holders>
<MdUser>
<source-sid>43</source-sid>
<target-sid>44</target-sid>
<sort-key>1</sort-key>
</MdUser>
<MdUser>
<source-sid>42</source-sid>
<target-sid>44</target-sid>
<sort-key>2</sort-key>
</MdUser>
<User>
<source-sid>44</source-sid>
<target-sid>45</target-sid>
</User>
<Subdevice>
<source-sid>45</source-sid>
<target-sid>46</target-sid>
</Subdevice>
<FilesystemUser>
<source-sid>46</source-sid>
<target-sid>47</target-sid>
</FilesystemUser>
</Holders>
</Devicegraph>
37 changes: 37 additions & 0 deletions test/y2storage/proposal/space_maker_test.rb
Expand Up @@ -646,6 +646,43 @@ def probed_partition(name)
end
end

# A partition on a RAID and a partition on a plain disk are treated
# differently (bsc#1139808) - see comment in Partition#disk.
#
context "with one RAID1 containing a single resizable Windows partition" do
let(:scenario) { "windows-pc-raid1.xml" }
let(:resize_info) do
instance_double("Y2Storage::ResizeInfo", resize_ok?: true, min_size: 1.GiB, max_size: 60.GiB,
reasons: 0, reason_texts: [])
end
let(:windows_partitions) { [partition_double("/dev/md0p1")] }
let(:resize_windows) { true }

before do
settings.candidate_devices = ["/dev/md0"]
settings.root_device = "/dev/md0"
allow_any_instance_of(Y2Storage::Partition).to receive(:detect_resize_info)
.and_return(resize_info)
end

context "with enough free space in the Windows partition" do
let(:vol1) { planned_vol(mount_point: "/1", type: :ext4, min: 40.GiB) }

it "shrinks the Windows partition by the required size" do
result = maker.provide_space(fake_devicegraph, volumes, lvm_helper)
win_partition = Y2Storage::Partition.find_by_name(result[:devicegraph], "/dev/md0p1")
expect(win_partition.size).to eq 20.GiB - 35.MiB
end

it "suggests a distribution using the freed space" do
result = maker.provide_space(fake_devicegraph, volumes, lvm_helper)
distribution = result[:partitions_distribution]
expect(distribution.spaces.size).to eq 1
expect(distribution.spaces.first.partitions).to eq volumes
end
end
end

context "if there are two Windows partitions" do
let(:scenario) { "double-windows-pc" }
let(:resize_info) do
Expand Down

0 comments on commit 9eddcac

Please sign in to comment.