Update Chef provisioner to new validation API

This commit is contained in:
Mitchell Hashimoto 2013-01-18 13:12:02 -08:00
parent df32c47780
commit fff021e51d
5 changed files with 20 additions and 23 deletions

View File

@ -90,12 +90,10 @@ module Vagrant
# Called after the configuration is finalized and loaded to validate
# this object.
#
# @param [Environment] env Vagrant::Environment object of the
# environment that this configuration has been loaded into. This
# gives you convenient access to things like the the root path
# and so on.
# @param [ErrorRecorder] errors
def validate(env, errors)
# @param [Machine] machine Access to the machine that is being
# validated.
# @return [Hash]
def validate(machine)
end
end
end

View File

@ -52,12 +52,6 @@ module VagrantPlugins
run_list << name
end
def validate(env, errors)
super
errors.add(I18n.t("vagrant.config.chef.vagrant_as_json_key")) if json.has_key?(:vagrant)
end
def instance_variables_hash
# Overridden so that the 'json' key could be removed, since its just
# merged into the config anyways

View File

@ -22,12 +22,16 @@ module VagrantPlugins
def file_backup_path; @file_backup_path || "/srv/chef/cache"; end
def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end
def validate(env, errors)
super
def validate(machine)
errors = []
errors << I18n.t("vagrant.config.chef.server_url_empty") if \
!chef_server_url || chef_server_url.strip == ""
errors << I18n.t("vagrant.config.chef.validation_key_path") if \
!validation_key_path
errors << I18n.t("vagrant.config.chef.run_list_empty") if \
@run_list && @run_list.empty?
errors.add(I18n.t("vagrant.config.chef.server_url_empty")) if !chef_server_url || chef_server_url.strip == ""
errors.add(I18n.t("vagrant.config.chef.validation_key_path")) if !validation_key_path
errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if @run_list && @run_list.empty?
{ "chef client provisioner" => errors }
end
end
end

View File

@ -37,11 +37,14 @@ module VagrantPlugins
@nfs || false
end
def validate(env, errors)
super
def validate(machine)
errors = []
errors << I18n.t("vagrant.config.chef.cookbooks_path_empty") if \
!cookbooks_path || [cookbooks_path].flatten.empty?
errors << I18n.t("vagrant.config.chef.run_list_empty") if \
!run_list || run_list.empty?
errors.add(I18n.t("vagrant.config.chef.cookbooks_path_empty")) if !cookbooks_path || [cookbooks_path].flatten.empty?
errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if !run_list || run_list.empty?
{ "chef solo provisioner" => errors }
end
end
end

View File

@ -311,8 +311,6 @@ en:
cookbooks_path_empty: "Must specify a cookbooks path for chef solo."
run_list_empty: "Run list must not be empty."
server_url_empty: "Chef server URL must be populated."
vagrant_as_json_key: |-
`vagrant` cannot be a JSON key, because it is used by Vagrant already.
validation_key_path: "Validation key path must be valid path to your chef server validation key."
ssh:
private_key_missing: "`private_key_path` file must exist: %{path}"