Skip to content

Commit

Permalink
Merge "mount_info_mismatch can reattach a disk to an instance/vm"
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic authored and Gerrit Code Review committed Apr 27, 2012
2 parents 5ff0682 + 4334c2f commit 414d49f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
17 changes: 15 additions & 2 deletions director/lib/director/problem_handlers/mount_info_mismatch.rb
Expand Up @@ -17,7 +17,10 @@ def initialize(disk_id, data)

@disk_cid = @disk.disk_cid
@vm_cid = @disk.instance.vm.cid if @disk.instance && @disk.instance.vm
handler_error("Can't find corresponding vm-cid for disk #{@disk_cid}") if @vm_cid.nil?
handler_error("Can't find corresponding vm-cid for disk `#{@disk_cid}'") if @vm_cid.nil?

@instance = @disk.instance
@vm = @instance.vm

@disk_owners = @data['owner_vms']
end
Expand All @@ -36,9 +39,19 @@ def description
end

resolution :ignore do
plan { "Ignore - Cannot be fixed using cloudcheck" }
plan { "Ignore" }
action { }
end

resolution :reattach_disk do
plan { "Reattach disk to instance" }
action { reattach_disk }
end

def reattach_disk
cloud.attach_disk(@vm_cid, @disk_cid)
agent_timeout_guard(@vm) { |agent| agent.mount_disk(@disk_cid) }
end
end
end
end
62 changes: 62 additions & 0 deletions director/spec/unit/problem_handlers/mount_info_mismatch_spec.rb
@@ -0,0 +1,62 @@
# Copyright (c) 2009-2012 VMware, Inc.

require File.expand_path("../../../spec_helper", __FILE__)

describe Bosh::Director::ProblemHandlers::MountInfoMismatch do

def make_handler(disk_id, data = {})
Bosh::Director::ProblemHandlers::MountInfoMismatch.new(disk_id, data)
end

before(:each) do
@cloud = mock("cloud")
@agent = mock("agent")

@vm = Bosh::Director::Models::Vm.make(:cid => "vm-cid")

@instance = Bosh::Director::Models::Instance.
make(:job => "mysql_node", :index => 3, :vm_id => @vm.id)

@disk = Bosh::Director::Models::PersistentDisk.
make(:disk_cid => "disk-cid", :instance_id => @instance.id,
:size => 300, :active => false)

@handler = make_handler(@disk.id, "owner_vms" => []) # Not mounted
@handler.stub!(:cloud).and_return(@cloud)
@handler.stub!(:agent_client).with(@instance.vm).and_return(@agent)
end

it "registers under inactive_disk type" do
handler = Bosh::Director::ProblemHandlers::Base.create_by_type(:mount_info_mismatch, @disk.id, {})
handler.should be_kind_of(Bosh::Director::ProblemHandlers::MountInfoMismatch)
end

it "has description" do
@handler.description.should =~ /Inconsistent mount information/
@handler.description.should =~ /Not mounted in any VM/
end

describe "invalid states" do
it "is invalid if disk is gone" do
@disk.destroy
lambda {
make_handler(@disk.id)
}.should raise_error("Disk `#{@disk.id}' is no longer in the database")
end

it "is invalid if disk no longer has associated instance" do
@instance.update(:vm => nil)
lambda {
make_handler(@disk.id)
}.should raise_error("Can't find corresponding vm-cid for disk `disk-cid'")
end

describe "reattach_disk" do
it "attaches disk" do
@cloud.should_receive(:attach_disk).with(@vm.cid, @disk.disk_cid)
@agent.should_receive(:mount_disk).with(@disk.disk_cid)
@handler.apply_resolution(:reattach_disk)
end
end
end
end

0 comments on commit 414d49f

Please sign in to comment.