Prompt for `reload` if shared folders aren't setup for Chef [GH-253]

This commit is contained in:
Mitchell Hashimoto 2012-01-10 22:36:39 -08:00
parent 638881614a
commit cb6020869f
4 changed files with 43 additions and 2 deletions

View File

@ -50,6 +50,8 @@
`sudo` installed Vagrant installations work. [GH-580] `sudo` installed Vagrant installations work. [GH-580]
- Provisioner stdout/stderr is now color coded based on stdout/stderr. - Provisioner stdout/stderr is now color coded based on stdout/stderr.
stdout is green, stderr is red. [GH-595] stdout is green, stderr is red. [GH-595]
- Chef solo now prompts users to run a `reload` if shared folders
are not found on the VM. [GH-253]
- "--no-provision" once again works for certain commands. [GH-591] - "--no-provision" once again works for certain commands. [GH-591]
- Resuming a VM from a saved state will show an error message if there - Resuming a VM from a saved state will show an error message if there
would be port collisions. [GH-602] would be port collisions. [GH-602]

View File

@ -7,7 +7,8 @@ module Vagrant
def initialize(app, env) def initialize(app, env)
@logger = Log4r::Logger.new("vagrant::action::vm::provision") @logger = Log4r::Logger.new("vagrant::action::vm::provision")
@app = app @app = app
@env["provision.enabled"] = true if !env.has_key?("provision.enabled")
env["provision.enabled"] = true if !env.has_key?("provision.enabled")
end end
def call(env) def call(env)

View File

@ -1,3 +1,5 @@
require "log4r"
require 'vagrant/provisioners/chef' require 'vagrant/provisioners/chef'
module Vagrant module Vagrant
@ -39,6 +41,11 @@ module Vagrant
Config Config
end end
def initialize(env, config)
super
@logger = Log4r::Logger.new("vagrant::provisioners::chef_solo")
end
def prepare def prepare
@cookbook_folders = expanded_folders(config.cookbooks_path, "cookbooks") @cookbook_folders = expanded_folders(config.cookbooks_path, "cookbooks")
@role_folders = expanded_folders(config.roles_path, "roles") @role_folders = expanded_folders(config.roles_path, "roles")
@ -50,6 +57,19 @@ module Vagrant
end end
def provision! def provision!
# Verify that the proper shared folders exist.
check = []
[@cookbook_folders, @role_folders, @data_bags_folders].each do |folders|
folders.each do |type, local_path, remote_path|
# We only care about checking folders that have a local path, meaning
# they were shared from the local machine, rather than assumed to
# exist on the VM.
check << remote_path if local_path
end
end
verify_shared_folders(check)
verify_binary(chef_binary_path("chef-solo")) verify_binary(chef_binary_path("chef-solo"))
chown_provisioning_folder chown_provisioning_folder
setup_json setup_json
@ -138,6 +158,17 @@ module Vagrant
end end
end end
def verify_shared_folders(folders)
folders.each do |folder|
@logger.debug("Checking for shared folder: #{folder}")
if !env[:vm].channel.test("test -d #{folder}")
raise ChefError, :missing_shared_folders
end
end
end
protected
# Extracts only the remote paths from a list of folders # Extracts only the remote paths from a list of folders
def guest_paths(folders) def guest_paths(folders)
folders.map { |parts| parts[2] } folders.map { |parts| parts[2] }

View File

@ -564,7 +564,14 @@ en:
upload_encrypted_data_bag_secret_key: "Uploading chef encrypted data bag secret key..." upload_encrypted_data_bag_secret_key: "Uploading chef encrypted data bag secret key..."
running_client: "Running chef-client..." running_client: "Running chef-client..."
running_solo: "Running chef-solo..." running_solo: "Running chef-solo..."
invalid_provisioner: "Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefClient instead." invalid_provisioner: |-
Vagrant::Provisioners::Chef is not a valid provisioner! Use
ChefSolo or ChefClient instead.
missing_shared_folders: |-
Shared folders that Chef requires are missing on the virtual machine.
This is usually due to configuration changing after already booting the
machine. The fix is to run a `vagrant reload` so that the proper shared
folders will prepared and mounted on the VM.
not_detected: |- not_detected: |-
The `%{binary}` binary appears to not be in the PATH of the guest. This The `%{binary}` binary appears to not be in the PATH of the guest. This
could be because the PATH is not properly setup or perhaps chef is not could be because the PATH is not properly setup or perhaps chef is not