Hobo boot process loads the UUID as VM object rather than the raw UUID.
This commit is contained in:
parent
66a62ad19a
commit
a394f1cd5f
|
@ -11,18 +11,18 @@ module Hobo
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize class variables used
|
# Initialize class variables used
|
||||||
@@persisted_uuid = nil
|
@@persisted_vm = nil
|
||||||
@@root_path = nil
|
@@root_path = nil
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def persisted_uuid; @@persisted_uuid; end
|
def persisted_vm; @@persisted_vm; end
|
||||||
def root_path; @@root_path; end
|
def root_path; @@root_path; end
|
||||||
def dotfile_path; File.join(root_path, Hobo.config[:dotfile_name]); end
|
def dotfile_path; File.join(root_path, Hobo.config[:dotfile_name]); end
|
||||||
|
|
||||||
def load!
|
def load!
|
||||||
load_root_path!
|
load_root_path!
|
||||||
load_config!
|
load_config!
|
||||||
load_uuid!
|
load_vm!
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_directories
|
def ensure_directories
|
||||||
|
@ -46,17 +46,17 @@ module Hobo
|
||||||
Hobo.config!(parsed)
|
Hobo.config!(parsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_uuid!
|
def load_vm!
|
||||||
File.open(dotfile_path) do |f|
|
File.open(dotfile_path) do |f|
|
||||||
@@persisted_uuid = f.read
|
@@persisted_vm = VirtualBox::VM.find(f.read)
|
||||||
end
|
end
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
@@persisted_uuid = nil
|
@@persisted_vm = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def persist_uuid(uuid)
|
def persist_vm(vm)
|
||||||
File.open(dotfile_path, 'w+') do |f|
|
File.open(dotfile_path, 'w+') do |f|
|
||||||
f.write(uuid)
|
f.write(vm.uuid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Hobo
|
||||||
# provisions it.
|
# provisions it.
|
||||||
def up
|
def up
|
||||||
vm = import
|
vm = import
|
||||||
persist_uuid(vm)
|
persist_vm(vm)
|
||||||
setup_mac_address(vm)
|
setup_mac_address(vm)
|
||||||
forward_ssh(vm)
|
forward_ssh(vm)
|
||||||
setup_shared_folder(vm)
|
setup_shared_folder(vm)
|
||||||
|
@ -16,9 +16,9 @@ module Hobo
|
||||||
VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
|
VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def persist_uuid(vm)
|
def persist_vm(vm)
|
||||||
HOBO_LOGGER.info "Persisting the VM UUID (#{vm.uuid})..."
|
HOBO_LOGGER.info "Persisting the VM UUID (#{vm.uuid})..."
|
||||||
Env.persist_uuid(vm.uuid)
|
Env.persist_vm(vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_mac_address(vm)
|
def setup_mac_address(vm)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class EnvTest < Test::Unit::TestCase
|
||||||
context "initial load" do
|
context "initial load" do
|
||||||
test "load! should load the config and set the persisted_uid" do
|
test "load! should load the config and set the persisted_uid" do
|
||||||
Hobo::Env.expects(:load_config!).once
|
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.expects(:load_root_path!).once
|
||||||
Hobo::Env.load!
|
Hobo::Env.load!
|
||||||
end
|
end
|
||||||
|
@ -79,18 +79,19 @@ class EnvTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "persisting the UUID into a file" do
|
context "persisting the VM into a file" do
|
||||||
setup do
|
setup do
|
||||||
Hobo.config! hobo_mock_config
|
Hobo.config! hobo_mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should save it to the dotfile path" do
|
test "should save it to the dotfile path" do
|
||||||
uuid = "foo"
|
vm = mock("vm")
|
||||||
|
vm.stubs(:uuid).returns("foo")
|
||||||
|
|
||||||
filemock = mock("filemock")
|
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)
|
File.expects(:open).with(Hobo::Env.dotfile_path, 'w+').once.yields(filemock)
|
||||||
Hobo::Env.persist_uuid(uuid)
|
Hobo::Env.persist_vm(vm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,17 +101,19 @@ class EnvTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "loading of the uuid from the dotfile" do
|
test "loading of the uuid from the dotfile" do
|
||||||
|
VirtualBox::VM.expects(:find).with("foo").returns("foovm")
|
||||||
|
|
||||||
filemock = mock("filemock")
|
filemock = mock("filemock")
|
||||||
filemock.expects(:read).returns("foo")
|
filemock.expects(:read).returns("foo")
|
||||||
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
||||||
Hobo::Env.load_uuid!
|
Hobo::Env.load_vm!
|
||||||
assert_equal Hobo::Env.persisted_uuid, 'foo'
|
assert_equal 'foovm', Hobo::Env.persisted_vm
|
||||||
end
|
end
|
||||||
|
|
||||||
test "uuid should be nil if dotfile didn't exist" do
|
test "uuid should be nil if dotfile didn't exist" do
|
||||||
File.expects(:open).raises(Errno::ENOENT)
|
File.expects(:open).raises(Errno::ENOENT)
|
||||||
Hobo::Env.load_uuid!
|
Hobo::Env.load_vm!
|
||||||
assert_nil Hobo::Env.persisted_uuid
|
assert_nil Hobo::Env.persisted_vm
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should build up the dotfile out of the root path and the dotfile name" do
|
test "should build up the dotfile out of the root path and the dotfile name" do
|
||||||
|
|
|
@ -10,7 +10,7 @@ class VMTest < Test::Unit::TestCase
|
||||||
should "create the instance in the proper order" do
|
should "create the instance in the proper order" do
|
||||||
create_seq = sequence("create_seq")
|
create_seq = sequence("create_seq")
|
||||||
Hobo::VM.expects(:import).in_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(:setup_mac_address).in_sequence(create_seq)
|
||||||
Hobo::VM.expects(:forward_ssh).in_sequence(create_seq)
|
Hobo::VM.expects(:forward_ssh).in_sequence(create_seq)
|
||||||
Hobo::VM.expects(:setup_shared_folder).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
|
||||||
end
|
end
|
||||||
|
|
||||||
context "persisting UUID" do
|
context "persisting VM" do
|
||||||
should "persist the UUID with Env" do
|
should "persist the VM with Env" do
|
||||||
@vm.stubs(:uuid).returns("FOO")
|
@vm.stubs(:uuid)
|
||||||
Hobo::Env.expects(:persist_uuid).with(@vm.uuid).once
|
Hobo::Env.expects(:persist_vm).with(@vm).once
|
||||||
Hobo::VM.persist_uuid(@vm)
|
Hobo::VM.persist_vm(@vm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue