Merge branch 'master' of github.com:hashicorp/vagrant
This commit is contained in:
commit
045f31cc45
|
@ -129,10 +129,10 @@ module Vagrant
|
||||||
if ENV["VAGRANT_APPIMAGE"]
|
if ENV["VAGRANT_APPIMAGE"]
|
||||||
embed_path = Pathname.new(Vagrant.installer_embedded_dir).expand_path.to_s
|
embed_path = Pathname.new(Vagrant.installer_embedded_dir).expand_path.to_s
|
||||||
exec_path = Pathname.new(@command[0]).expand_path.to_s
|
exec_path = Pathname.new(@command[0]).expand_path.to_s
|
||||||
if !exec_path.start_with?(embed_path) && ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"]
|
if !exec_path.start_with?(embed_path) && ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"]
|
||||||
@logger.info("Detected AppImage environment and request to external binary. Updating library path.")
|
@logger.info("Detected AppImage environment and request to external binary. Updating library path.")
|
||||||
@logger.debug("Setting LD_LIBRARY_PATH to #{ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"]}")
|
@logger.debug("Setting LD_LIBRARY_PATH to #{ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"]}")
|
||||||
process.environment["LD_LIBRARY_PATH"] = ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"].to_s
|
process.environment["LD_LIBRARY_PATH"] = ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"].to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,7 +7,8 @@ module VagrantPlugins
|
||||||
attr_accessor :sensitive
|
attr_accessor :sensitive
|
||||||
attr_accessor :plugins
|
attr_accessor :plugins
|
||||||
|
|
||||||
VALID_PLUGIN_KEYS = [:sources, :version, :entry_point].freeze
|
VALID_PLUGIN_KEYS = ["sources", "version", "entry_point"].map(&:freeze).freeze
|
||||||
|
INVALID_PLUGIN_FORMAT = :invalid_plugin_format
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@host = UNSET_VALUE
|
@host = UNSET_VALUE
|
||||||
|
@ -43,13 +44,21 @@ module VagrantPlugins
|
||||||
errors << I18n.t("vagrant.config.root.sensitive_bad_type")
|
errors << I18n.t("vagrant.config.root.sensitive_bad_type")
|
||||||
end
|
end
|
||||||
|
|
||||||
@plugins.each do |plugin_name, plugin_info|
|
if @plugins == INVALID_PLUGIN_FORMAT
|
||||||
invalid_keys = plugin_info.keys - VALID_PLUGIN_KEYS
|
errors << I18n.t("vagrant.config.root.plugins_invalid_format")
|
||||||
if !invalid_keys.empty?
|
else
|
||||||
errors << I18n.t("vagrant.config.root.plugins_bad_key",
|
@plugins.each do |plugin_name, plugin_info|
|
||||||
plugin_name: plugin_name,
|
if plugin_info.is_a?(Hash)
|
||||||
plugin_key: invalid_keys.join(", ")
|
invalid_keys = plugin_info.keys - VALID_PLUGIN_KEYS
|
||||||
)
|
if !invalid_keys.empty?
|
||||||
|
errors << I18n.t("vagrant.config.root.plugins_bad_key",
|
||||||
|
plugin_name: plugin_name,
|
||||||
|
plugin_key: invalid_keys.join(", ")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
errors << I18n.t("vagrant.config.root.plugins_invalid_format")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,18 +70,26 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_plugins(val)
|
def format_plugins(val)
|
||||||
result = case val
|
case val
|
||||||
when String
|
when String
|
||||||
{val => {}}
|
{val => Vagrant::Util::HashWithIndifferentAccess.new}
|
||||||
when Array
|
when Array
|
||||||
Hash[val.map{|item| [item.to_s, {}]}]
|
val.inject(Vagrant::Util::HashWithIndifferentAccess.new) { |memo, item|
|
||||||
else
|
memo.merge(format_plugins(item))
|
||||||
val
|
}
|
||||||
end
|
when Hash
|
||||||
result.keys.each do |key|
|
Vagrant::Util::HashWithIndifferentAccess.new.tap { |h|
|
||||||
result[key] = Hash[result[key].map{|k,v| [k.to_sym, v]}]
|
val.each_pair { |k, v|
|
||||||
|
if v.is_a?(Hash)
|
||||||
|
h[k] = Vagrant::Util::HashWithIndifferentAccess.new(v)
|
||||||
|
else
|
||||||
|
h[k] = v
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
INVALID_PLUGIN_FORMAT
|
||||||
end
|
end
|
||||||
result
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1815,6 +1815,8 @@ en:
|
||||||
sensitive_bad_type: |-
|
sensitive_bad_type: |-
|
||||||
Invalid type provided for `sensitive`. The sensitive option expects a string
|
Invalid type provided for `sensitive`. The sensitive option expects a string
|
||||||
or an array of strings.
|
or an array of strings.
|
||||||
|
plugins_invalid_format: |-
|
||||||
|
Invalid type provided for `plugins`.
|
||||||
plugins_bad_key: |-
|
plugins_bad_key: |-
|
||||||
Invalid plugin configuration detected for `%{plugin_name}` plugin.
|
Invalid plugin configuration detected for `%{plugin_name}` plugin.
|
||||||
|
|
||||||
|
|
|
@ -56,4 +56,54 @@ describe VagrantPlugins::Kernel_V2::VagrantConfig do
|
||||||
subject.finalize!
|
subject.finalize!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#plugins" do
|
||||||
|
it "converts string into hash of plugins" do
|
||||||
|
subject.plugins = "vagrant-plugin"
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.plugins).to be_a(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "converts array of strings into hash of plugins" do
|
||||||
|
subject.plugins = ["vagrant-plugin", "vagrant-other-plugin"]
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.plugins).to be_a(Hash)
|
||||||
|
expect(subject.plugins.keys).to eq(["vagrant-plugin", "vagrant-other-plugin"])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not convert hash" do
|
||||||
|
plugins = {"vagrant-plugin" => {}}
|
||||||
|
subject.plugins = plugins
|
||||||
|
subject.finalize
|
||||||
|
expect(subject.plugins).to eq(plugins)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "converts array of mixed strings and hashes" do
|
||||||
|
subject.plugins = ["vagrant-plugin", {"vagrant-other-plugin" => {:version => "1"}}]
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.plugins["vagrant-plugin"]).to eq({})
|
||||||
|
expect(subject.plugins["vagrant-other-plugin"]).to eq({"version" => "1"})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates a validation error when incorrect type is provided" do
|
||||||
|
subject.plugins = 0
|
||||||
|
subject.finalize!
|
||||||
|
result = subject.validate(machine)
|
||||||
|
expect(result.values).not_to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates a validation error when invalid option is provided" do
|
||||||
|
subject.plugins = {"vagrant-plugin" => {"badkey" => true}}
|
||||||
|
subject.finalize!
|
||||||
|
result = subject.validate(machine)
|
||||||
|
expect(result.values).not_to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates a validation error when options are incorrect type" do
|
||||||
|
subject.plugins = {"vagrant-plugin" => 1}
|
||||||
|
subject.finalize!
|
||||||
|
result = subject.validate(machine)
|
||||||
|
expect(result.values).not_to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe Vagrant::Util::Subprocess do
|
||||||
allow(process_env).to receive(:[]=)
|
allow(process_env).to receive(:[]=)
|
||||||
allow(ENV).to receive(:[]).with("VAGRANT_INSTALLER_ENV").and_return("1")
|
allow(ENV).to receive(:[]).with("VAGRANT_INSTALLER_ENV").and_return("1")
|
||||||
allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE").and_return("1")
|
allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE").and_return("1")
|
||||||
allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE_LD_LIBRARY_PATH").and_return(appimage_ld_path)
|
allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH").and_return(appimage_ld_path)
|
||||||
allow(File).to receive(:file?).with(exec_path).and_return(true)
|
allow(File).to receive(:file?).with(exec_path).and_return(true)
|
||||||
allow(ChildProcess).to receive(:build).and_return(process)
|
allow(ChildProcess).to receive(:build).and_return(process)
|
||||||
allow(Vagrant).to receive(:installer_embedded_dir).and_return(appimage_path)
|
allow(Vagrant).to receive(:installer_embedded_dir).and_return(appimage_path)
|
||||||
|
|
Loading…
Reference in New Issue