Get shell provisioning working again, acceptance test to prove it
This commit is contained in:
parent
d6b325e887
commit
6dbade0fc6
|
@ -7,9 +7,9 @@ module Vagrant
|
||||||
class Base
|
class Base
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
|
|
||||||
# The environment which provisioner is running in. This is a
|
# The environment which provisioner is running in. This is the
|
||||||
# {Vagrant::Action::Environment}
|
# action environment, not a Vagrant::Environment.
|
||||||
attr_reader :action_env
|
attr_reader :env
|
||||||
|
|
||||||
# The configuration for this provisioner. This will be an instance of
|
# The configuration for this provisioner. This will be an instance of
|
||||||
# the `Config` class which is part of the provisioner.
|
# the `Config` class which is part of the provisioner.
|
||||||
|
@ -29,25 +29,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(env, config)
|
def initialize(env, config)
|
||||||
@action_env = env
|
@env = env
|
||||||
@config = config
|
@config = config
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the actual {Vagrant::Environment} which this provisioner
|
|
||||||
# represents.
|
|
||||||
#
|
|
||||||
# @return [Vagrant::Environment]
|
|
||||||
def env
|
|
||||||
action_env.env
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the VM which this provisioner is working on.
|
|
||||||
#
|
|
||||||
# @return [Vagrant::VM]
|
|
||||||
def vm
|
|
||||||
env.vm
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is the method called to "prepare" the provisioner. This is called
|
# This is the method called to "prepare" the provisioner. This is called
|
||||||
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
|
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
|
||||||
# This can be used to setup shared folders, forward ports, etc. Whatever is
|
# This can be used to setup shared folders, forward ports, etc. Whatever is
|
||||||
|
|
|
@ -16,11 +16,7 @@ module Vagrant
|
||||||
@args = nil
|
@args = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def expanded_path
|
def validate(env, errors)
|
||||||
Pathname.new(path).expand_path(env.root_path) if path
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate(errors)
|
|
||||||
super
|
super
|
||||||
|
|
||||||
# Validate that the parameters are properly set
|
# Validate that the parameters are properly set
|
||||||
|
@ -31,6 +27,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate the existence of a script to upload
|
# Validate the existence of a script to upload
|
||||||
|
expanded_path = Pathname.new(path).expand_path(env.root_path)
|
||||||
if path && !expanded_path.file?
|
if path && !expanded_path.file?
|
||||||
errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path))
|
errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path))
|
||||||
end
|
end
|
||||||
|
@ -53,7 +50,7 @@ module Vagrant
|
||||||
def with_script_file
|
def with_script_file
|
||||||
if config.path
|
if config.path
|
||||||
# Just yield the path to that file...
|
# Just yield the path to that file...
|
||||||
yield config.expanded_path
|
yield Pathname.new(config.path).expand_path(env[:root_path])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,15 +74,15 @@ module Vagrant
|
||||||
|
|
||||||
with_script_file do |path|
|
with_script_file do |path|
|
||||||
# Upload the script to the VM
|
# Upload the script to the VM
|
||||||
vm.ssh.upload!(path.to_s, config.upload_path)
|
env[:vm].ssh.upload!(path.to_s, config.upload_path)
|
||||||
|
|
||||||
# Execute it with sudo
|
# Execute it with sudo
|
||||||
vm.ssh.execute do |ssh|
|
env[:vm].ssh.execute do |ssh|
|
||||||
ssh.sudo!(commands) do |ch, type, data|
|
ssh.sudo!(commands) do |ch, type, data|
|
||||||
if type == :exit_status
|
if type == :exit_status
|
||||||
ssh.check_exit_status(data, commands)
|
ssh.check_exit_status(data, commands)
|
||||||
else
|
else
|
||||||
env.ui.info(data)
|
env[:ui].info(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
||||||
|
end
|
Loading…
Reference in New Issue