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