And then God said unto thee, "You shall be named Vagrant."
This commit is contained in:
parent
3b08a877c2
commit
c1998d2127
4
Rakefile
4
Rakefile
|
@ -3,11 +3,11 @@ require 'rake/testtask'
|
|||
begin
|
||||
require 'jeweler'
|
||||
Jeweler::Tasks.new do |gemspec|
|
||||
gemspec.name = "hobo"
|
||||
gemspec.name = "vagrant"
|
||||
gemspec.summary = "Create virtualized development environments"
|
||||
gemspec.description = "Create virtualized development environments"
|
||||
gemspec.email = "todo@todo.com"
|
||||
gemspec.homepage = "http://github.com/mitchellh/hobo"
|
||||
gemspec.homepage = "http://github.com/mitchellh/vagrant"
|
||||
gemspec.authors = ["Mitchell Hashimoto", "John Bender"]
|
||||
|
||||
gemspec.add_dependency('virtualbox', '>= 0.4.3')
|
||||
|
|
|
@ -8,21 +8,21 @@ end
|
|||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "destroys the hobo environment"
|
||||
short_desc "destroys the vagrant environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Destroys the hobo environment.
|
||||
Destroys the vagrant environment.
|
||||
|
||||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.down
|
||||
Vagrant::VM.down
|
||||
end
|
||||
end
|
|
@ -8,21 +8,21 @@ end
|
|||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "resumes the hobo environment"
|
||||
short_desc "resumes the vagrant environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Resumes the hobo environment.
|
||||
Resumes the vagrant environment.
|
||||
|
||||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.resume
|
||||
Vagrant::VM.resume
|
||||
end
|
||||
end
|
|
@ -8,10 +8,10 @@ end
|
|||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "opens an SSH connection into the VM"
|
||||
|
@ -23,6 +23,6 @@ Opens an SSH connection into the created VM.
|
|||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.ssh
|
||||
Vagrant::VM.ssh
|
||||
end
|
||||
end
|
|
@ -8,21 +8,21 @@ end
|
|||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "create the hobo environment"
|
||||
short_desc "suspends the vagrant environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Create the hobo environment.
|
||||
Suspends the vagrant environment.
|
||||
|
||||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.up
|
||||
Vagrant::VM.suspend
|
||||
end
|
||||
end
|
|
@ -8,21 +8,21 @@ end
|
|||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "suspends the hobo environment"
|
||||
short_desc "create the vagrant environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Suspends the hobo environment.
|
||||
Create the vagrant environment.
|
||||
|
||||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.suspend
|
||||
Vagrant::VM.up
|
||||
end
|
||||
end
|
|
@ -1,21 +1,21 @@
|
|||
Hobo::Config.run do |config|
|
||||
Vagrant::Config.run do |config|
|
||||
# default config goes here
|
||||
config.ssh.username = "hobo"
|
||||
config.ssh.password = "hobo"
|
||||
config.ssh.username = "vagrant"
|
||||
config.ssh.password = "vagrant"
|
||||
config.ssh.host = "localhost"
|
||||
config.ssh.forwarded_port_key = "ssh"
|
||||
config.ssh.max_tries = 10
|
||||
|
||||
config.dotfile_name = ".hobo"
|
||||
config.dotfile_name = ".vagrant"
|
||||
|
||||
config.vm.base = "~/.hobo/base/base.ovf"
|
||||
config.vm.base = "~/.vagrant/base/base.ovf"
|
||||
config.vm.base_mac = "0800279C2E41"
|
||||
config.vm.project_directory = "/hobo"
|
||||
config.vm.project_directory = "/vagrant"
|
||||
config.vm.forward_port("ssh", 22, 2222)
|
||||
|
||||
config.chef.cookbooks_path = "cookbooks"
|
||||
config.chef.provisioning_path = "/tmp/hobo-chef"
|
||||
config.chef.provisioning_path = "/tmp/vagrant-chef"
|
||||
config.chef.json = {
|
||||
:recipes => ["hobo_main"]
|
||||
:recipes => ["vagrant_main"]
|
||||
}
|
||||
end
|
24
lib/hobo.rb
24
lib/hobo.rb
|
@ -1,24 +0,0 @@
|
|||
libdir = File.dirname(__FILE__)
|
||||
$:.unshift(libdir)
|
||||
PROJECT_ROOT = File.join(libdir, '..')
|
||||
|
||||
require 'ftools'
|
||||
require 'json'
|
||||
require 'pathname'
|
||||
require 'logger'
|
||||
require 'virtualbox'
|
||||
require 'net/ssh'
|
||||
require 'net/scp'
|
||||
require 'ping'
|
||||
require 'hobo/busy'
|
||||
require 'hobo/util'
|
||||
require 'hobo/config'
|
||||
require 'hobo/env'
|
||||
require 'hobo/provisioning'
|
||||
require 'hobo/ssh'
|
||||
require 'hobo/vm'
|
||||
|
||||
# TODO: Make this configurable
|
||||
log_output = ENV['HOBO_ENV'] == 'test' ? nil : STDOUT
|
||||
HOBO_LOGGER = Hobo::Logger.new(log_output)
|
||||
Hobo::Env.load! unless ENV['HOBO_ENV'] == 'test'
|
|
@ -1,44 +0,0 @@
|
|||
module Hobo
|
||||
class SSH
|
||||
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh')
|
||||
|
||||
class << self
|
||||
def connect(opts={})
|
||||
options = {}
|
||||
[:host, :password, :username].each do |param|
|
||||
options[param] = opts[param] || Hobo.config.ssh.send(param)
|
||||
end
|
||||
|
||||
# The port is special
|
||||
options[:port] = opts[:port] || Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
||||
|
||||
Kernel.exec "#{SCRIPT} #{options[:username]} #{options[:password]} #{options[:host]} #{options[:port]}".strip
|
||||
end
|
||||
|
||||
def execute
|
||||
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
||||
Net::SSH.start(Hobo.config.ssh.host, Hobo.config[:ssh][:username], :port => port, :password => Hobo.config[:ssh][:password]) do |ssh|
|
||||
yield ssh
|
||||
end
|
||||
end
|
||||
|
||||
def upload!(from, to)
|
||||
execute do |ssh|
|
||||
scp = Net::SCP.new(ssh)
|
||||
scp.upload!(from, to)
|
||||
end
|
||||
end
|
||||
|
||||
def up?
|
||||
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
||||
Net::SSH.start(Hobo.config.ssh.host, Hobo.config.ssh.username, :port => port, :password => Hobo.config.ssh.password, :timeout => 5) do |ssh|
|
||||
return true
|
||||
end
|
||||
|
||||
false
|
||||
rescue Errno::ECONNREFUSED
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
libdir = File.dirname(__FILE__)
|
||||
$:.unshift(libdir)
|
||||
PROJECT_ROOT = File.join(libdir, '..')
|
||||
|
||||
require 'ftools'
|
||||
require 'json'
|
||||
require 'pathname'
|
||||
require 'logger'
|
||||
require 'virtualbox'
|
||||
require 'net/ssh'
|
||||
require 'net/scp'
|
||||
require 'ping'
|
||||
require 'vagrant/busy'
|
||||
require 'vagrant/util'
|
||||
require 'vagrant/config'
|
||||
require 'vagrant/env'
|
||||
require 'vagrant/provisioning'
|
||||
require 'vagrant/ssh'
|
||||
require 'vagrant/vm'
|
||||
|
||||
# TODO: Make this configurable
|
||||
log_output = ENV['VAGRANT_ENV'] == 'test' ? nil : STDOUT
|
||||
VAGRANT_LOGGER = Vagrant::Logger.new(log_output)
|
||||
Vagrant::Env.load! unless ENV['VAGRANT_ENV'] == 'test'
|
|
@ -1,4 +1,4 @@
|
|||
module Hobo
|
||||
module Vagrant
|
||||
def self.busy?
|
||||
Busy.busy?
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module Hobo
|
||||
module Vagrant
|
||||
def self.config
|
||||
Config.config
|
||||
end
|
|
@ -1,19 +1,19 @@
|
|||
require 'yaml'
|
||||
|
||||
module Hobo
|
||||
module Vagrant
|
||||
class Env
|
||||
HOBOFILE_NAME = "Hobofile"
|
||||
ROOTFILE_NAME = "Vagrantfile"
|
||||
|
||||
# Initialize class variables used
|
||||
@@persisted_vm = nil
|
||||
@@root_path = nil
|
||||
|
||||
extend Hobo::Util
|
||||
|
||||
extend Vagrant::Util
|
||||
|
||||
class << self
|
||||
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 dotfile_path; File.join(root_path, Vagrant.config.dotfile_name); end
|
||||
|
||||
def load!
|
||||
load_root_path!
|
||||
|
@ -24,11 +24,11 @@ module Hobo
|
|||
def load_config!
|
||||
load_paths = [
|
||||
File.join(PROJECT_ROOT, "config", "default.rb"),
|
||||
File.join(root_path, HOBOFILE_NAME)
|
||||
File.join(root_path, ROOTFILE_NAME)
|
||||
]
|
||||
|
||||
load_paths.each do |path|
|
||||
HOBO_LOGGER.info "Loading config from #{path}..."
|
||||
VAGRANT_LOGGER.info "Loading config from #{path}..."
|
||||
load path if File.exist?(path)
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Hobo
|
|||
|
||||
def load_vm!
|
||||
File.open(dotfile_path) do |f|
|
||||
@@persisted_vm = Hobo::VM.find(f.read)
|
||||
@@persisted_vm = Vagrant::VM.find(f.read)
|
||||
end
|
||||
rescue Errno::ENOENT
|
||||
@@persisted_vm = nil
|
||||
|
@ -53,15 +53,15 @@ module Hobo
|
|||
def load_root_path!(path=Pathname.new(Dir.pwd))
|
||||
if path.to_s == '/'
|
||||
error_and_exit(<<-msg)
|
||||
A `Hobofile` was not found! This file is required for hobo to run
|
||||
since it describes the expected environment that hobo is supposed
|
||||
to manage. Please create a Hobofile and place it in your project
|
||||
A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
|
||||
since it describes the expected environment that vagrant is supposed
|
||||
to manage. Please create a #{ROOTFILE_NAME} and place it in your project
|
||||
root.
|
||||
msg
|
||||
return
|
||||
end
|
||||
|
||||
file = "#{path}/#{HOBOFILE_NAME}"
|
||||
file = "#{path}/#{ROOTFILE_NAME}"
|
||||
if File.exist?(file)
|
||||
@@root_path = path.to_s
|
||||
return
|
||||
|
@ -73,10 +73,10 @@ msg
|
|||
def require_persisted_vm
|
||||
if !persisted_vm
|
||||
error_and_exit(<<-error)
|
||||
The task you're trying to run requires that the hobo environment
|
||||
already be created, but unfortunately this hobo still appears to
|
||||
The task you're trying to run requires that the vagrant environment
|
||||
already be created, but unfortunately this vagrant still appears to
|
||||
have no box! You can setup the environment by setting up your
|
||||
Hobofile and running `hobo up`
|
||||
#{ROOTFILE_NAME} and running `vagrant up`
|
||||
error
|
||||
return
|
||||
end
|
|
@ -1,13 +1,13 @@
|
|||
module Hobo
|
||||
module Vagrant
|
||||
class Provisioning
|
||||
include Hobo::Util
|
||||
include Vagrant::Util
|
||||
|
||||
def initialize(vm)
|
||||
@vm = vm
|
||||
|
||||
# Share the cookbook folder. We'll use the provisioning path exclusively for
|
||||
# chef stuff.
|
||||
@vm.share_folder("hobo-provisioning", File.expand_path(Hobo.config.chef.cookbooks_path, Env.root_path), cookbooks_path)
|
||||
@vm.share_folder("vagrant-provisioning", File.expand_path(Vagrant.config.chef.cookbooks_path, Env.root_path), cookbooks_path)
|
||||
end
|
||||
|
||||
def run
|
||||
|
@ -20,29 +20,29 @@ module Hobo
|
|||
def chown_provisioning_folder
|
||||
logger.info "Setting permissions on provisioning folder..."
|
||||
SSH.execute do |ssh|
|
||||
ssh.exec!("sudo chown #{Hobo.config.ssh.username} #{Hobo.config.chef.provisioning_path}")
|
||||
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}")
|
||||
end
|
||||
end
|
||||
|
||||
def setup_json
|
||||
logger.info "Generating JSON and uploading..."
|
||||
SSH.upload!(StringIO.new(Hobo.config.chef.json.to_json), File.join(Hobo.config.chef.provisioning_path, "dna.json"))
|
||||
SSH.upload!(StringIO.new(Vagrant.config.chef.json.to_json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
|
||||
end
|
||||
|
||||
def setup_solo_config
|
||||
solo_file = <<-solo
|
||||
file_cache_path "#{Hobo.config.chef.provisioning_path}"
|
||||
file_cache_path "#{Vagrant.config.chef.provisioning_path}"
|
||||
cookbook_path "#{cookbooks_path}"
|
||||
solo
|
||||
|
||||
logger.info "Uploading chef-solo configuration script..."
|
||||
SSH.upload!(StringIO.new(solo_file), File.join(Hobo.config.chef.provisioning_path, "solo.rb"))
|
||||
SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "solo.rb"))
|
||||
end
|
||||
|
||||
def run_chef_solo
|
||||
logger.info "Running chef recipes..."
|
||||
SSH.execute do |ssh|
|
||||
ssh.exec!("cd #{Hobo.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
|
||||
ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
|
||||
# TODO: Very verbose. It would be easier to save the data and only show it during
|
||||
# an error, or when verbosity level is set high
|
||||
logger.info("#{stream}: #{data}")
|
||||
|
@ -51,7 +51,7 @@ solo
|
|||
end
|
||||
|
||||
def cookbooks_path
|
||||
File.join(Hobo.config.chef.provisioning_path, "cookbooks")
|
||||
File.join(Vagrant.config.chef.provisioning_path, "cookbooks")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
module Vagrant
|
||||
class SSH
|
||||
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'vagrant-ssh-expect.sh')
|
||||
|
||||
class << self
|
||||
def connect(opts={})
|
||||
options = {}
|
||||
[:host, :password, :username].each do |param|
|
||||
options[param] = opts[param] || Vagrant.config.ssh.send(param)
|
||||
end
|
||||
|
||||
# The port is special
|
||||
options[:port] = opts[:port] || Vagrant.config.vm.forwarded_ports[Vagrant.config.ssh.forwarded_port_key][:hostport]
|
||||
|
||||
Kernel.exec "#{SCRIPT} #{options[:username]} #{options[:password]} #{options[:host]} #{options[:port]}".strip
|
||||
end
|
||||
|
||||
def execute
|
||||
port = Vagrant.config.vm.forwarded_ports[Vagrant.config.ssh.forwarded_port_key][:hostport]
|
||||
Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config[:ssh][:username], :port => port, :password => Vagrant.config[:ssh][:password]) do |ssh|
|
||||
yield ssh
|
||||
end
|
||||
end
|
||||
|
||||
def upload!(from, to)
|
||||
execute do |ssh|
|
||||
scp = Net::SCP.new(ssh)
|
||||
scp.upload!(from, to)
|
||||
end
|
||||
end
|
||||
|
||||
def up?
|
||||
port = Vagrant.config.vm.forwarded_ports[Vagrant.config.ssh.forwarded_port_key][:hostport]
|
||||
Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => 5) do |ssh|
|
||||
return true
|
||||
end
|
||||
|
||||
false
|
||||
rescue Errno::ECONNREFUSED
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
module Hobo
|
||||
module Vagrant
|
||||
module Util
|
||||
def error_and_exit(error)
|
||||
puts <<-error
|
||||
=====================================================================
|
||||
Hobo experienced an error!
|
||||
Vagrant experienced an error!
|
||||
|
||||
#{error.chomp}
|
||||
=====================================================================
|
||||
|
@ -12,13 +12,13 @@ error
|
|||
end
|
||||
|
||||
def logger
|
||||
HOBO_LOGGER
|
||||
VAGRANT_LOGGER
|
||||
end
|
||||
end
|
||||
|
||||
class Logger < ::Logger
|
||||
def format_message(level, time, progname, msg)
|
||||
"[#{level} #{time.strftime('%m-%d-%Y %X')}] Hobo: #{msg}\n"
|
||||
"[#{level} #{time.strftime('%m-%d-%Y %X')}] Vagrant: #{msg}\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +1,10 @@
|
|||
module Hobo
|
||||
module Vagrant
|
||||
class VM
|
||||
HD_EXT_DEFAULT = 'VMDK'
|
||||
attr_reader :vm
|
||||
|
||||
extend Hobo::Util
|
||||
include Hobo::Util
|
||||
extend Vagrant::Util
|
||||
include Vagrant::Util
|
||||
|
||||
class << self
|
||||
# Bring up the virtual machine. Imports the base image and
|
||||
|
@ -25,29 +25,29 @@ module Hobo
|
|||
SSH.connect
|
||||
end
|
||||
|
||||
# Save the state of the current hobo environment to disk
|
||||
# Save the state of the current vagrant environment to disk
|
||||
def suspend
|
||||
Env.require_persisted_vm
|
||||
error_and_exit(<<-error) if Env.persisted_vm.saved?
|
||||
The hobo virtual environment you are trying to suspend is already in a
|
||||
The vagrant virtual environment you are trying to suspend is already in a
|
||||
suspended state.
|
||||
error
|
||||
logger.info "Saving VM state..."
|
||||
Env.persisted_vm.save_state(true)
|
||||
end
|
||||
|
||||
# Resume the current hobo environment from disk
|
||||
# Resume the current vagrant environment from disk
|
||||
def resume
|
||||
Env.require_persisted_vm
|
||||
error_and_exit(<<-error) unless Env.persisted_vm.saved?
|
||||
The hobo virtual environment you are trying to resume is not in a
|
||||
The vagrant virtual environment you are trying to resume is not in a
|
||||
suspended state.
|
||||
error
|
||||
Env.persisted_vm.start
|
||||
end
|
||||
|
||||
# Finds a virtual machine by a given UUID and either returns
|
||||
# a Hobo::VM object or returns nil.
|
||||
# a Vagrant::VM object or returns nil.
|
||||
def find(uuid)
|
||||
vm = VirtualBox::VM.find(uuid)
|
||||
return nil if vm.nil?
|
||||
|
@ -60,7 +60,7 @@ error
|
|||
end
|
||||
|
||||
def create
|
||||
share_folder("hobo-root", Env.root_path, Hobo.config.vm.project_directory)
|
||||
share_folder("vagrant-root", Env.root_path, Vagrant.config.vm.project_directory)
|
||||
|
||||
# Create the provisioning object, prior to doing anything so it can
|
||||
# set any configuration on the VM object prior to creation
|
||||
|
@ -68,7 +68,7 @@ error
|
|||
|
||||
# The path of righteousness
|
||||
import
|
||||
move_hd if Hobo.config[:vm][:hd_location]
|
||||
move_hd if Vagrant.config[:vm][:hd_location]
|
||||
persist
|
||||
setup_mac_address
|
||||
forward_ports
|
||||
|
@ -96,7 +96,7 @@ The virtual machine must be powered off to move its disk.
|
|||
error
|
||||
|
||||
old_image = hd.image.dup
|
||||
new_image_file = Hobo.config[:vm][:hd_location] + old_image.filename
|
||||
new_image_file = Vagrant.config[:vm][:hd_location] + old_image.filename
|
||||
|
||||
logger.info "Cloning current VM Disk to new location (#{ new_image_file })..."
|
||||
# TODO image extension default?
|
||||
|
@ -111,8 +111,8 @@ error
|
|||
end
|
||||
|
||||
def import
|
||||
logger.info "Importing base VM (#{Hobo.config[:vm][:base]})..."
|
||||
@vm = VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
|
||||
logger.info "Importing base VM (#{Vagrant.config[:vm][:base]})..."
|
||||
@vm = VirtualBox::VM.import(File.expand_path(Vagrant.config[:vm][:base]))
|
||||
end
|
||||
|
||||
def persist
|
||||
|
@ -122,15 +122,15 @@ error
|
|||
|
||||
def setup_mac_address
|
||||
logger.info "Matching MAC addresses..."
|
||||
@vm.nics.first.macaddress = Hobo.config[:vm][:base_mac]
|
||||
@vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac]
|
||||
@vm.save(true)
|
||||
end
|
||||
|
||||
def forward_ports
|
||||
HOBO_LOGGER.info "Forwarding ports..."
|
||||
logger.info "Forwarding ports..."
|
||||
|
||||
Hobo.config.vm.forwarded_ports.each do |name, options|
|
||||
HOBO_LOGGER.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
||||
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
||||
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
||||
port = VirtualBox::ForwardedPort.new
|
||||
port.name = name
|
||||
port.hostport = options[:hostport]
|
||||
|
@ -157,12 +157,12 @@ error
|
|||
def mount_shared_folders
|
||||
logger.info "Mounting shared folders..."
|
||||
|
||||
Hobo::SSH.execute do |ssh|
|
||||
Vagrant::SSH.execute do |ssh|
|
||||
shared_folders.each do |name, hostpath, guestpath|
|
||||
logger.info "-- #{name}: #{guestpath}"
|
||||
ssh.exec!("sudo mkdir -p #{guestpath}")
|
||||
ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}")
|
||||
ssh.exec!("sudo chown #{Hobo.config.ssh.username} #{guestpath}")
|
||||
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{guestpath}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -174,15 +174,15 @@ error
|
|||
# Now we have to wait for the boot to be successful
|
||||
logger.info "Waiting for VM to boot..."
|
||||
|
||||
Hobo.config[:ssh][:max_tries].to_i.times do |i|
|
||||
logger.info "Trying to connect (attempt ##{i+1} of #{Hobo.config[:ssh][:max_tries]})..."
|
||||
Vagrant.config[:ssh][:max_tries].to_i.times do |i|
|
||||
logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
|
||||
|
||||
if Hobo::SSH.up?
|
||||
if Vagrant::SSH.up?
|
||||
logger.info "VM booted and ready for use!"
|
||||
return true
|
||||
end
|
||||
|
||||
sleep 5 unless ENV['HOBO_ENV'] == 'test'
|
||||
sleep 5 unless ENV['VAGRANT_ENV'] == 'test'
|
||||
end
|
||||
|
||||
logger.info "Failed to connect to VM! Failed to boot?"
|
|
@ -1,46 +0,0 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
|
||||
class ConfigTest < Test::Unit::TestCase
|
||||
context "accessing configuration" do
|
||||
setup do
|
||||
Hobo::Config.run { |config| }
|
||||
Hobo::Config.execute!
|
||||
end
|
||||
|
||||
should "forward config to the class method" do
|
||||
assert_equal Hobo.config, Hobo::Config.config
|
||||
end
|
||||
end
|
||||
|
||||
context "initializing" do
|
||||
teardown do
|
||||
Hobo::Config.instance_variable_set(:@config_runners, nil)
|
||||
Hobo::Config.instance_variable_set(:@config, nil)
|
||||
end
|
||||
|
||||
should "not run the blocks right away" do
|
||||
obj = mock("obj")
|
||||
obj.expects(:foo).never
|
||||
Hobo::Config.run { |config| obj.foo }
|
||||
Hobo::Config.run { |config| obj.foo }
|
||||
Hobo::Config.run { |config| obj.foo }
|
||||
end
|
||||
|
||||
should "run the blocks when execute! is ran" do
|
||||
obj = mock("obj")
|
||||
obj.expects(:foo).times(2)
|
||||
Hobo::Config.run { |config| obj.foo }
|
||||
Hobo::Config.run { |config| obj.foo }
|
||||
Hobo::Config.execute!
|
||||
end
|
||||
|
||||
should "run the blocks with the same config object" do
|
||||
config = mock("config")
|
||||
config.expects(:foo).twice
|
||||
Hobo::Config.stubs(:config).returns(config)
|
||||
Hobo::Config.run { |config| config.foo }
|
||||
Hobo::Config.run { |config| config.foo }
|
||||
Hobo::Config.execute!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,7 +8,7 @@ rescue LoadError
|
|||
end
|
||||
|
||||
# This silences logger output
|
||||
ENV['HOBO_ENV'] = 'test'
|
||||
ENV['VAGRANT_ENV'] = 'test'
|
||||
|
||||
# ruby-debug, not necessary, but useful if we have it
|
||||
begin
|
||||
|
@ -16,16 +16,16 @@ begin
|
|||
rescue LoadError; end
|
||||
|
||||
|
||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'hobo')
|
||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'vagrant')
|
||||
require 'contest'
|
||||
require 'mocha'
|
||||
|
||||
class Test::Unit::TestCase
|
||||
def hobo_mock_config
|
||||
Hobo::Config.instance_variable_set(:@config_runners, nil)
|
||||
Hobo::Config.instance_variable_set(:@config, nil)
|
||||
def mock_config
|
||||
Vagrant::Config.instance_variable_set(:@config_runners, nil)
|
||||
Vagrant::Config.instance_variable_set(:@config, nil)
|
||||
|
||||
Hobo::Config.run do |config|
|
||||
Vagrant::Config.run do |config|
|
||||
config.dotfile_name = ".hobo"
|
||||
|
||||
config.ssh.username = "foo"
|
||||
|
@ -46,6 +46,6 @@ class Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
Hobo::Config.execute!
|
||||
Vagrant::Config.execute!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,36 +2,36 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
|
||||
class BusyTest < Test::Unit::TestCase
|
||||
context "during an action in a busy block" do
|
||||
should "hobo should report as busy" do
|
||||
Hobo.busy do
|
||||
# Inside the block Hobo.busy? should be true
|
||||
assert Hobo.busy?
|
||||
should "report as busy" do
|
||||
Vagrant.busy do
|
||||
# Inside the block Vagrant.busy? should be true
|
||||
assert Vagrant.busy?
|
||||
end
|
||||
|
||||
#After the block finishes Hobo.busy? should be false
|
||||
assert !Hobo.busy?
|
||||
#After the block finishes Vagrant.busy? should be false
|
||||
assert !Vagrant.busy?
|
||||
end
|
||||
|
||||
|
||||
should "set busy to false upon exception and reraise the error" do
|
||||
assert_raise Exception do
|
||||
Hobo.busy do
|
||||
assert Hobo.busy?
|
||||
Vagrant.busy do
|
||||
assert Vagrant.busy?
|
||||
raise Exception
|
||||
end
|
||||
end
|
||||
|
||||
assert !Hobo.busy?
|
||||
|
||||
assert !Vagrant.busy?
|
||||
end
|
||||
|
||||
should "report busy to the outside world regardless of thread" do
|
||||
Thread.new do
|
||||
Hobo.busy do
|
||||
Vagrant.busy do
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
|
||||
# While the above thread is executing hobo should be busy
|
||||
assert Hobo.busy?
|
||||
|
||||
# While the above thread is executing vagrant should be busy
|
||||
assert Vagrant.busy?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
|
||||
class ConfigTest < Test::Unit::TestCase
|
||||
context "accessing configuration" do
|
||||
setup do
|
||||
Vagrant::Config.run { |config| }
|
||||
Vagrant::Config.execute!
|
||||
end
|
||||
|
||||
should "forward config to the class method" do
|
||||
assert_equal Vagrant.config, Vagrant::Config.config
|
||||
end
|
||||
end
|
||||
|
||||
context "initializing" do
|
||||
teardown do
|
||||
Vagrant::Config.instance_variable_set(:@config_runners, nil)
|
||||
Vagrant::Config.instance_variable_set(:@config, nil)
|
||||
end
|
||||
|
||||
should "not run the blocks right away" do
|
||||
obj = mock("obj")
|
||||
obj.expects(:foo).never
|
||||
Vagrant::Config.run { |config| obj.foo }
|
||||
Vagrant::Config.run { |config| obj.foo }
|
||||
Vagrant::Config.run { |config| obj.foo }
|
||||
end
|
||||
|
||||
should "run the blocks when execute! is ran" do
|
||||
obj = mock("obj")
|
||||
obj.expects(:foo).times(2)
|
||||
Vagrant::Config.run { |config| obj.foo }
|
||||
Vagrant::Config.run { |config| obj.foo }
|
||||
Vagrant::Config.execute!
|
||||
end
|
||||
|
||||
should "run the blocks with the same config object" do
|
||||
config = mock("config")
|
||||
config.expects(:foo).twice
|
||||
Vagrant::Config.stubs(:config).returns(config)
|
||||
Vagrant::Config.run { |config| config.foo }
|
||||
Vagrant::Config.run { |config| config.foo }
|
||||
Vagrant::Config.execute!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,86 +6,82 @@ class EnvTest < Test::Unit::TestCase
|
|||
File.expects(:open).with(dotfile, 'r').returns(['foo'])
|
||||
end
|
||||
|
||||
def dotfile(dir=Dir.pwd)
|
||||
"#{dir}/#{hobo_mock_config[:dotfile_name]}"
|
||||
end
|
||||
|
||||
def mock_persisted_vm(returnvalue="foovm")
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:read).returns("foo")
|
||||
Hobo::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
||||
Hobo::Env.load_vm!
|
||||
Vagrant::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
File.expects(:open).with(Vagrant::Env.dotfile_path).once.yields(filemock)
|
||||
Vagrant::Env.load_vm!
|
||||
end
|
||||
|
||||
setup do
|
||||
Hobo::Env.stubs(:error_and_exit)
|
||||
hobo_mock_config
|
||||
Vagrant::Env.stubs(:error_and_exit)
|
||||
mock_config
|
||||
end
|
||||
|
||||
context "requiring a VM" do
|
||||
should "error and exit if no persisted VM was found" do
|
||||
assert_nil Hobo::Env.persisted_vm
|
||||
Hobo::Env.expects(:error_and_exit).once
|
||||
Hobo::Env.require_persisted_vm
|
||||
assert_nil Vagrant::Env.persisted_vm
|
||||
Vagrant::Env.expects(:error_and_exit).once
|
||||
Vagrant::Env.require_persisted_vm
|
||||
end
|
||||
|
||||
should "return and continue if persisted VM is found" do
|
||||
mock_persisted_vm
|
||||
Hobo::Env.expects(:error_and_exit).never
|
||||
Hobo::Env.require_persisted_vm
|
||||
Vagrant::Env.expects(:error_and_exit).never
|
||||
Vagrant::Env.require_persisted_vm
|
||||
end
|
||||
end
|
||||
|
||||
context "loading config" do
|
||||
setup do
|
||||
@root_path = "/foo"
|
||||
Hobo::Env.stubs(:root_path).returns(@root_path)
|
||||
Vagrant::Env.stubs(:root_path).returns(@root_path)
|
||||
File.stubs(:exist?).returns(false)
|
||||
Hobo::Config.stubs(:execute!)
|
||||
Vagrant::Config.stubs(:execute!)
|
||||
end
|
||||
|
||||
should "load from the project root" do
|
||||
File.expects(:exist?).with(File.join(PROJECT_ROOT, "config", "default.rb")).once
|
||||
Hobo::Env.load_config!
|
||||
Vagrant::Env.load_config!
|
||||
end
|
||||
|
||||
should "load from the root path" do
|
||||
File.expects(:exist?).with(File.join(@root_path, Hobo::Env::HOBOFILE_NAME)).once
|
||||
Hobo::Env.load_config!
|
||||
File.expects(:exist?).with(File.join(@root_path, Vagrant::Env::ROOTFILE_NAME)).once
|
||||
Vagrant::Env.load_config!
|
||||
end
|
||||
|
||||
should "load the files only if exist? returns true" do
|
||||
File.expects(:exist?).once.returns(true)
|
||||
Hobo::Env.expects(:load).once
|
||||
Hobo::Env.load_config!
|
||||
Vagrant::Env.expects(:load).once
|
||||
Vagrant::Env.load_config!
|
||||
end
|
||||
|
||||
should "not load the files if exist? returns false" do
|
||||
Hobo::Env.expects(:load).never
|
||||
Hobo::Env.load_config!
|
||||
Vagrant::Env.expects(:load).never
|
||||
Vagrant::Env.load_config!
|
||||
end
|
||||
|
||||
should "execute after loading" do
|
||||
File.expects(:exist?).once.returns(true)
|
||||
Hobo::Env.expects(:load).once
|
||||
Hobo::Config.expects(:execute!).once
|
||||
Hobo::Env.load_config!
|
||||
Vagrant::Env.expects(:load).once
|
||||
Vagrant::Config.expects(:execute!).once
|
||||
Vagrant::Env.load_config!
|
||||
end
|
||||
end
|
||||
|
||||
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_vm!).once
|
||||
Hobo::Env.expects(:load_root_path!).once
|
||||
Hobo::Env.load!
|
||||
Vagrant::Env.expects(:load_config!).once
|
||||
Vagrant::Env.expects(:load_vm!).once
|
||||
Vagrant::Env.expects(:load_root_path!).once
|
||||
Vagrant::Env.load!
|
||||
end
|
||||
end
|
||||
|
||||
context "persisting the VM into a file" do
|
||||
setup do
|
||||
hobo_mock_config
|
||||
mock_config
|
||||
end
|
||||
|
||||
test "should save it to the dotfile path" do
|
||||
|
@ -94,30 +90,30 @@ class EnvTest < Test::Unit::TestCase
|
|||
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:write).with(vm.uuid)
|
||||
File.expects(:open).with(Hobo::Env.dotfile_path, 'w+').once.yields(filemock)
|
||||
Hobo::Env.persist_vm(vm)
|
||||
File.expects(:open).with(Vagrant::Env.dotfile_path, 'w+').once.yields(filemock)
|
||||
Vagrant::Env.persist_vm(vm)
|
||||
end
|
||||
end
|
||||
|
||||
context "loading the UUID out from the persisted file" do
|
||||
test "loading of the uuid from the dotfile" do
|
||||
mock_persisted_vm
|
||||
assert_equal 'foovm', Hobo::Env.persisted_vm
|
||||
assert_equal 'foovm', Vagrant::Env.persisted_vm
|
||||
end
|
||||
|
||||
test "uuid should be nil if dotfile didn't exist" do
|
||||
File.expects(:open).raises(Errno::ENOENT)
|
||||
Hobo::Env.load_vm!
|
||||
assert_nil Hobo::Env.persisted_vm
|
||||
Vagrant::Env.load_vm!
|
||||
assert_nil Vagrant::Env.persisted_vm
|
||||
end
|
||||
|
||||
test "should build up the dotfile out of the root path and the dotfile name" do
|
||||
assert_equal File.join(Hobo::Env.root_path, Hobo.config.dotfile_name), Hobo::Env.dotfile_path
|
||||
assert_equal File.join(Vagrant::Env.root_path, Vagrant.config.dotfile_name), Vagrant::Env.dotfile_path
|
||||
end
|
||||
end
|
||||
|
||||
context "loading the root path" do
|
||||
test "should walk the parent directories looking for hobofile" do
|
||||
test "should walk the parent directories looking for rootfile" do
|
||||
paths = [
|
||||
Pathname.new("/foo/bar/baz"),
|
||||
Pathname.new("/foo/bar"),
|
||||
|
@ -126,25 +122,25 @@ class EnvTest < Test::Unit::TestCase
|
|||
|
||||
search_seq = sequence("search_seq")
|
||||
paths.each do |path|
|
||||
File.expects(:exist?).with("#{path}/#{Hobo::Env::HOBOFILE_NAME}").returns(false).in_sequence(search_seq)
|
||||
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(false).in_sequence(search_seq)
|
||||
end
|
||||
|
||||
assert_nil Hobo::Env.load_root_path!(paths.first)
|
||||
assert_nil Vagrant::Env.load_root_path!(paths.first)
|
||||
end
|
||||
|
||||
test "should print out an error and exit if not found" do
|
||||
path = Pathname.new("/")
|
||||
|
||||
Hobo::Env.expects(:error_and_exit).once
|
||||
Hobo::Env.load_root_path!(path)
|
||||
Vagrant::Env.expects(:error_and_exit).once
|
||||
Vagrant::Env.load_root_path!(path)
|
||||
end
|
||||
|
||||
test "should set the path for the Hobofile" do
|
||||
test "should set the path for the rootfile" do
|
||||
path = "/foo"
|
||||
File.expects(:exist?).with("#{path}/#{Hobo::Env::HOBOFILE_NAME}").returns(true)
|
||||
Hobo::Env.load_root_path!(Pathname.new(path))
|
||||
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)
|
||||
Vagrant::Env.load_root_path!(Pathname.new(path))
|
||||
|
||||
assert_equal path, Hobo::Env.root_path
|
||||
assert_equal path, Vagrant::Env.root_path
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,24 +3,24 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
class ProvisioningTest < Test::Unit::TestCase
|
||||
setup do
|
||||
# Stub upload so nothing happens
|
||||
Hobo::SSH.stubs(:upload!)
|
||||
Vagrant::SSH.stubs(:upload!)
|
||||
|
||||
vm = mock("vm")
|
||||
vm.stubs(:share_folder)
|
||||
@prov = Hobo::Provisioning.new(vm)
|
||||
@prov = Vagrant::Provisioning.new(vm)
|
||||
end
|
||||
|
||||
context "initializing" do
|
||||
should "setup shared folder on VM for the cookbooks" do
|
||||
File.expects(:expand_path).with(Hobo.config.chef.cookbooks_path, Hobo::Env.root_path).returns("foo")
|
||||
Hobo::Provisioning.any_instance.expects(:cookbooks_path).returns("bar")
|
||||
File.expects(:expand_path).with(Vagrant.config.chef.cookbooks_path, Vagrant::Env.root_path).returns("foo")
|
||||
Vagrant::Provisioning.any_instance.expects(:cookbooks_path).returns("bar")
|
||||
vm = mock("vm")
|
||||
vm.expects(:share_folder).with("hobo-provisioning", "foo", "bar")
|
||||
Hobo::Provisioning.new(vm)
|
||||
vm.expects(:share_folder).with("vagrant-provisioning", "foo", "bar")
|
||||
Vagrant::Provisioning.new(vm)
|
||||
end
|
||||
|
||||
should "return the proper cookbook path" do
|
||||
cookbooks_path = File.join(Hobo.config.chef.provisioning_path, "cookbooks")
|
||||
cookbooks_path = File.join(Vagrant.config.chef.provisioning_path, "cookbooks")
|
||||
assert_equal cookbooks_path, @prov.cookbooks_path
|
||||
end
|
||||
end
|
||||
|
@ -28,23 +28,23 @@ class ProvisioningTest < Test::Unit::TestCase
|
|||
context "permissions on provisioning folder" do
|
||||
should "chown the folder to the ssh user" do
|
||||
ssh = mock("ssh")
|
||||
ssh.expects(:exec!).with("sudo chown #{Hobo.config.ssh.username} #{Hobo.config.chef.provisioning_path}")
|
||||
Hobo::SSH.expects(:execute).yields(ssh)
|
||||
ssh.expects(:exec!).with("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}")
|
||||
Vagrant::SSH.expects(:execute).yields(ssh)
|
||||
@prov.chown_provisioning_folder
|
||||
end
|
||||
end
|
||||
|
||||
context "generating and uploading json" do
|
||||
should "convert the JSON config to JSON" do
|
||||
Hobo.config.chef.json.expects(:to_json).once.returns("foo")
|
||||
Vagrant.config.chef.json.expects(:to_json).once.returns("foo")
|
||||
@prov.setup_json
|
||||
end
|
||||
|
||||
should "upload a StringIO to dna.json" do
|
||||
Hobo.config.chef.json.expects(:to_json).once.returns("foo")
|
||||
Vagrant.config.chef.json.expects(:to_json).once.returns("foo")
|
||||
StringIO.expects(:new).with("foo").returns("bar")
|
||||
File.expects(:join).with(Hobo.config.chef.provisioning_path, "dna.json").once.returns("baz")
|
||||
Hobo::SSH.expects(:upload!).with("bar", "baz").once
|
||||
File.expects(:join).with(Vagrant.config.chef.provisioning_path, "dna.json").once.returns("baz")
|
||||
Vagrant::SSH.expects(:upload!).with("bar", "baz").once
|
||||
@prov.setup_json
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ class ProvisioningTest < Test::Unit::TestCase
|
|||
context "generating and uploading chef solo configuration file" do
|
||||
should "upload properly generate the configuration file using configuration data" do
|
||||
expected_config = <<-config
|
||||
file_cache_path "#{Hobo.config.chef.provisioning_path}"
|
||||
file_cache_path "#{Vagrant.config.chef.provisioning_path}"
|
||||
cookbook_path "#{@prov.cookbooks_path}"
|
||||
config
|
||||
|
||||
|
@ -63,8 +63,8 @@ config
|
|||
should "upload this file as solo.rb to the provisioning folder" do
|
||||
@prov.expects(:cookbooks_path).returns("cookbooks")
|
||||
StringIO.expects(:new).returns("foo")
|
||||
File.expects(:join).with(Hobo.config.chef.provisioning_path, "solo.rb").once.returns("bar")
|
||||
Hobo::SSH.expects(:upload!).with("foo", "bar").once
|
||||
File.expects(:join).with(Vagrant.config.chef.provisioning_path, "solo.rb").once.returns("bar")
|
||||
Vagrant::SSH.expects(:upload!).with("foo", "bar").once
|
||||
@prov.setup_solo_config
|
||||
end
|
||||
end
|
||||
|
@ -72,8 +72,8 @@ config
|
|||
context "running chef solo" do
|
||||
should "cd into the provisioning directory and run chef solo" do
|
||||
ssh = mock("ssh")
|
||||
ssh.expects(:exec!).with("cd #{Hobo.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
|
||||
Hobo::SSH.expects(:execute).yields(ssh)
|
||||
ssh.expects(:exec!).with("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
|
||||
Vagrant::SSH.expects(:execute).yields(ssh)
|
||||
@prov.run_chef_solo
|
||||
end
|
||||
end
|
|
@ -2,71 +2,71 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
|
||||
class SshTest < Test::Unit::TestCase
|
||||
setup do
|
||||
hobo_mock_config
|
||||
mock_config
|
||||
end
|
||||
|
||||
context "hobo ssh" do
|
||||
context "ssh" do
|
||||
setup do
|
||||
@script = Hobo::SSH::SCRIPT
|
||||
@script = Vagrant::SSH::SCRIPT
|
||||
end
|
||||
|
||||
test "should call exec with defaults when no options are supplied" do
|
||||
ssh = Hobo.config.ssh
|
||||
port = Hobo.config.vm.forwarded_ports[ssh.forwarded_port_key][:hostport]
|
||||
ssh = Vagrant.config.ssh
|
||||
port = Vagrant.config.vm.forwarded_ports[ssh.forwarded_port_key][:hostport]
|
||||
Kernel.expects(:exec).with("#{@script} #{ssh[:username]} #{ssh[:password]} #{ssh[:host]} #{port}")
|
||||
Hobo::SSH.connect
|
||||
Vagrant::SSH.connect
|
||||
end
|
||||
|
||||
test "should call exec with supplied params" do
|
||||
args = {:username => 'bar', :password => 'baz', :host => 'bak', :port => 'bag'}
|
||||
Kernel.expects(:exec).with("#{@script} #{args[:username]} #{args[:password]} #{args[:host]} #{args[:port]}")
|
||||
Hobo::SSH.connect(args)
|
||||
Vagrant::SSH.connect(args)
|
||||
end
|
||||
end
|
||||
|
||||
context "net-ssh interaction" do
|
||||
should "call net::ssh.start with the proper names" do
|
||||
Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config.ssh.username, anything).once
|
||||
Hobo::SSH.execute
|
||||
Net::SSH.expects(:start).with(Vagrant.config.ssh.host, Vagrant.config.ssh.username, anything).once
|
||||
Vagrant::SSH.execute
|
||||
end
|
||||
|
||||
should "use custom host if set" do
|
||||
Hobo.config.ssh.host = "foo"
|
||||
Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config.ssh.username, anything).once
|
||||
Hobo::SSH.execute
|
||||
Vagrant.config.ssh.host = "foo"
|
||||
Net::SSH.expects(:start).with(Vagrant.config.ssh.host, Vagrant.config.ssh.username, anything).once
|
||||
Vagrant::SSH.execute
|
||||
end
|
||||
end
|
||||
|
||||
context "SCPing files to the remote host" do
|
||||
should "use Hobo::SSH execute to setup an SCP connection and upload" do
|
||||
should "use Vagrant::SSH execute to setup an SCP connection and upload" do
|
||||
scp = mock("scp")
|
||||
ssh = mock("ssh")
|
||||
scp.expects(:upload!).with("foo", "bar").once
|
||||
Net::SCP.expects(:new).with(ssh).returns(scp).once
|
||||
Hobo::SSH.expects(:execute).yields(ssh).once
|
||||
Hobo::SSH.upload!("foo", "bar")
|
||||
Vagrant::SSH.expects(:execute).yields(ssh).once
|
||||
Vagrant::SSH.upload!("foo", "bar")
|
||||
end
|
||||
end
|
||||
|
||||
context "checking if host is up" do
|
||||
setup do
|
||||
hobo_mock_config
|
||||
mock_config
|
||||
end
|
||||
|
||||
should "return true if SSH connection works" do
|
||||
Net::SSH.expects(:start).yields("success")
|
||||
assert Hobo::SSH.up?
|
||||
assert Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "return false if SSH connection times out" do
|
||||
Net::SSH.expects(:start)
|
||||
assert !Hobo::SSH.up?
|
||||
assert !Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "return false if the connection is refused" do
|
||||
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
|
||||
assert_nothing_raised {
|
||||
assert !Hobo::SSH.up?
|
||||
assert !Vagrant::SSH.up?
|
||||
}
|
||||
end
|
||||
end
|
|
@ -3,79 +3,79 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
class VMTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm = mock("vm")
|
||||
hobo_mock_config
|
||||
mock_config
|
||||
|
||||
@persisted_vm = mock("persisted_vm")
|
||||
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
||||
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
||||
|
||||
Net::SSH.stubs(:start)
|
||||
end
|
||||
|
||||
context "hobo ssh" do
|
||||
context "vagrant ssh" do
|
||||
setup do
|
||||
Hobo::SSH.stubs(:connect)
|
||||
Vagrant::SSH.stubs(:connect)
|
||||
end
|
||||
|
||||
should "require a persisted VM" do
|
||||
Hobo::Env.expects(:require_persisted_vm).once
|
||||
Hobo::VM.ssh
|
||||
Vagrant::Env.expects(:require_persisted_vm).once
|
||||
Vagrant::VM.ssh
|
||||
end
|
||||
|
||||
should "connect to SSH" do
|
||||
Hobo::SSH.expects(:connect).once
|
||||
Hobo::VM.ssh
|
||||
Vagrant::SSH.expects(:connect).once
|
||||
Vagrant::VM.ssh
|
||||
end
|
||||
end
|
||||
|
||||
context "hobo down" do
|
||||
context "vagrant down" do
|
||||
setup do
|
||||
@persisted_vm.stubs(:destroy)
|
||||
end
|
||||
|
||||
should "require a persisted VM" do
|
||||
Hobo::Env.expects(:require_persisted_vm).once
|
||||
Hobo::VM.down
|
||||
Vagrant::Env.expects(:require_persisted_vm).once
|
||||
Vagrant::VM.down
|
||||
end
|
||||
|
||||
should "destroy the persisted VM and the VM image" do
|
||||
@persisted_vm.expects(:destroy).once
|
||||
Hobo::VM.down
|
||||
Vagrant::VM.down
|
||||
end
|
||||
end
|
||||
|
||||
context "hobo up" do
|
||||
should "create a Hobo::VM instance and call create" do
|
||||
context "vagrant up" do
|
||||
should "create a Vagrant::VM instance and call create" do
|
||||
inst = mock("instance")
|
||||
inst.expects(:create).once
|
||||
Hobo::VM.expects(:new).returns(inst)
|
||||
Hobo::VM.up
|
||||
Vagrant::VM.expects(:new).returns(inst)
|
||||
Vagrant::VM.up
|
||||
end
|
||||
end
|
||||
|
||||
context "finding a VM" do
|
||||
should "return nil if the VM is not found" do
|
||||
VirtualBox::VM.expects(:find).returns(nil)
|
||||
assert_nil Hobo::VM.find("foo")
|
||||
assert_nil Vagrant::VM.find("foo")
|
||||
end
|
||||
|
||||
should "return a Hobo::VM object for that VM otherwise" do
|
||||
should "return a Vagrant::VM object for that VM otherwise" do
|
||||
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
||||
result = Hobo::VM.find("foo")
|
||||
assert result.is_a?(Hobo::VM)
|
||||
result = Vagrant::VM.find("foo")
|
||||
assert result.is_a?(Vagrant::VM)
|
||||
assert_equal "bar", result.vm
|
||||
end
|
||||
end
|
||||
|
||||
context "hobo VM instance" do
|
||||
context "vagrant VM instance" do
|
||||
setup do
|
||||
@vm = Hobo::VM.new(@mock_vm)
|
||||
@vm = Vagrant::VM.new(@mock_vm)
|
||||
end
|
||||
|
||||
context "creating" do
|
||||
should "create the VM in the proper order" do
|
||||
prov = mock("prov")
|
||||
create_seq = sequence("create_seq")
|
||||
Hobo::Provisioning.expects(:new).with(@vm).in_sequence(create_seq).returns(prov)
|
||||
Vagrant::Provisioning.expects(:new).with(@vm).in_sequence(create_seq).returns(prov)
|
||||
@vm.expects(:import).in_sequence(create_seq)
|
||||
@vm.expects(:persist).in_sequence(create_seq)
|
||||
@vm.expects(:setup_mac_address).in_sequence(create_seq)
|
||||
|
@ -113,19 +113,19 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
should "start the VM in headless mode" do
|
||||
@mock_vm.expects(:start).with(:headless, true).once
|
||||
Hobo::SSH.expects(:up?).once.returns(true)
|
||||
Vagrant::SSH.expects(:up?).once.returns(true)
|
||||
@vm.start
|
||||
end
|
||||
|
||||
should "repeatedly ping the SSH port and return false with no response" do
|
||||
seq = sequence('pings')
|
||||
Hobo::SSH.expects(:up?).times(Hobo.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
|
||||
Hobo::SSH.expects(:up?).once.returns(true).in_sequence(seq)
|
||||
Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
|
||||
Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq)
|
||||
assert @vm.start
|
||||
end
|
||||
|
||||
should "ping the max number of times then just return" do
|
||||
Hobo::SSH.expects(:up?).times(Hobo.config[:ssh][:max_tries].to_i).returns(false)
|
||||
Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false)
|
||||
assert !@vm.start
|
||||
end
|
||||
end
|
||||
|
@ -145,7 +145,7 @@ class VMTest < Test::Unit::TestCase
|
|||
context "persisting" do
|
||||
should "persist the VM with Env" do
|
||||
@mock_vm.stubs(:uuid)
|
||||
Hobo::Env.expects(:persist_vm).with(@mock_vm).once
|
||||
Vagrant::Env.expects(:persist_vm).with(@mock_vm).once
|
||||
@vm.persist
|
||||
end
|
||||
end
|
||||
|
@ -178,28 +178,28 @@ class VMTest < Test::Unit::TestCase
|
|||
should "put the vm in a suspended state" do
|
||||
saved_state_expectation(false)
|
||||
save_expectation
|
||||
Hobo::VM.suspend
|
||||
Vagrant::VM.suspend
|
||||
end
|
||||
|
||||
should "results in an error and exit if the vm is already in a saved state" do
|
||||
saved_state_expectation(true)
|
||||
save_expectation
|
||||
Hobo::VM.expects(:error_and_exit)
|
||||
Hobo::VM.suspend
|
||||
Vagrant::VM.expects(:error_and_exit)
|
||||
Vagrant::VM.suspend
|
||||
end
|
||||
|
||||
should "start a vm in a suspended state" do
|
||||
saved_state_expectation(true)
|
||||
start_expectation
|
||||
Hobo::VM.resume
|
||||
Vagrant::VM.resume
|
||||
end
|
||||
|
||||
should "results in an error and exit if the vm is not in a saved state" do
|
||||
saved_state_expectation(false)
|
||||
start_expectation
|
||||
# TODO research the matter of mocking exit
|
||||
Hobo::VM.expects(:error_and_exit)
|
||||
Hobo::VM.resume
|
||||
Vagrant::VM.expects(:error_and_exit)
|
||||
Vagrant::VM.resume
|
||||
end
|
||||
|
||||
def saved_state_expectation(saved)
|
||||
|
@ -211,14 +211,14 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def start_expectation
|
||||
Hobo::Env.persisted_vm.expects(:start).once.returns(true)
|
||||
Vagrant::Env.persisted_vm.expects(:start).once.returns(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "shared folders" do
|
||||
setup do
|
||||
@mock_vm = mock("mock_vm")
|
||||
@vm = Hobo::VM.new(@mock_vm)
|
||||
@vm = Vagrant::VM.new(@mock_vm)
|
||||
end
|
||||
|
||||
should "not have any shared folders initially" do
|
||||
|
@ -260,9 +260,9 @@ class VMTest < Test::Unit::TestCase
|
|||
@vm.shared_folders.each do |name, hostpath, guestpath|
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq)
|
||||
ssh.expects(:exec!).with("sudo mount -t vboxsf #{name} #{guestpath}").in_sequence(mount_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{Hobo.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{Vagrant.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
||||
end
|
||||
Hobo::SSH.expects(:execute).yields(ssh)
|
||||
Vagrant::SSH.expects(:execute).yields(ssh)
|
||||
|
||||
@vm.mount_shared_folders
|
||||
end
|
||||
|
@ -286,8 +286,8 @@ class VMTest < Test::Unit::TestCase
|
|||
def move_hd_expectations
|
||||
image, hd = mock('image'), mock('hd')
|
||||
|
||||
Hobo.config[:vm].expects(:hd_location).at_least_once.returns('/locations/')
|
||||
image.expects(:clone).with(Hobo.config[:vm][:hd_location] + 'foo', Hobo::VM::HD_EXT_DEFAULT, true).returns(image)
|
||||
Vagrant.config[:vm].expects(:hd_location).at_least_once.returns('/locations/')
|
||||
image.expects(:clone).with(Vagrant.config[:vm][:hd_location] + 'foo', Vagrant::VM::HD_EXT_DEFAULT, true).returns(image)
|
||||
image.expects(:filename).twice.returns('foo')
|
||||
|
||||
hd.expects(:image).twice.returns(image)
|
||||
|
@ -297,7 +297,7 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
@mock_vm.expects(:save)
|
||||
|
||||
vm = Hobo::VM.new(@mock_vm)
|
||||
vm = Vagrant::VM.new(@mock_vm)
|
||||
vm.expects(:hd).times(3).returns(hd)
|
||||
vm
|
||||
end
|
Loading…
Reference in New Issue