Port collision with SSH test.
This commit is contained in:
parent
1f0720dfc2
commit
919f7adaa3
|
@ -25,7 +25,7 @@ end
|
|||
|
||||
# Enable logging if requested
|
||||
if ENV["ACCEPTANCE_LOG"]
|
||||
logger = Log4r::Logger.new("acceptance")
|
||||
logger = Log4r::Logger.new("test")
|
||||
logger.outputters = Log4r::Outputter.stdout
|
||||
logger.level = Log4r.const_get(ENV["ACCEPTANCE_LOG"].upcase)
|
||||
logger = nil
|
||||
|
|
|
@ -6,15 +6,23 @@ require "uri"
|
|||
require "vagrant/util/retryable"
|
||||
|
||||
require "acceptance/support/shared/command_examples"
|
||||
require "support/tempdir"
|
||||
|
||||
describe "vagrant port forwarding" do
|
||||
include Vagrant::Util::Retryable
|
||||
|
||||
include_context "acceptance"
|
||||
|
||||
it "forwards ports properly" do
|
||||
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
|
||||
|
||||
|
@ -27,7 +35,6 @@ end
|
|||
VFILE
|
||||
end
|
||||
|
||||
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
||||
assert_execute("vagrant", "up")
|
||||
|
||||
thr = nil
|
||||
|
@ -49,4 +56,36 @@ VFILE
|
|||
thr.kill if thr
|
||||
end
|
||||
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
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Acceptance
|
|||
attr_reader :box_directory
|
||||
|
||||
def initialize(path)
|
||||
@logger = Log4r::Logger.new("acceptance::config")
|
||||
@logger = Log4r::Logger.new("test::acceptance::config")
|
||||
@logger.info("Loading configuration from: #{path}")
|
||||
options = YAML.load_file(path)
|
||||
@logger.info("Loaded: #{options.inspect}")
|
||||
|
|
|
@ -14,15 +14,15 @@ module Acceptance
|
|||
def initialize(apps=nil, env=nil)
|
||||
super()
|
||||
|
||||
@logger = Log4r::Logger.new("acceptance::isolated_environment")
|
||||
@logger = Log4r::Logger.new("test::acceptance::isolated_environment")
|
||||
|
||||
@apps = apps || {}
|
||||
@env = env || {}
|
||||
@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
|
||||
@env["HOME"] ||= @homedir.to_s
|
||||
@env["VBOX_USER_HOME"] ||= @homedir.to_s
|
||||
end
|
||||
|
||||
# Executes a command in the context of this isolated environment.
|
||||
|
@ -32,8 +32,6 @@ module Acceptance
|
|||
# Create the command
|
||||
command = replace_command(command)
|
||||
|
||||
@logger.info("Executing: #{[command].concat(argN).inspect}")
|
||||
|
||||
# Determine the options
|
||||
options = argN.last.is_a?(Hash) ? argN.pop : {}
|
||||
options = {
|
||||
|
@ -45,6 +43,7 @@ module Acceptance
|
|||
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?
|
||||
|
|
|
@ -7,7 +7,7 @@ shared_context "acceptance" do
|
|||
# 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("acceptance::#{logger_name}") }
|
||||
let(:logger) { Log4r::Logger.new("test::acceptance::#{logger_name}") }
|
||||
|
||||
# This is the global configuration given by the acceptance test
|
||||
# configurations.
|
||||
|
@ -18,10 +18,7 @@ shared_context "acceptance" do
|
|||
# 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) do
|
||||
apps = { "vagrant" => config.vagrant_path }
|
||||
Acceptance::IsolatedEnvironment.new(apps, config.env)
|
||||
end
|
||||
let!(:environment) { new_environment }
|
||||
|
||||
before(:each) do
|
||||
# Wait for VBoxSVC to disappear, since each test requires its
|
||||
|
@ -33,6 +30,16 @@ shared_context "acceptance" 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]
|
||||
|
|
|
@ -24,7 +24,7 @@ class IsolatedEnvironment
|
|||
# @param [Hash] env Additional environmental variables to inject
|
||||
# into the execution environments.
|
||||
def initialize
|
||||
@logger = Log4r::Logger.new("isolated_environment")
|
||||
@logger = Log4r::Logger.new("test::isolated_environment")
|
||||
|
||||
# Create a temporary directory for our work
|
||||
@tempdir = Tempdir.new("vagrant")
|
||||
|
|
Loading…
Reference in New Issue