Hobo boot process loads the UUID as VM object rather than the raw UUID.

This commit is contained in:
Mitchell Hashimoto 2010-01-31 01:16:44 -08:00
parent 66a62ad19a
commit a394f1cd5f
4 changed files with 29 additions and 26 deletions

View File

@ -11,18 +11,18 @@ module Hobo
}
# Initialize class variables used
@@persisted_uuid = nil
@@persisted_vm = nil
@@root_path = nil
class << self
def persisted_uuid; @@persisted_uuid; end
def persisted_vm; @@persisted_vm; end
def root_path; @@root_path; end
def dotfile_path; File.join(root_path, Hobo.config[:dotfile_name]); end
def load!
load_root_path!
load_config!
load_uuid!
load_vm!
end
def ensure_directories
@ -46,17 +46,17 @@ module Hobo
Hobo.config!(parsed)
end
def load_uuid!
def load_vm!
File.open(dotfile_path) do |f|
@@persisted_uuid = f.read
@@persisted_vm = VirtualBox::VM.find(f.read)
end
rescue Errno::ENOENT
@@persisted_uuid = nil
@@persisted_vm = nil
end
def persist_uuid(uuid)
def persist_vm(vm)
File.open(dotfile_path, 'w+') do |f|
f.write(uuid)
f.write(vm.uuid)
end
end

View File

@ -5,7 +5,7 @@ module Hobo
# provisions it.
def up
vm = import
persist_uuid(vm)
persist_vm(vm)
setup_mac_address(vm)
forward_ssh(vm)
setup_shared_folder(vm)
@ -16,9 +16,9 @@ module Hobo
VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
end
def persist_uuid(vm)
def persist_vm(vm)
HOBO_LOGGER.info "Persisting the VM UUID (#{vm.uuid})..."
Env.persist_uuid(vm.uuid)
Env.persist_vm(vm)
end
def setup_mac_address(vm)

View File

@ -21,7 +21,7 @@ class EnvTest < Test::Unit::TestCase
context "initial load" do
test "load! should load the config and set the persisted_uid" do
Hobo::Env.expects(:load_config!).once
Hobo::Env.expects(:load_uuid!).once
Hobo::Env.expects(:load_vm!).once
Hobo::Env.expects(:load_root_path!).once
Hobo::Env.load!
end
@ -79,18 +79,19 @@ class EnvTest < Test::Unit::TestCase
end
end
context "persisting the UUID into a file" do
context "persisting the VM into a file" do
setup do
Hobo.config! hobo_mock_config
end
test "should save it to the dotfile path" do
uuid = "foo"
vm = mock("vm")
vm.stubs(:uuid).returns("foo")
filemock = mock("filemock")
filemock.expects(:write).with(uuid)
filemock.expects(:write).with(vm.uuid)
File.expects(:open).with(Hobo::Env.dotfile_path, 'w+').once.yields(filemock)
Hobo::Env.persist_uuid(uuid)
Hobo::Env.persist_vm(vm)
end
end
@ -100,17 +101,19 @@ class EnvTest < Test::Unit::TestCase
end
test "loading of the uuid from the dotfile" do
VirtualBox::VM.expects(:find).with("foo").returns("foovm")
filemock = mock("filemock")
filemock.expects(:read).returns("foo")
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
Hobo::Env.load_uuid!
assert_equal Hobo::Env.persisted_uuid, 'foo'
Hobo::Env.load_vm!
assert_equal 'foovm', Hobo::Env.persisted_vm
end
test "uuid should be nil if dotfile didn't exist" do
File.expects(:open).raises(Errno::ENOENT)
Hobo::Env.load_uuid!
assert_nil Hobo::Env.persisted_uuid
Hobo::Env.load_vm!
assert_nil Hobo::Env.persisted_vm
end
test "should build up the dotfile out of the root path and the dotfile name" do

View File

@ -10,7 +10,7 @@ class VMTest < Test::Unit::TestCase
should "create the instance in the proper order" do
create_seq = sequence("create_seq")
Hobo::VM.expects(:import).in_sequence(create_seq)
Hobo::VM.expects(:persist_uuid).in_sequence(create_seq)
Hobo::VM.expects(:persist_vm).in_sequence(create_seq)
Hobo::VM.expects(:setup_mac_address).in_sequence(create_seq)
Hobo::VM.expects(:forward_ssh).in_sequence(create_seq)
Hobo::VM.expects(:setup_shared_folder).in_sequence(create_seq)
@ -30,11 +30,11 @@ class VMTest < Test::Unit::TestCase
end
end
context "persisting UUID" do
should "persist the UUID with Env" do
@vm.stubs(:uuid).returns("FOO")
Hobo::Env.expects(:persist_uuid).with(@vm.uuid).once
Hobo::VM.persist_uuid(@vm)
context "persisting VM" do
should "persist the VM with Env" do
@vm.stubs(:uuid)
Hobo::Env.expects(:persist_vm).with(@vm).once
Hobo::VM.persist_vm(@vm)
end
end