Removing some old files
This commit is contained in:
parent
0b8809006b
commit
b08c1a62ce
|
@ -133,7 +133,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(path)
|
def export(path)
|
||||||
# TODO: Progress
|
|
||||||
execute("export", @uuid, "--output", path.to_s)
|
execute("export", @uuid, "--output", path.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(path)
|
def export(path)
|
||||||
# TODO: Progress
|
|
||||||
execute("export", @uuid, "--output", path.to_s)
|
execute("export", @uuid, "--output", path.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(path)
|
def export(path)
|
||||||
# TODO: Progress
|
|
||||||
execute("export", @uuid, "--output", path.to_s)
|
execute("export", @uuid, "--output", path.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(path)
|
def export(path)
|
||||||
# TODO: Progress
|
|
||||||
execute("export", @uuid, "--output", path.to_s)
|
execute("export", @uuid, "--output", path.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
require "rubygems"
|
|
||||||
require "rspec/autorun"
|
|
||||||
|
|
||||||
require "log4r"
|
|
||||||
|
|
||||||
# Add the test directory to the load path
|
|
||||||
$:.unshift File.expand_path("../../", __FILE__)
|
|
||||||
|
|
||||||
# Load in the supporting files for our tests
|
|
||||||
require "acceptance/support/shared/base_context"
|
|
||||||
require "acceptance/support/config"
|
|
||||||
require "acceptance/support/virtualbox"
|
|
||||||
require "acceptance/support/matchers/match_output"
|
|
||||||
require "acceptance/support/matchers/succeed"
|
|
||||||
|
|
||||||
# Do not buffer output
|
|
||||||
$stdout.sync = true
|
|
||||||
$stderr.sync = true
|
|
||||||
|
|
||||||
# If VirtualBox is currently running, fail.
|
|
||||||
if Acceptance::VirtualBox.find_vboxsvc
|
|
||||||
$stderr.puts "VirtualBox must be closed and remain closed for the duration of the tests."
|
|
||||||
abort
|
|
||||||
end
|
|
||||||
|
|
||||||
# Enable logging if requested
|
|
||||||
if ENV["ACCEPTANCE_LOG"]
|
|
||||||
logger = Log4r::Logger.new("test")
|
|
||||||
logger.outputters = Log4r::Outputter.stdout
|
|
||||||
logger.level = Log4r.const_get(ENV["ACCEPTANCE_LOG"].upcase)
|
|
||||||
logger = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Parse the command line options and load the global configuration.
|
|
||||||
if !ENV.has_key?("ACCEPTANCE_CONFIG")
|
|
||||||
$stderr.puts "A configuration file must be passed into the acceptance test."
|
|
||||||
abort
|
|
||||||
elsif !File.file?(ENV["ACCEPTANCE_CONFIG"])
|
|
||||||
$stderr.puts "The configuration file must exist."
|
|
||||||
abort
|
|
||||||
end
|
|
||||||
|
|
||||||
$acceptance_options = Acceptance::Config.new(ENV["ACCEPTANCE_CONFIG"])
|
|
||||||
|
|
||||||
# Configure RSpec
|
|
||||||
RSpec.configure do |c|
|
|
||||||
c.expect_with :rspec, :stdlib
|
|
||||||
end
|
|
|
@ -1,99 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant box" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "has no boxes by default" do
|
|
||||||
result = execute("vagrant", "box", "list")
|
|
||||||
result.stdout.should match_output(:no_boxes)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can add a box from a file" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
# Add the box, which we expect to succeed
|
|
||||||
result = execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
result.should succeed
|
|
||||||
|
|
||||||
# Verify that the box now shows up in the list of available boxes
|
|
||||||
result = execute("vagrant", "box", "list")
|
|
||||||
result.stdout.should match_output(:box_installed, "foo")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "errors if attempting to add a box with the same name" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
# Add the box, which we expect to succeed
|
|
||||||
assert_execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
|
|
||||||
# Adding it again should not succeed
|
|
||||||
result = execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:box_already_exists, "foo")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "overwrites a box when adding with `--force`" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
# Add the box, which we expect to succeed
|
|
||||||
assert_execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
|
|
||||||
# Adding it again should not succeed
|
|
||||||
assert_execute("vagrant", "box", "add", "foo", box_path("default"), "--force")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "gives an error if the file doesn't exist" do
|
|
||||||
result = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:box_path_doesnt_exist)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "gives an error if the file is not a valid box" do
|
|
||||||
invalid = environment.workdir.join("nope.txt")
|
|
||||||
invalid.open("w+") do |f|
|
|
||||||
f.write("INVALID!")
|
|
||||||
end
|
|
||||||
|
|
||||||
result = execute("vagrant", "box", "add", "foo", invalid.to_s)
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:box_invalid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can add a box from an HTTP server" do
|
|
||||||
pending("Need to setup HTTP server functionality")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can remove a box" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
# Add the box, remove the box, then verify that the box no longer
|
|
||||||
# shows up in the list of available boxes.
|
|
||||||
execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
execute("vagrant", "box", "remove", "foo")
|
|
||||||
result = execute("vagrant", "box", "list")
|
|
||||||
result.should succeed
|
|
||||||
result.stdout.should match_output(:no_boxes)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can repackage a box" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
original_size = File.size(box_path("default"))
|
|
||||||
logger.debug("Original package size: #{original_size}")
|
|
||||||
|
|
||||||
# Add the box, repackage it, and verify that a package.box is
|
|
||||||
# dumped of relatively similar size.
|
|
||||||
execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
||||||
execute("vagrant", "box", "repackage", "foo")
|
|
||||||
|
|
||||||
# By default, repackage should dump into package.box into the CWD
|
|
||||||
repackaged_file = environment.workdir.join("package.box")
|
|
||||||
repackaged_file.file?.should be, "package.box should exist in cwd of environment"
|
|
||||||
|
|
||||||
# Compare the sizes
|
|
||||||
repackaged_size = repackaged_file.size
|
|
||||||
logger.debug("Repackaged size: #{repackaged_size}")
|
|
||||||
size_diff = (repackaged_size - original_size).abs
|
|
||||||
size_diff.should be < 1000, "Sizes should be very similar"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,37 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant destroy" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "destroy"]
|
|
||||||
|
|
||||||
it "succeeds and ignores if the VM is not created" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
|
|
||||||
result = assert_execute("vagrant", "destroy")
|
|
||||||
result.stdout.should match_output(:vm_not_created_warning)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to destroy a running virtual machine" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Destroy the VM and assert that it worked properly (seemingly)
|
|
||||||
result = assert_execute("vagrant", "destroy")
|
|
||||||
result.stdout.should match_output(:vm_destroyed)
|
|
||||||
|
|
||||||
# Assert that the VM no longer is created
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "not created")
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# it is able to destroy a halted virtual machine
|
|
||||||
# it is able to destroy a suspended virtual machine
|
|
||||||
end
|
|
|
@ -1,72 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant halt" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "halt"]
|
|
||||||
|
|
||||||
it "succeeds and ignores if the VM is not created" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
|
|
||||||
result = assert_execute("vagrant", "halt")
|
|
||||||
result.stdout.should match_output(:vm_not_created_warning)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to halt a running virtual machine" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Halt the VM and assert that it worked properly (seemingly)
|
|
||||||
result = assert_execute("vagrant", "halt")
|
|
||||||
result.stdout.should match_output(:vm_halt_graceful)
|
|
||||||
|
|
||||||
# Assert that the VM is no longer running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "poweroff")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to force halt a running virtual machine" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Halt the VM and assert that it worked properly (seemingly)
|
|
||||||
result = assert_execute("vagrant", "halt", "--force")
|
|
||||||
result.stdout.should match_output(:vm_halt_force)
|
|
||||||
|
|
||||||
# Assert that the VM is no longer running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "poweroff")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to come back up after the machine has been halted" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_execute("vagrant", "halt")
|
|
||||||
|
|
||||||
# Assert that the VM is no longer running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "poweroff")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Assert that the VM is once again running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "running")
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# halt behavior on suspend machine
|
|
||||||
# halt behavior if machine is already powered off
|
|
||||||
end
|
|
|
@ -1,33 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant init" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "creates a Vagrantfile in the working directory" do
|
|
||||||
vagrantfile = environment.workdir.join("Vagrantfile")
|
|
||||||
vagrantfile.exist?.should_not be, "Vagrantfile shouldn't exist initially"
|
|
||||||
|
|
||||||
result = execute("vagrant", "init")
|
|
||||||
result.should succeed
|
|
||||||
vagrantfile.exist?.should be, "Vagrantfile should exist"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates a Vagrantfile with the box set to the given argument" do
|
|
||||||
vagrantfile = environment.workdir.join("Vagrantfile")
|
|
||||||
|
|
||||||
result = execute("vagrant", "init", "foo")
|
|
||||||
result.should succeed
|
|
||||||
vagrantfile.read.should match(/config.vm.box = "foo"$/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates a Vagrantfile with the box URL set to the given argument" do
|
|
||||||
vagrantfile = environment.workdir.join("Vagrantfile")
|
|
||||||
|
|
||||||
result = execute("vagrant", "init", "foo", "bar")
|
|
||||||
result.should succeed
|
|
||||||
|
|
||||||
contents = vagrantfile.read
|
|
||||||
contents.should match(/config.vm.box = "foo"$/)
|
|
||||||
contents.should match(/config.vm.box_url = "bar"$/)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,37 +0,0 @@
|
||||||
require File.expand_path("../../base", __FILE__)
|
|
||||||
|
|
||||||
require "net/http"
|
|
||||||
require "uri"
|
|
||||||
|
|
||||||
require "acceptance/support/network_tests"
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
require "support/tempdir"
|
|
||||||
|
|
||||||
describe "vagrant host only networking" do
|
|
||||||
include Acceptance::NetworkTests
|
|
||||||
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
def initialize_environment(env=nil)
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
env ||= environment
|
|
||||||
env.execute("vagrant", "box", "add", "base", box_path("default")).should succeed
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates a network with a static IP" do
|
|
||||||
initialize_environment
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.puts(<<VFILE)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.network :hostonly, "192.168.33.10"
|
|
||||||
end
|
|
||||||
VFILE
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_host_to_vm_network("http://192.168.33.10:8000/", 8000)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,125 +0,0 @@
|
||||||
require File.expand_path("../../base", __FILE__)
|
|
||||||
|
|
||||||
require "net/http"
|
|
||||||
require "uri"
|
|
||||||
|
|
||||||
require "acceptance/support/network_tests"
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
require "support/tempdir"
|
|
||||||
|
|
||||||
describe "vagrant port forwarding" do
|
|
||||||
include Acceptance::NetworkTests
|
|
||||||
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
def initialize_environment(env=nil)
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
env ||= environment
|
|
||||||
env.execute("vagrant", "box", "add", "base", box_path("default")).should succeed
|
|
||||||
end
|
|
||||||
|
|
||||||
it "forwards ports properly" do
|
|
||||||
initialize_environment
|
|
||||||
|
|
||||||
guest_port = 3000
|
|
||||||
host_port = 5000
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.puts(<<VFILE)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.forward_port #{guest_port}, #{host_port}
|
|
||||||
end
|
|
||||||
VFILE
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_host_to_vm_network("http://localhost:#{host_port}/", guest_port)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "properly overrides port forwarding from the same port" do
|
|
||||||
initialize_environment
|
|
||||||
|
|
||||||
guest_port = 3000
|
|
||||||
host_port = 5000
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.puts(<<VFILE)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.forward_port #{guest_port}, #{host_port - 1}
|
|
||||||
config.vm.forward_port #{guest_port}, #{host_port}
|
|
||||||
end
|
|
||||||
VFILE
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_host_to_vm_network("http://localhost:#{host_port}/", guest_port)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "detects and corrects port collisions" do
|
|
||||||
# The two environments need to share a VBOX_USER_HOME so that the
|
|
||||||
# VM's go into the same place.
|
|
||||||
env_vars = { "VBOX_USER_HOME" => Tempdir.new("vagrant").to_s }
|
|
||||||
environment = new_environment(env_vars)
|
|
||||||
environment2 = new_environment(env_vars)
|
|
||||||
|
|
||||||
# For this test we create two isolated environments and `vagrant up`
|
|
||||||
# in each. SSH would collide, so this verifies that it won't!
|
|
||||||
begin
|
|
||||||
initialize_environment(environment)
|
|
||||||
initialize_environment(environment2)
|
|
||||||
|
|
||||||
# Build both environments up.
|
|
||||||
environment.execute("vagrant", "init").should succeed
|
|
||||||
environment.execute("vagrant", "up").should succeed
|
|
||||||
environment2.execute("vagrant", "init").should succeed
|
|
||||||
environment2.execute("vagrant", "up").should succeed
|
|
||||||
|
|
||||||
# Touch files in both environments
|
|
||||||
environment.execute("vagrant", "ssh", "-c", "touch /vagrant/foo").should succeed
|
|
||||||
environment2.execute("vagrant", "ssh", "-c", "touch /vagrant/bar").should succeed
|
|
||||||
|
|
||||||
# Verify that the files exist in each folder, properly
|
|
||||||
environment.workdir.join("foo").exist?.should be
|
|
||||||
environment2.workdir.join("bar").exist?.should be
|
|
||||||
ensure
|
|
||||||
environment.close
|
|
||||||
environment2.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "refuses to resume if there is a port collision" do
|
|
||||||
# The two environments need to share a VBOX_USER_HOME so that the
|
|
||||||
# VM's go into the same place.
|
|
||||||
env_vars = { "VBOX_USER_HOME" => Tempdir.new("vagrant").path }
|
|
||||||
environment = new_environment(env_vars)
|
|
||||||
environment2 = new_environment(env_vars)
|
|
||||||
|
|
||||||
# For this test we `vagrant up` one environment, suspend it,
|
|
||||||
# `vagrant up` another environment, and then come back to the first
|
|
||||||
# and try to resume. SSH would collide so it should error.
|
|
||||||
begin
|
|
||||||
# Bring up the first environment and suspend it
|
|
||||||
initialize_environment(environment)
|
|
||||||
environment.execute("vagrant", "init").should succeed
|
|
||||||
environment.execute("vagrant", "up").should succeed
|
|
||||||
environment.execute("vagrant", "suspend").should succeed
|
|
||||||
|
|
||||||
# Bring up the second environment
|
|
||||||
initialize_environment(environment2)
|
|
||||||
environment2.execute("vagrant", "init").should succeed
|
|
||||||
environment2.execute("vagrant", "up").should succeed
|
|
||||||
|
|
||||||
# Attempt to bring up the first environment again, but it should
|
|
||||||
# result in an error.
|
|
||||||
result = environment.execute("vagrant", "up")
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:resume_port_collision)
|
|
||||||
ensure
|
|
||||||
environment.close
|
|
||||||
environment2.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,46 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant package" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
# This creates an initial environment that is ready for a "vagrant up"
|
|
||||||
def initialize_valid_environment
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can package a running virtual machine" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_execute("vagrant", "package")
|
|
||||||
environment.workdir.join("package.box").should be_file
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can package a `base` VM directly from VirtualBox" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# Use a custom Vagrantfile that sets the VM name to `foo`
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-vf)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.customize ["modifyvm", :id, "--name", "foo"]
|
|
||||||
end
|
|
||||||
vf
|
|
||||||
end
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Remove the Vagrantfile so it doesn't use that
|
|
||||||
environment.workdir.join("Vagrantfile").unlink
|
|
||||||
|
|
||||||
# Now package the base VM
|
|
||||||
assert_execute("vagrant", "package", "--base", "foo")
|
|
||||||
environment.workdir.join("package.box").should be_file
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,61 +0,0 @@
|
||||||
require File.expand_path("../../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant provisioning basics" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "doesn't provision with `--no-provision` set" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-vf)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.provision :shell, :inline => "echo success > /vagrant/results"
|
|
||||||
end
|
|
||||||
vf
|
|
||||||
end
|
|
||||||
|
|
||||||
# Bring the VM up without enabling provisioning
|
|
||||||
assert_execute("vagrant", "up", "--no-provision")
|
|
||||||
|
|
||||||
# Verify the file that the script creates does NOT exist
|
|
||||||
result_file = environment.workdir.join("results")
|
|
||||||
result_file.exist?.should_not be
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can provision with multiple provisioners" do
|
|
||||||
# Skeleton for multiple provisioners
|
|
||||||
environment.skeleton!("provisioner_multi")
|
|
||||||
|
|
||||||
# Setup the basic environment
|
|
||||||
require_box("default")
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Verify the file the shell provisioner made is there, but not the
|
|
||||||
# Chef one.
|
|
||||||
environment.workdir.join("shell").exist?.should be
|
|
||||||
environment.workdir.join("chef_solo").exist?.should be
|
|
||||||
end
|
|
||||||
|
|
||||||
it "only uses the provisioners specified with `--provision-with`" do
|
|
||||||
# Skeleton for multiple provisioners
|
|
||||||
environment.skeleton!("provisioner_multi")
|
|
||||||
|
|
||||||
# Setup the basic environment
|
|
||||||
require_box("default")
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
# Bring up the VM, only using the shell provisioner
|
|
||||||
assert_execute("vagrant", "up", "--provision-with", "shell")
|
|
||||||
|
|
||||||
# Verify the file the shell provisioner made is there, but not the
|
|
||||||
# Chef one.
|
|
||||||
environment.workdir.join("shell").exist?.should be
|
|
||||||
environment.workdir.join("chef_solo").exist?.should_not be
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,37 +0,0 @@
|
||||||
require File.expand_path("../../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant provisioning with chef solo" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "runs basic cookbooks" do
|
|
||||||
# Create the chef solo basic skeleton
|
|
||||||
environment.skeleton!("chef_solo_basic")
|
|
||||||
|
|
||||||
# Setup the basic environment
|
|
||||||
require_box("default")
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Check for the file it should have created
|
|
||||||
results = assert_execute("vagrant", "ssh", "-c", "cat /tmp/chef_solo_basic")
|
|
||||||
results.stdout.should == "success"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "merges JSON into the attributes" do
|
|
||||||
# Copy the skeleton
|
|
||||||
environment.skeleton!("chef_solo_json")
|
|
||||||
|
|
||||||
# Setup the basic environment
|
|
||||||
require_box("default")
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Check for the file it should have created
|
|
||||||
results = assert_execute("vagrant", "ssh", "-c", "cat /tmp/chef_solo_basic")
|
|
||||||
results.stdout.should == "json_data"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,53 +0,0 @@
|
||||||
require File.expand_path("../../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant provisioning with shell" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "runs a script on boot" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-vf)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.provision :shell, :path => "script.sh"
|
|
||||||
end
|
|
||||||
vf
|
|
||||||
end
|
|
||||||
|
|
||||||
environment.workdir.join("script.sh").open("w+") do |f|
|
|
||||||
f.write(<<-vf)
|
|
||||||
echo success > /vagrant/results
|
|
||||||
vf
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
result_file = environment.workdir.join("results")
|
|
||||||
result_file.exist?.should be
|
|
||||||
result_file.read.should == "success\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "runs an inline script" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-vf)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.provision :shell, :inline => "echo success > /vagrant/results"
|
|
||||||
end
|
|
||||||
vf
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
result_file = environment.workdir.join("results")
|
|
||||||
result_file.exist?.should be
|
|
||||||
result_file.read.should == "success\n"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,17 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant resume" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "resume"]
|
|
||||||
|
|
||||||
it "succeeds and ignores if the VM is not created" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
|
|
||||||
result = assert_execute("vagrant", "resume")
|
|
||||||
result.stdout.should match_output(:vm_not_created_warning)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,84 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant shared folders" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
# This creates an initial environment that is ready for a "vagrant up"
|
|
||||||
def initialize_valid_environment
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should have a '/vagrant' shared folder" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# This is the file that will be created from the VM,
|
|
||||||
# but should then exist on the host machine
|
|
||||||
foofile = environment.workdir.join("foo")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
foofile.exist?.should_not be,
|
|
||||||
"'foo' should not exist yet."
|
|
||||||
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
|
||||||
foofile.exist?.should be, "'foo' should exist since it was touched in the shared folder"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a shared folder if the :create flag is set" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# Setup the custom Vagrantfile
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-VF)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.share_folder "v-root", "/vagrant", "./data", :create => true
|
|
||||||
end
|
|
||||||
VF
|
|
||||||
end
|
|
||||||
|
|
||||||
data_dir = environment.workdir.join("data")
|
|
||||||
|
|
||||||
# Verify the directory doesn't exist prior, for sanity
|
|
||||||
data_dir.exist?.should_not be
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Verify the directory exists
|
|
||||||
data_dir.should be_directory
|
|
||||||
|
|
||||||
# Touch a file and verify it is shared
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
|
||||||
data_dir.join("foo").exist?.should be
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should properly shell expand relative directories on the guest" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# Setup the custom Vagrantfile
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-VF)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.share_folder "v-root", "~/data", "."
|
|
||||||
end
|
|
||||||
VF
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sanity
|
|
||||||
foo_file = environment.workdir.join("foo")
|
|
||||||
foo_file.exist?.should_not be
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Touch a file in the shared folder we expect and verify
|
|
||||||
# it is shared.
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "touch ~/data/foo")
|
|
||||||
foo_file.exist?.should be
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Chef Solo Basic Skeleton
|
|
||||||
|
|
||||||
This is a skeleton that contains a basic chef solo setup.
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Just create a file
|
|
||||||
file "/tmp/chef_solo_basic" do
|
|
||||||
mode 0644
|
|
||||||
content "success"
|
|
||||||
end
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Chef Solo Basic Skeleton
|
|
||||||
|
|
||||||
This is a skeleton that contains a basic chef solo setup.
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Create a file where the contents is the data we set with
|
|
||||||
# the Vagrantfile.
|
|
||||||
file "/tmp/chef_solo_basic" do
|
|
||||||
mode 0644
|
|
||||||
content node[:test][:data]
|
|
||||||
end
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Chef Solo Basic Skeleton
|
|
||||||
|
|
||||||
This is a skeleton that contains a basic chef solo setup.
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Just create a file
|
|
||||||
file "/vagrant/chef_solo" do
|
|
||||||
mode 0644
|
|
||||||
content "success"
|
|
||||||
end
|
|
|
@ -1,46 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant ssh" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "ssh"]
|
|
||||||
it_behaves_like "a command that requires a virtual machine", ["vagrant", "ssh"]
|
|
||||||
|
|
||||||
it "is able to SSH into a running virtual machine" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
outputted = false
|
|
||||||
result = assert_execute("vagrant", "ssh") do |io_type, data|
|
|
||||||
if io_type == :stdin and !outputted
|
|
||||||
data.puts("echo hello")
|
|
||||||
data.puts("exit")
|
|
||||||
outputted = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
result.stdout.chomp.should eql("hello"), "Vagrant should bring up a VM to be able to SSH into."
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to execute a single command via the command line" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
result = execute("vagrant", "ssh", "-c", "echo foo")
|
|
||||||
result.exit_code.should == 0
|
|
||||||
result.stdout.should == "foo\n"
|
|
||||||
|
|
||||||
result = execute("vagrant", "ssh", "-c", "foooooooooo")
|
|
||||||
result.exit_code.should == 127
|
|
||||||
result.stderr.should =~ /foooooooooo: command not found/
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# SSH should fail if the VM is not running
|
|
||||||
end
|
|
|
@ -1,42 +0,0 @@
|
||||||
require "yaml"
|
|
||||||
|
|
||||||
require "log4r"
|
|
||||||
|
|
||||||
module Acceptance
|
|
||||||
# This represents a configuration object for acceptance tests.
|
|
||||||
class Config
|
|
||||||
attr_reader :vagrant_path
|
|
||||||
attr_reader :vagrant_version
|
|
||||||
attr_reader :env
|
|
||||||
attr_reader :box_directory
|
|
||||||
|
|
||||||
def initialize(path)
|
|
||||||
@logger = Log4r::Logger.new("test::acceptance::config")
|
|
||||||
@logger.info("Loading configuration from: #{path}")
|
|
||||||
options = YAML.load_file(path)
|
|
||||||
@logger.info("Loaded: #{options.inspect}")
|
|
||||||
|
|
||||||
@vagrant_path = options["vagrant_path"]
|
|
||||||
@vagrant_version = options["vagrant_version"]
|
|
||||||
@env = options["env"]
|
|
||||||
@box_directory = options["box_directory"]
|
|
||||||
|
|
||||||
# Verify the configuration object.
|
|
||||||
validate
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method verifies the configuration and makes sure that
|
|
||||||
# all the configuration is available and appears good. This
|
|
||||||
# method will raise an ArgumentError in the case that anything
|
|
||||||
# is wrong.
|
|
||||||
def validate
|
|
||||||
if !@vagrant_path || !File.file?(@vagrant_path)
|
|
||||||
raise ArgumentError, "'vagrant_path' must point to the `vagrant` executable"
|
|
||||||
elsif !@vagrant_version
|
|
||||||
raise ArgumentError, "`vagrant_version' must be set to the version of the `vagrant` executable"
|
|
||||||
elsif !@box_directory || !File.directory?(@box_directory)
|
|
||||||
raise ArgumentError, "`box_directory` must be set to a folder containing boxes for the tests."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,118 +0,0 @@
|
||||||
require "fileutils"
|
|
||||||
require "pathname"
|
|
||||||
|
|
||||||
require "log4r"
|
|
||||||
require "childprocess"
|
|
||||||
|
|
||||||
require "vagrant/util/subprocess"
|
|
||||||
|
|
||||||
require "acceptance/support/virtualbox"
|
|
||||||
require "support/isolated_environment"
|
|
||||||
|
|
||||||
module Acceptance
|
|
||||||
# This class manages an isolated environment for Vagrant to
|
|
||||||
# run in. It creates a temporary directory to act as the
|
|
||||||
# working directory as well as sets a custom home directory.
|
|
||||||
class IsolatedEnvironment < ::IsolatedEnvironment
|
|
||||||
SKELETON_DIR = Pathname.new(File.expand_path("../../skeletons", __FILE__))
|
|
||||||
|
|
||||||
def initialize(apps=nil, env=nil)
|
|
||||||
super()
|
|
||||||
|
|
||||||
@logger = Log4r::Logger.new("test::acceptance::isolated_environment")
|
|
||||||
|
|
||||||
@apps = apps.clone || {}
|
|
||||||
@env = env.clone || {}
|
|
||||||
|
|
||||||
# Set the home directory and virtualbox home directory environmental
|
|
||||||
# variables so that Vagrant and VirtualBox see the proper paths here.
|
|
||||||
@env["HOME"] ||= @homedir.to_s
|
|
||||||
@env["VBOX_USER_HOME"] ||= @homedir.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
# Copies a skeleton into this isolated environment. This is useful
|
|
||||||
# for testing environments that require a complex setup.
|
|
||||||
#
|
|
||||||
# @param [String] name Name of the skeleton in the skeletons/ directory.
|
|
||||||
def skeleton!(name)
|
|
||||||
# Copy all the files into the home directory
|
|
||||||
source = Dir.glob(SKELETON_DIR.join(name).join("*").to_s)
|
|
||||||
FileUtils.cp_r(source, @workdir.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Executes a command in the context of this isolated environment.
|
|
||||||
# Any command executed will therefore see our temporary directory
|
|
||||||
# as the home directory.
|
|
||||||
def execute(command, *argN)
|
|
||||||
# Create the command
|
|
||||||
command = replace_command(command)
|
|
||||||
|
|
||||||
# Determine the options
|
|
||||||
options = argN.last.is_a?(Hash) ? argN.pop : {}
|
|
||||||
options = {
|
|
||||||
:workdir => @workdir,
|
|
||||||
:env => @env,
|
|
||||||
:notify => [:stdin, :stderr, :stdout]
|
|
||||||
}.merge(options)
|
|
||||||
|
|
||||||
# Add the options to be passed on
|
|
||||||
argN << options
|
|
||||||
|
|
||||||
# Execute, logging out the stdout/stderr as we get it
|
|
||||||
@logger.info("Executing: #{[command].concat(argN).inspect}")
|
|
||||||
Vagrant::Util::Subprocess.execute(command *argN) do |type, data|
|
|
||||||
@logger.debug("#{type}: #{data}") if type == :stdout || type == :stderr
|
|
||||||
yield type, data if block_given?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Closes the environment, cleans up the temporary directories, etc.
|
|
||||||
def close
|
|
||||||
# Only delete virtual machines if VBoxSVC is running, meaning
|
|
||||||
# that something related to VirtualBox started running in this
|
|
||||||
# environment.
|
|
||||||
delete_virtual_machines if VirtualBox.find_vboxsvc
|
|
||||||
|
|
||||||
# Let the parent handle cleaning up
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete_virtual_machines
|
|
||||||
# Delete all virtual machines
|
|
||||||
@logger.debug("Finding all virtual machines")
|
|
||||||
execute("VBoxManage", "list", "vms").stdout.lines.each do |line|
|
|
||||||
data = /^"(?<name>.+?)" {(?<uuid>.+?)}$/.match(line)
|
|
||||||
|
|
||||||
begin
|
|
||||||
@logger.debug("Removing VM: #{data[:name]}")
|
|
||||||
|
|
||||||
# We add a timeout onto this because sometimes for seemingly no
|
|
||||||
# reason it will simply freeze, although the VM is successfully
|
|
||||||
# "aborted." The timeout gets around this strange behavior.
|
|
||||||
execute("VBoxManage", "controlvm", data[:uuid], "poweroff", :timeout => 5)
|
|
||||||
rescue Vagrant::Util::Subprocess::TimeoutExceeded => e
|
|
||||||
@logger.info("Failed to poweroff VM '#{data[:uuid]}'. Killing process.")
|
|
||||||
|
|
||||||
# Kill the process and wait a bit for it to disappear
|
|
||||||
Process.kill('KILL', e.pid)
|
|
||||||
Process.waitpid2(e.pid)
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep 0.5
|
|
||||||
|
|
||||||
result = execute("VBoxManage", "unregistervm", data[:uuid], "--delete")
|
|
||||||
raise Exception, "VM unregistration failed!" if result.exit_code != 0
|
|
||||||
end
|
|
||||||
|
|
||||||
@logger.info("Removed all virtual machines")
|
|
||||||
end
|
|
||||||
|
|
||||||
# This replaces a command with a replacement defined when this
|
|
||||||
# isolated environment was initialized. If nothing was defined,
|
|
||||||
# then the command itself is returned.
|
|
||||||
def replace_command(command)
|
|
||||||
return @apps[command] if @apps.has_key?(command)
|
|
||||||
return command
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,9 +0,0 @@
|
||||||
RSpec::Matchers.define :have_color do
|
|
||||||
match do |actual|
|
|
||||||
actual.index("\e[31m")
|
|
||||||
end
|
|
||||||
|
|
||||||
failure_message_for_should do |actual|
|
|
||||||
"expected output to contain color, but didn't"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,14 +0,0 @@
|
||||||
require "acceptance/support/output"
|
|
||||||
|
|
||||||
# This creates a matcher that is used to match against certain
|
|
||||||
# Vagrant output. Vagrant output is not what is being tested,
|
|
||||||
# so all that state is hidden away in Acceptance::Output.
|
|
||||||
RSpec::Matchers.define :match_output do |expected, *args|
|
|
||||||
match do |actual|
|
|
||||||
Acceptance::Output.new(actual).send(expected, *args)
|
|
||||||
end
|
|
||||||
|
|
||||||
failure_message_for_should do |actual|
|
|
||||||
"expected output to match: #{expected} #{args.inspect}"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,14 +0,0 @@
|
||||||
# Matcher that verifies that a process succeeds.
|
|
||||||
RSpec::Matchers.define :succeed do
|
|
||||||
match do |thing|
|
|
||||||
thing.exit_code.should == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
failure_message_for_should do |actual|
|
|
||||||
"expected process to succeed. exit code: #{actual.exit_code}"
|
|
||||||
end
|
|
||||||
|
|
||||||
failure_message_for_should_not do |actual|
|
|
||||||
"expected process to fail. exit code: #{actual.exit_code}"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,29 +0,0 @@
|
||||||
require "vagrant/util/retryable"
|
|
||||||
|
|
||||||
module Acceptance
|
|
||||||
module NetworkTests
|
|
||||||
include Vagrant::Util::Retryable
|
|
||||||
|
|
||||||
# Tests that the host can access the VM through the network.
|
|
||||||
#
|
|
||||||
# @param [String] url URL to request from the host.
|
|
||||||
# @param [Integer] guest_port Port to run a web server on the guest.
|
|
||||||
def assert_host_to_vm_network(url, guest_port)
|
|
||||||
# Start up a web server in another thread by SSHing into the VM.
|
|
||||||
thr = Thread.new do
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "python -m SimpleHTTPServer #{guest_port}")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Verify that port forwarding works by making a simple HTTP request
|
|
||||||
# to the port. We should get a 200 response. We retry this a few times
|
|
||||||
# as we wait for the HTTP server to come online.
|
|
||||||
retryable(:tries => 5, :sleep => 2) do
|
|
||||||
result = Net::HTTP.get_response(URI.parse(url))
|
|
||||||
result.code.should == "200"
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
# The server needs to die. This is how.
|
|
||||||
thr.kill if thr
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,95 +0,0 @@
|
||||||
module Acceptance
|
|
||||||
# This class helps with matching against output so that every
|
|
||||||
# test isn't inherently tied to the output format of Vagrant.
|
|
||||||
class Output
|
|
||||||
DEFAULT_VM = "default"
|
|
||||||
|
|
||||||
def initialize(text)
|
|
||||||
@text = text
|
|
||||||
end
|
|
||||||
|
|
||||||
def box_already_exists(name)
|
|
||||||
@text =~ /^A box already exists under the name of '#{name}'/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Checks that an error message was outputted about the box
|
|
||||||
# being added being invalid.
|
|
||||||
def box_invalid
|
|
||||||
@text =~ /^The box file you're attempting to add is invalid./
|
|
||||||
end
|
|
||||||
|
|
||||||
# Checks that an error message was outputted about the path
|
|
||||||
# not existing to the box.
|
|
||||||
def box_path_doesnt_exist
|
|
||||||
@text =~ /^The specified path to a file doesn't exist.$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Tests that the box with given name is installed.
|
|
||||||
def box_installed(name)
|
|
||||||
@text =~ /^#{name}$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Tests that the output says there are no installed boxes.
|
|
||||||
def no_boxes
|
|
||||||
@text =~ /There are no installed boxes!/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Tests that the output says there is no Vagrantfile, and as such
|
|
||||||
# can't do whatever we requested Vagrant to do.
|
|
||||||
def no_vagrantfile
|
|
||||||
@text =~ /^A Vagrant environment is required/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Tests that the output contains a specific Vagrant version.
|
|
||||||
def version(version)
|
|
||||||
@text =~ /^Vagrant version #{version}$/
|
|
||||||
end
|
|
||||||
|
|
||||||
def resume_port_collision
|
|
||||||
@text =~ /^This VM cannot be resumed, because the forwarded ports/
|
|
||||||
end
|
|
||||||
|
|
||||||
# This checks that the VM with the given `vm_name` has the
|
|
||||||
# status of `status`.
|
|
||||||
def status(vm_name, status)
|
|
||||||
@text =~ /^#{vm_name}\s+#{status}$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# This checks that an error message that the VM must be created
|
|
||||||
# is shown.
|
|
||||||
def error_vm_must_be_created
|
|
||||||
@text =~ /^VM must be created/
|
|
||||||
end
|
|
||||||
|
|
||||||
# This checks that the warning that the VM is not created is emitted.
|
|
||||||
def vm_not_created_warning
|
|
||||||
@text =~ /VM not created. Moving on...$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# This checks that the VM is destroyed.
|
|
||||||
def vm_destroyed
|
|
||||||
@text =~ /Destroying VM and associated drives...$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# This checks that the "up" output properly contains text showing that
|
|
||||||
# it is downloading the box during the up process.
|
|
||||||
def up_fetching_box(name, vm=DEFAULT_VM)
|
|
||||||
@text =~ /^\[#{vm}\] Box #{name} was not found. Fetching box from specified URL...$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check that the output shows that the VM was shut down gracefully
|
|
||||||
def vm_halt_graceful
|
|
||||||
@text =~ /Attempting graceful shutdown of/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Output shows a forceful VM shutdown.
|
|
||||||
def vm_halt_force
|
|
||||||
@text =~ /Forcing shutdown of VM...$/
|
|
||||||
end
|
|
||||||
|
|
||||||
# Output shows the VM is in the process of suspending
|
|
||||||
def vm_suspending
|
|
||||||
@text =~ /Saving VM state and suspending execution...$/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,72 +0,0 @@
|
||||||
require "acceptance/support/isolated_environment"
|
|
||||||
require "acceptance/support/output"
|
|
||||||
require "acceptance/support/virtualbox"
|
|
||||||
|
|
||||||
shared_context "acceptance" do
|
|
||||||
# Setup variables for the loggers of this test. These can be used to
|
|
||||||
# create more verbose logs for tests which can be useful in the case
|
|
||||||
# that a test fails.
|
|
||||||
let(:logger_name) { "logger" }
|
|
||||||
let(:logger) { Log4r::Logger.new("test::acceptance::#{logger_name}") }
|
|
||||||
|
|
||||||
# This is the global configuration given by the acceptance test
|
|
||||||
# configurations.
|
|
||||||
let(:config) { $acceptance_options }
|
|
||||||
|
|
||||||
# Setup the environment so that we have an isolated area
|
|
||||||
# to run Vagrant. We do some configuration here as well in order
|
|
||||||
# to replace "vagrant" with the proper path to Vagrant as well
|
|
||||||
# as tell the isolated environment about custom environmental
|
|
||||||
# variables to pass in.
|
|
||||||
let!(:environment) { new_environment }
|
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
# Wait for VBoxSVC to disappear, since each test requires its
|
|
||||||
# own isolated VirtualBox process.
|
|
||||||
Acceptance::VirtualBox.wait_for_vboxsvc
|
|
||||||
end
|
|
||||||
|
|
||||||
after(:each) do
|
|
||||||
environment.close
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates a new isolated environment instance each time it is called.
|
|
||||||
#
|
|
||||||
# @return [Acceptance::IsolatedEnvironment]
|
|
||||||
def new_environment(env=nil)
|
|
||||||
apps = { "vagrant" => config.vagrant_path }
|
|
||||||
env = config.env.merge(env || {})
|
|
||||||
|
|
||||||
Acceptance::IsolatedEnvironment.new(apps, env)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Executes the given command in the context of the isolated environment.
|
|
||||||
#
|
|
||||||
# @return [Object]
|
|
||||||
def execute(*args, &block)
|
|
||||||
environment.execute(*args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method is an assertion helper for asserting that a process
|
|
||||||
# succeeds. It is a wrapper around `execute` that asserts that the
|
|
||||||
# exit status was successful.
|
|
||||||
def assert_execute(*args, &block)
|
|
||||||
result = execute(*args, &block)
|
|
||||||
assert(result.exit_code == 0, "expected '#{args.join(" ")}' to succeed")
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
# This can be added to the beginning of a test to verify that the
|
|
||||||
# box with the given name is available to a test. This will raise
|
|
||||||
# an exception if the box is not found.
|
|
||||||
def require_box(name)
|
|
||||||
if !File.exist?(box_path(name))
|
|
||||||
raise ArgumentError, "The tests should have a '#{name}' box."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is used to get the path to a box of a specific name.
|
|
||||||
def box_path(name)
|
|
||||||
File.join(config.box_directory, "#{name}.box")
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,33 +0,0 @@
|
||||||
# This is a shared example that tests that a command requires a
|
|
||||||
# Vagrant environment to run properly. The exact command to run
|
|
||||||
# should be given as a parameter to the shared examples.
|
|
||||||
shared_examples "a command that requires a Vagrantfile" do |*args|
|
|
||||||
let(:command) do
|
|
||||||
raise ArgumentError, "A command must be set for the shared example." if args.empty?
|
|
||||||
args[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fails if no Vagrantfile is found" do
|
|
||||||
result = execute(*command)
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:no_vagrantfile)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is a shared example that tests that the command requires a
|
|
||||||
# virtual machine to be created, and additionally to be in one of
|
|
||||||
# many states.
|
|
||||||
shared_examples "a command that requires a virtual machine" do |*args|
|
|
||||||
let(:command) do
|
|
||||||
raise ArgumentError, "A command must be set for the shared example." if args.empty?
|
|
||||||
args[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fails if the virtual machine is not created" do
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
|
|
||||||
result = execute(*command)
|
|
||||||
result.should_not succeed
|
|
||||||
result.stderr.should match_output(:error_vm_must_be_created)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,36 +0,0 @@
|
||||||
require 'sys/proctable'
|
|
||||||
|
|
||||||
module Acceptance
|
|
||||||
module VirtualBox
|
|
||||||
extend self
|
|
||||||
|
|
||||||
# This method will wait for the "VBoxSVC" process to end. This will
|
|
||||||
# block during that time period. The reason for this is because only
|
|
||||||
# one "VBoxSVC" can run per user and manages all state within VirtualBox.
|
|
||||||
# Before you can run VirtualBox with a custom home directory, you must
|
|
||||||
# wait for this VBoxSVC process to die.
|
|
||||||
def wait_for_vboxsvc
|
|
||||||
time_passed = 0
|
|
||||||
while find_vboxsvc
|
|
||||||
if time_passed > 5
|
|
||||||
raise Exception, "VBoxSVC process is not going away."
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
time_passed += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method finds the VBoxSVC process and returns information about it.
|
|
||||||
# This will return "nil" if VBoxSVC is not found.
|
|
||||||
def find_vboxsvc
|
|
||||||
Sys::ProcTable.ps do |process|
|
|
||||||
if process.comm == "VBoxSVC"
|
|
||||||
return process
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,56 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant suspend" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "suspend"]
|
|
||||||
|
|
||||||
it "succeeds and ignores if the VM is not created" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
|
|
||||||
result = assert_execute("vagrant", "suspend")
|
|
||||||
result.stdout.should match_output(:vm_not_created_warning)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to suspend a running virtual machine" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Suspend the VM and assert that it worked properly (seemingly)
|
|
||||||
result = assert_execute("vagrant", "suspend")
|
|
||||||
result.stdout.should match_output(:vm_suspending)
|
|
||||||
|
|
||||||
# Assert that the VM is no longer running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "saved")
|
|
||||||
end
|
|
||||||
|
|
||||||
# These tests are parameterized since both "vagrant resume" and
|
|
||||||
# "vagrant up" should achieve the same result.
|
|
||||||
["resume", "up"].each do |command|
|
|
||||||
it "is able to resume after the machine has been suspended using #{command}" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
assert_execute("vagrant", "suspend")
|
|
||||||
|
|
||||||
# Assert that the VM is no longer running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "saved")
|
|
||||||
|
|
||||||
assert_execute("vagrant", command)
|
|
||||||
|
|
||||||
# Assert that the VM is once again running
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "running")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,33 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant up", "basics" do
|
|
||||||
include_context "acceptance"
|
|
||||||
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "up"]
|
|
||||||
|
|
||||||
# This creates an initial environment that is ready for a "vagrant up"
|
|
||||||
def initialize_valid_environment
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
|
||||||
assert_execute("vagrant", "init")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "brings up a running virtual machine" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
result = assert_execute("vagrant", "status")
|
|
||||||
result.stdout.should match_output(:status, "default", "running")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is able to run if Vagrantfile is in a parent directory" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# Create a subdirectory in the working directory and use
|
|
||||||
# that as the CWD for `vagrant up` and verify it still works
|
|
||||||
foodir = environment.workdir.join("foo")
|
|
||||||
foodir.mkdir
|
|
||||||
assert_execute("vagrant", "up", :chdir => foodir.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,40 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/shared/command_examples"
|
|
||||||
|
|
||||||
describe "vagrant up", "with a box URL set" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "downloads and brings up the VM if the box doesn't exist" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "init", "base", box_path("default"))
|
|
||||||
result = assert_execute("vagrant", "up")
|
|
||||||
result.stdout.should match_output(:up_fetching_box, "base")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "downloads the file only once and works if shared by multiple VMs", :issue => "GH-564" do
|
|
||||||
require_box("default")
|
|
||||||
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.puts(<<-VFILE)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.define :machine1 do |vm_config|
|
|
||||||
vm_config.vm.box = "base"
|
|
||||||
vm_config.vm.box_url = "#{box_path("default")}"
|
|
||||||
end
|
|
||||||
|
|
||||||
config.vm.define :machine2 do |vm_config|
|
|
||||||
vm_config.vm.box = "base"
|
|
||||||
vm_config.vm.box_url = "#{box_path("default")}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
VFILE
|
|
||||||
end
|
|
||||||
|
|
||||||
# Bring up the environment, which should work. `machine1` should download
|
|
||||||
# the box while `machine2` doesn't.
|
|
||||||
result = assert_execute("vagrant", "up")
|
|
||||||
result.stdout.should match_output(:up_fetching_box, "base", "machine1")
|
|
||||||
result.stdout.should_not match_output(:up_fetching_box, "base", "machine2")
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,47 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
require "acceptance/support/matchers/have_color"
|
|
||||||
|
|
||||||
describe "vagrant and color output" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
# This is a check to see if the `expect` program is installed on this
|
|
||||||
# computer. Some tests require this and if this doesn't exist then the
|
|
||||||
# test itself will be skipped.
|
|
||||||
def self.has_expect?
|
|
||||||
`which expect`
|
|
||||||
$?.success?
|
|
||||||
end
|
|
||||||
|
|
||||||
it "outputs color if there is a TTY", :if => has_expect? do
|
|
||||||
environment.workdir.join("color.exp").open("w+") do |f|
|
|
||||||
f.puts(<<-SCRIPT)
|
|
||||||
spawn #{environment.replace_command("vagrant")} status
|
|
||||||
expect default {}
|
|
||||||
SCRIPT
|
|
||||||
end
|
|
||||||
|
|
||||||
result = execute("expect", "color.exp")
|
|
||||||
result.stdout.should have_color
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't output color if there is a TTY but --no-color is present", :if => has_expect? do
|
|
||||||
environment.workdir.join("color.exp").open("w+") do |f|
|
|
||||||
f.puts(<<-SCRIPT)
|
|
||||||
spawn #{environment.replace_command("vagrant")} status --no-color
|
|
||||||
expect default {}
|
|
||||||
SCRIPT
|
|
||||||
end
|
|
||||||
|
|
||||||
result = execute("expect", "color.exp")
|
|
||||||
result.stdout.should_not have_color
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't output color in the absense of a TTY" do
|
|
||||||
# This should always output an error, which on a TTY would
|
|
||||||
# output color. We check that this doesn't output color.
|
|
||||||
# If `vagrant status` itself is broken, another acceptance test
|
|
||||||
# should catch that. We just assume it works here.
|
|
||||||
result = execute("vagrant", "status")
|
|
||||||
result.stdout.should_not have_color
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,15 +0,0 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
|
||||||
|
|
||||||
describe "vagrant version" do
|
|
||||||
include_context "acceptance"
|
|
||||||
|
|
||||||
it "prints the version when called with '-v'" do
|
|
||||||
result = execute("vagrant", "-v")
|
|
||||||
result.stdout.should match_output(:version, config.vagrant_version)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "prints the version when called with '--version'" do
|
|
||||||
result = execute("vagrant", "--version")
|
|
||||||
result.stdout.should match_output(:version, config.vagrant_version)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue