From 3631ff00786db5b73a4cba9b3379f3a496c2776c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 30 Jan 2010 23:00:56 -0800 Subject: [PATCH] hobo-up persists the UUID of the VM --- .gitignore | 3 ++- lib/hobo/vm.rb | 12 ++++++------ test/hobo/vm_test.rb | 24 ++++++++++++++---------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index f21c2ce32..ba9126244 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ gembin/* vendor/gems/* pkg/* -Hobofile \ No newline at end of file +Hobofile +.hobo \ No newline at end of file diff --git a/lib/hobo/vm.rb b/lib/hobo/vm.rb index 9a56abfa2..8a04704fe 100644 --- a/lib/hobo/vm.rb +++ b/lib/hobo/vm.rb @@ -10,23 +10,23 @@ module Hobo forward_ssh(vm) setup_shared_folder(vm) end - + def import HOBO_LOGGER.info "Importing base VM (#{Hobo.config[:vm][:base]})..." VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base])) end - + def persist_uuid(vm) HOBO_LOGGER.info "Persisting the VM UUID (#{vm.uuid})..." - # TODO: persist it! dot file in the root (where Hobofile is) + Env.persist_uuid(vm.uuid) end - + def setup_mac_address(vm) HOBO_LOGGER.info "Matching MAC addresses..." vm.nics.first.macaddress = Hobo.config[:vm][:base_mac] vm.save(true) end - + def forward_ssh(vm) HOBO_LOGGER.info "Forwarding SSH ports..." port = VirtualBox::ForwardedPort.new @@ -36,7 +36,7 @@ module Hobo vm.forwarded_ports << port vm.save(true) end - + # TODO: We need to get the host path. def setup_shared_folder(vm) HOBO_LOGGER.info "Creating shared folders..." diff --git a/test/hobo/vm_test.rb b/test/hobo/vm_test.rb index c29d8037f..d8878c383 100644 --- a/test/hobo/vm_test.rb +++ b/test/hobo/vm_test.rb @@ -5,7 +5,7 @@ class VMTest < Test::Unit::TestCase @vm = mock("vm") Hobo.config!(hobo_mock_config) end - + context "hobo up" do should "create the instance in the proper order" do create_seq = sequence("create_seq") @@ -17,35 +17,39 @@ class VMTest < Test::Unit::TestCase Hobo::VM.up end end - + context "importing" do should "call import on VirtualBox::VM with the proper base" do VirtualBox::VM.expects(:import).once Hobo::VM.import end - + should "return the VM object" do VirtualBox::VM.expects(:import).returns(@vm).once assert_equal @vm, Hobo::VM.import end end - + context "persisting UUID" do - # TODO, functionality doesn't exist yet + 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) + end end - + context "setting up MAC address" do should "match the mac address with the base" do nic = mock("nic") nic.expects(:macaddress=).once - + @vm.expects(:nics).returns([nic]).once @vm.expects(:save).with(true).once - + Hobo::VM.setup_mac_address(@vm) end end - + context "forwarding SSH" do should "create a port forwarding for the VM" do # TODO: Test the actual port value to make sure it has the @@ -57,7 +61,7 @@ class VMTest < Test::Unit::TestCase Hobo::VM.forward_ssh(@vm) end end - + context "setting up the shared folder" do # TODO: Since the code actually doesn't do anything yet end