Permalink
Browse files

Recreate VM resolution now handles disk already being detached

  • Loading branch information...
1 parent 1464618 commit adeed9ae4a5d4a6e67967dd9619e8d14697395a9 Jeffrey Peckham and Sean Swedai committed Mar 27, 2013
@@ -493,8 +493,8 @@ def detach_ebs_volume(instance, volume, force=false)
end
if device_map[volume.id].nil?
- cloud_error("Disk `#{volume.id}' is not attached " \
- "to instance `#{instance.id}'")
+ raise Bosh::Clouds::DiskNotAttached.new(true),
+ "Disk `#{volume.id}' is not attached to instance `#{instance.id}'"
end
attachment = volume.detach_from(instance, device_map[volume.id], force: force)
@@ -108,10 +108,15 @@ def recreate_vm(vm)
# to ignore "VM not found" errors in `delete_vm' and let the method
# proceed creating a new VM. Other errors are not forgiven.
begin
- if disk_cid
- cloud.detach_disk(vm.cid, disk_cid)
+ begin
+ if disk_cid
+ cloud.detach_disk(vm.cid, disk_cid)
+ end
+ rescue Bosh::Clouds::DiskNotAttached => e
+ @logger.warn("Disk '#{disk_cid}' was already detached from '#{vm.cid}'")
end
+
cloud.delete_vm(vm.cid)
rescue Bosh::Clouds::VMNotFound => e
@logger.warn("VM '#{vm.cid}' might have already been deleted from the cloud")
@@ -120,31 +120,63 @@ def fake_job_context
Bosh::Director::Models::PersistentDisk.make(disk_cid: "disk-cid", instance_id: instance.id)
end
- it "recreates VM (w/persistent disk)" do
- fake_cloud.should_receive(:detach_disk).with("vm-cid", "disk-cid").ordered
- fake_cloud.should_receive(:delete_vm).with("vm-cid").ordered
- fake_cloud.should_receive(:create_vm).
- with("agent-222", "sc-302", {"foo" => "bar"}, ["A", "B", "C"], ["disk-cid"], {"key1" => "value1"}).
- ordered.and_return("new-vm-cid")
-
- fake_new_agent.should_receive(:wait_until_ready).ordered
- fake_cloud.should_receive(:attach_disk).with("new-vm-cid", "disk-cid").ordered
-
- fake_new_agent.should_receive(:mount_disk).with("disk-cid").ordered
- fake_new_agent.should_receive(:apply).with(spec).ordered
- fake_new_agent.should_receive(:start).ordered
-
- fake_job_context
-
- expect {
- test_problem_handler.apply_resolution(:recreate_vm)
- }.to change { Bosh::Director::Models::Vm.where(agent_id: "agent-007").count }.from(1).to(0)
+ context "and the disk is attached" do
+
+ it "recreates VM (w/persistent disk)" do
+ fake_cloud.should_receive(:detach_disk).with("vm-cid", "disk-cid").ordered
+ fake_cloud.should_receive(:delete_vm).with("vm-cid").ordered
+ fake_cloud.should_receive(:create_vm).
+ with("agent-222", "sc-302", {"foo" => "bar"}, ["A", "B", "C"], ["disk-cid"], {"key1" => "value1"}).
+ ordered.and_return("new-vm-cid")
+
+ fake_new_agent.should_receive(:wait_until_ready).ordered
+ fake_cloud.should_receive(:attach_disk).with("new-vm-cid", "disk-cid").ordered
+
+ fake_new_agent.should_receive(:mount_disk).with("disk-cid").ordered
+ fake_new_agent.should_receive(:apply).with(spec).ordered
+ fake_new_agent.should_receive(:start).ordered
+
+ fake_job_context
+
+ expect {
+ test_problem_handler.apply_resolution(:recreate_vm)
+ }.to change { Bosh::Director::Models::Vm.where(agent_id: "agent-007").count }.from(1).to(0)
+
+ instance.reload
+ instance.vm.apply_spec.should == spec
+ instance.vm.cid.should == "new-vm-cid"
+ instance.vm.agent_id.should == "agent-222"
+ instance.persistent_disk.disk_cid.should == "disk-cid"
+ end
+ end
- instance.reload
- instance.vm.apply_spec.should == spec
- instance.vm.cid.should == "new-vm-cid"
- instance.vm.agent_id.should == "agent-222"
- instance.persistent_disk.disk_cid.should == "disk-cid"
+ context "and the disk is already detached" do
+ it "recreates VM (w/persistent disk)" do
+ fake_cloud.should_receive(:detach_disk).with("vm-cid", "disk-cid").ordered.and_raise(Bosh::Clouds::DiskNotAttached.new(true))
+ fake_cloud.should_receive(:delete_vm).with("vm-cid").ordered
+ fake_cloud.should_receive(:create_vm).
+ with("agent-222", "sc-302", {"foo" => "bar"}, ["A", "B", "C"], ["disk-cid"], {"key1" => "value1"}).
+ ordered.and_return("new-vm-cid")
+
+ fake_new_agent.should_receive(:wait_until_ready).ordered
+ fake_cloud.should_receive(:attach_disk).with("new-vm-cid", "disk-cid").ordered
+
+ fake_new_agent.should_receive(:mount_disk).with("disk-cid").ordered
+ fake_new_agent.should_receive(:apply).with(spec).ordered
+ fake_new_agent.should_receive(:start).ordered
+
+ fake_job_context
+
+ expect {
+ test_problem_handler.apply_resolution(:recreate_vm)
+ }.to change { Bosh::Director::Models::Vm.where(agent_id: "agent-007").count }.from(1).to(0)
+
+ instance.reload
+ instance.vm.apply_spec.should == spec
+ instance.vm.cid.should == "new-vm-cid"
+ instance.vm.agent_id.should == "agent-222"
+ instance.persistent_disk.disk_cid.should == "disk-cid"
+ end
end
end

0 comments on commit adeed9a

Please sign in to comment.