From a394f1cd5fdb06496acaeb8d1d5bc21597f5afa7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 31 Jan 2010 01:16:44 -0800 Subject: [PATCH] Hobo boot process loads the UUID as VM object rather than the raw UUID. --- lib/hobo/env.rb | 16 ++++++++-------- lib/hobo/vm.rb | 6 +++--- test/hobo/env_test.rb | 21 ++++++++++++--------- test/hobo/vm_test.rb | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/hobo/env.rb b/lib/hobo/env.rb index 6ddf80409..0790630fc 100644 --- a/lib/hobo/env.rb +++ b/lib/hobo/env.rb @@ -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 diff --git a/lib/hobo/vm.rb b/lib/hobo/vm.rb index 8a04704fe..9774f62ab 100644 --- a/lib/hobo/vm.rb +++ b/lib/hobo/vm.rb @@ -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) diff --git a/test/hobo/env_test.rb b/test/hobo/env_test.rb index 35daff069..861f69098 100644 --- a/test/hobo/env_test.rb +++ b/test/hobo/env_test.rb @@ -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 diff --git a/test/hobo/vm_test.rb b/test/hobo/vm_test.rb index d8878c383..7ba4ae402 100644 --- a/test/hobo/vm_test.rb +++ b/test/hobo/vm_test.rb @@ -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