Skip to content

Commit 66f6142

Browse files
committed
Persist updated disk CID before reattaching to ensure correct disk is used in attach_disk
1 parent 72d4210 commit 66f6142

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/bosh-director/lib/bosh/director/disk_manager.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,11 @@ def update_disk_cpi(instance_plan, new_disk, old_disk)
338338
updates[:disk_cid] = new_disk_cid
339339
end
340340

341-
attach_disk(old_disk_model, instance_plan.tags)
342-
341+
# Persist the updated CID (and size/cloud_properties) BEFORE reattaching.
342+
# The CPI may have replaced the disk (e.g. GCP snapshot-based type change),
343+
# so attach_disk must read the new CID from the model, not the stale one.
343344
old_disk_model.update(updates)
345+
attach_disk(old_disk_model, instance_plan.tags)
344346
@logger.info("Finished IaaS native update of disk '#{old_disk_model.disk_cid}'")
345347
end
346348

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ module Bosh::Director
289289
model = Models::PersistentDisk.where(instance_id: instance_model.id, active: true).first
290290
expect(model.disk_cid).to eq('new-disk-cid-from-cpi')
291291
end
292+
293+
it 'persists the new CID before reattaching so attach uses the correct disk' do
294+
allow(cloud).to receive(:update_disk).and_return('new-disk-cid-from-cpi')
295+
296+
disk_manager.update_persistent_disk(instance_plan)
297+
298+
expect(cloud).to have_received(:attach_disk).with('vm234', 'new-disk-cid-from-cpi')
299+
end
292300
end
293301

294302
context 'when CPI returns the same disk CID' do

0 commit comments

Comments
 (0)