diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index 8a892fa2c..73ec117b9 100644 --- a/plugins/pushes/atlas/push.rb +++ b/plugins/pushes/atlas/push.rb @@ -27,6 +27,7 @@ module VagrantPlugins cmd << "-vcs" if config.vcs cmd += config.includes.map { |v| ["-include", v] } cmd += config.excludes.map { |v| ["-exclude", v] } + cmd += metadata.map { |k,v| ["-metadata", "#{k}=#{v}"] } cmd += ["-address", config.address] if config.address cmd += ["-token", config.token] if config.token cmd << config.app @@ -40,8 +41,7 @@ module VagrantPlugins # @return [String] def uploader_path # Determine the uploader path - uploader = config.uploader_path - if uploader + if uploader = config.uploader_path return uploader end @@ -53,6 +53,26 @@ module VagrantPlugins return Vagrant::Util::Which.which(UPLOADER_BIN) end + + # The metadata command for this push. + # + # @return [Array] + 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 diff --git a/test/unit/plugins/pushes/atlas/push_test.rb b/test/unit/plugins/pushes/atlas/push_test.rb index e7ffdebd5..72eb46057 100644 --- a/test/unit/plugins/pushes/atlas/push_test.rb +++ b/test/unit/plugins/pushes/atlas/push_test.rb @@ -9,9 +9,9 @@ describe VagrantPlugins::AtlasPush::Push do let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN } let(:env) do - double("env", - root_path: File.expand_path("..", __FILE__) - ) + iso_env = isolated_environment + iso_env.vagrantfile("") + iso_env.create_vagrant_env end let(:config) do @@ -99,6 +99,29 @@ describe VagrantPlugins::AtlasPush::Push do config.token = "atlas_token" subject.execute("foo") 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 describe "#uploader_path" do