Merge pull request #5283 from mitchellh/sethvargo/developed_on

Add extra metadata information to Atlas pushes
This commit is contained in:
Seth Vargo 2015-02-04 13:29:41 -05:00
commit 2c88f7b7d9
2 changed files with 48 additions and 5 deletions

View File

@ -27,6 +27,7 @@ module VagrantPlugins
cmd << "-vcs" if config.vcs cmd << "-vcs" if config.vcs
cmd += config.includes.map { |v| ["-include", v] } cmd += config.includes.map { |v| ["-include", v] }
cmd += config.excludes.map { |v| ["-exclude", v] } cmd += config.excludes.map { |v| ["-exclude", v] }
cmd += metadata.map { |k,v| ["-metadata", "#{k}=#{v}"] }
cmd += ["-address", config.address] if config.address cmd += ["-address", config.address] if config.address
cmd += ["-token", config.token] if config.token cmd += ["-token", config.token] if config.token
cmd << config.app cmd << config.app
@ -40,8 +41,7 @@ module VagrantPlugins
# @return [String] # @return [String]
def uploader_path def uploader_path
# Determine the uploader path # Determine the uploader path
uploader = config.uploader_path if uploader = config.uploader_path
if uploader
return uploader return uploader
end end
@ -53,6 +53,26 @@ module VagrantPlugins
return Vagrant::Util::Which.which(UPLOADER_BIN) return Vagrant::Util::Which.which(UPLOADER_BIN)
end end
# The metadata command for this push.
#
# @return [Array<String>]
def metadata
box = env.vagrantfile.config.vm.box
box_url = env.vagrantfile.config.vm.box_url
result = {}
if !box.nil? && !box.empty?
result["box"] = box
end
if !box_url.nil? && !box_url.empty?
result["box_url"] = Array(box_url).first
end
return result
end
end end
end end
end end

View File

@ -9,9 +9,9 @@ describe VagrantPlugins::AtlasPush::Push do
let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN } let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN }
let(:env) do let(:env) do
double("env", iso_env = isolated_environment
root_path: File.expand_path("..", __FILE__) iso_env.vagrantfile("")
) iso_env.create_vagrant_env
end end
let(:config) do let(:config) do
@ -99,6 +99,29 @@ describe VagrantPlugins::AtlasPush::Push do
config.token = "atlas_token" config.token = "atlas_token"
subject.execute("foo") subject.execute("foo")
end end
context "when metadata is available" do
let(:env) do
iso_env = isolated_environment
iso_env.vagrantfile <<-EOH
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.box_url = "https://atlas.hashicorp.com/hashicorp/precise64"
end
EOH
iso_env.create_vagrant_env
end
it "sends the metadata" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-metadata", "box=hashicorp/precise64",
"-metadata", "box_url=https://atlas.hashicorp.com/hashicorp/precise64",
"-token", "atlas_token", app, env.root_path.to_s)
config.token = "atlas_token"
subject.execute("foo")
end
end
end end
describe "#uploader_path" do describe "#uploader_path" do