Skip to content

Commit 6bde2ee

Browse files
committed
Add test coverage to new code added fr IaaS-native disk resize
1 parent c49276b commit 6bde2ee

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

src/bosh-director/lib/bosh/director/deployment_plan/persistent_disk_collection.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ def size_diff_only?(other)
147147

148148
def is_bigger_than?(other)
149149
unless other.is_a? PersistentDisk
150-
raise Exception, 'Cannot compare persistent disk size to anything
151-
that is not a persistent disk.'
150+
raise Exception, 'Cannot compare persistent disk size to anything that is not a persistent disk.'
152151
end
153152

154153
size >= other.size

src/bosh-director/spec/unit/deployment_plan/persistent_disk_collection_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,44 @@ module DeploymentPlan
349349
end
350350
end
351351
end
352+
353+
describe '#is_bigger_than?' do
354+
let(:new_disk) { new_disk = PersistentDiskCollection::PersistentDisk.new('', {}, 10) }
355+
356+
context 'when other thing is not a disk' do
357+
it 'raises an error' do
358+
old_disk = {}
359+
360+
expect {
361+
new_disk.is_bigger_than?(old_disk)
362+
}.to raise_error(/Cannot compare persistent disk size to anything that is not a persistent disk/)
363+
end
364+
end
365+
366+
context 'when the size is bigger' do
367+
it 'is true' do
368+
old_disk = PersistentDiskCollection::PersistentDisk.new('', {}, 5)
369+
370+
expect(new_disk.is_bigger_than?(old_disk)).to eq(true)
371+
end
372+
end
373+
374+
context 'when the size is equal' do
375+
it 'is true' do
376+
old_disk = PersistentDiskCollection::PersistentDisk.new('', {}, 10)
377+
378+
expect(new_disk.is_bigger_than?(old_disk)).to eq(true)
379+
end
380+
end
381+
382+
context 'when the size is smaller' do
383+
it 'is false' do
384+
old_disk = PersistentDiskCollection::PersistentDisk.new('', {}, 15)
385+
386+
expect(new_disk.is_bigger_than?(old_disk)).to eq(false)
387+
end
388+
end
389+
end
352390
end
353391
end
354392
end

src/bosh-director/spec/unit/disk_manager_spec.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ module Bosh::Director
239239
end
240240

241241
context 'when resize_disk is not supported' do
242-
let(:job_persistent_disk_size) { 512 }
242+
let(:job_persistent_disk_size) { 3072 }
243243

244244
it 'falls back to manually copying disk' do
245245
allow(cloud).to receive(:resize_disk).and_raise(Bosh::Clouds::NotSupported)
@@ -248,11 +248,24 @@ module Bosh::Director
248248

249249
expect(cloud).to have_received(:detach_disk).with('vm234', 'disk123').twice
250250
expect(cloud).to have_received(:resize_disk)
251-
expect(cloud).to have_received(:create_disk).with(512, { 'cloud' => 'properties' }, 'vm234')
251+
expect(cloud).to have_received(:create_disk).with(3072, { 'cloud' => 'properties' }, 'vm234')
252252
expect(cloud).to have_received(:attach_disk).with('vm234', 'disk123')
253253
expect(cloud).to have_received(:attach_disk).with('vm234', 'new-disk-cid')
254254
end
255255
end
256+
257+
context 'when shrinking disk' do
258+
let(:job_persistent_disk_size) { 512 }
259+
260+
it 'falls back to manually copying disk' do
261+
disk_manager.update_persistent_disk(instance_plan)
262+
263+
expect(cloud).not_to have_received(:resize_disk)
264+
expect(cloud).to have_received(:create_disk).with(512, { 'cloud' => 'properties' }, 'vm234')
265+
expect(cloud).to have_received(:attach_disk).with('vm234', 'new-disk-cid')
266+
expect(cloud).to have_received(:detach_disk).with('vm234', 'disk123')
267+
end
268+
end
256269
end
257270

258271
context 'when disk creation fails' do

0 commit comments

Comments
 (0)