From 52d0df329685b32c0805e0a209a001eb0690a9f1 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 19:19:08 -0500 Subject: [PATCH 1/7] Add --message option to `vagrant push` --- plugins/commands/push/command.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/commands/push/command.rb b/plugins/commands/push/command.rb index 902a0c946..f76d5a5d2 100644 --- a/plugins/commands/push/command.rb +++ b/plugins/commands/push/command.rb @@ -9,8 +9,17 @@ module VagrantPlugins # @todo support multiple strategies if requested by the community def execute + options = {} + opts = OptionParser.new do |o| o.banner = "Usage: vagrant push [strategy] [options]" + o.separator "" + o.separator "Options:" + o.separator "" + + o.on("-m", "--message BODY", "Text to identify this push") do |m| + options[:message] = m + end end # Parse the options From edbc3e74d4a99836fbac8b25b382547cab16077d Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 19:19:51 -0500 Subject: [PATCH 2/7] Pass metadata to push command --- plugins/pushes/atlas/push.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index 8a892fa2c..7def5077f 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 @@ -53,6 +54,16 @@ module VagrantPlugins return Vagrant::Util::Which.which(UPLOADER_BIN) end + + # The metadata command for this push. + # + # @return [Array] + def metadata + hash = { + "box" => env.vagrantfile.config.vm.box, + "box_url" => env.vagrantfile.config.vm.box_url, + }.reject { |k,v| v.nil? || v.empty? } + end end end end From 0dde0b3756d0a2770ff6736f605c4dede70d0af8 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 19:19:58 -0500 Subject: [PATCH 3/7] Use a real iso env for push tests --- test/unit/plugins/pushes/atlas/push_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/unit/plugins/pushes/atlas/push_test.rb b/test/unit/plugins/pushes/atlas/push_test.rb index e7ffdebd5..b59b2bde0 100644 --- a/test/unit/plugins/pushes/atlas/push_test.rb +++ b/test/unit/plugins/pushes/atlas/push_test.rb @@ -8,10 +8,17 @@ describe VagrantPlugins::AtlasPush::Push do let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN } + # let(:env) do + # double("env", + # root_path: File.expand_path("..", __FILE__) + # ) + # end + let(:env) do - double("env", - root_path: File.expand_path("..", __FILE__) - ) + # We have to create a Vagrantfile so there is a root path + env = isolated_environment + env.vagrantfile("") + env.create_vagrant_env end let(:config) do From d29a474fbb90ad701f6a274bf866d1e795cc3fc1 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 19:20:12 -0500 Subject: [PATCH 4/7] Cleanup that syntax --- plugins/pushes/atlas/push.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index 7def5077f..e44f65364 100644 --- a/plugins/pushes/atlas/push.rb +++ b/plugins/pushes/atlas/push.rb @@ -41,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 From 82b24e9a8fe6c27a498b707e40793f5f8abf0612 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 19:20:27 -0500 Subject: [PATCH 5/7] Pass in a message to the command as well --- plugins/pushes/atlas/push.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index e44f65364..323f070f5 100644 --- a/plugins/pushes/atlas/push.rb +++ b/plugins/pushes/atlas/push.rb @@ -30,6 +30,7 @@ module VagrantPlugins cmd += metadata.map { |k,v| ["-metadata", "#{k}=#{v}"] } cmd += ["-address", config.address] if config.address cmd += ["-token", config.token] if config.token + cmd += ["-message", message] if message cmd << config.app cmd << File.expand_path(config.dir, env.root_path) Vagrant::Util::SafeExec.exec(uploader, *cmd.flatten) From 257ff57772733fcb0ee01f1db236ff3cd0530137 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 21:06:51 -0500 Subject: [PATCH 6/7] Remove message for now --- plugins/commands/push/command.rb | 9 --------- plugins/pushes/atlas/push.rb | 1 - 2 files changed, 10 deletions(-) diff --git a/plugins/commands/push/command.rb b/plugins/commands/push/command.rb index f76d5a5d2..902a0c946 100644 --- a/plugins/commands/push/command.rb +++ b/plugins/commands/push/command.rb @@ -9,17 +9,8 @@ module VagrantPlugins # @todo support multiple strategies if requested by the community def execute - options = {} - opts = OptionParser.new do |o| o.banner = "Usage: vagrant push [strategy] [options]" - o.separator "" - o.separator "Options:" - o.separator "" - - o.on("-m", "--message BODY", "Text to identify this push") do |m| - options[:message] = m - end end # Parse the options diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index 323f070f5..e44f65364 100644 --- a/plugins/pushes/atlas/push.rb +++ b/plugins/pushes/atlas/push.rb @@ -30,7 +30,6 @@ module VagrantPlugins cmd += metadata.map { |k,v| ["-metadata", "#{k}=#{v}"] } cmd += ["-address", config.address] if config.address cmd += ["-token", config.token] if config.token - cmd += ["-message", message] if message cmd << config.app cmd << File.expand_path(config.dir, env.root_path) Vagrant::Util::SafeExec.exec(uploader, *cmd.flatten) From 7d25a687ca34da229fd79828483e649f50455678 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 4 Feb 2015 11:45:02 -0500 Subject: [PATCH 7/7] Add tests for sending metadata --- plugins/pushes/atlas/push.rb | 18 ++++++++--- test/unit/plugins/pushes/atlas/push_test.rb | 36 +++++++++++++++------ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/plugins/pushes/atlas/push.rb b/plugins/pushes/atlas/push.rb index e44f65364..73ec117b9 100644 --- a/plugins/pushes/atlas/push.rb +++ b/plugins/pushes/atlas/push.rb @@ -58,10 +58,20 @@ module VagrantPlugins # # @return [Array] def metadata - hash = { - "box" => env.vagrantfile.config.vm.box, - "box_url" => env.vagrantfile.config.vm.box_url, - }.reject { |k,v| v.nil? || v.empty? } + 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 diff --git a/test/unit/plugins/pushes/atlas/push_test.rb b/test/unit/plugins/pushes/atlas/push_test.rb index b59b2bde0..72eb46057 100644 --- a/test/unit/plugins/pushes/atlas/push_test.rb +++ b/test/unit/plugins/pushes/atlas/push_test.rb @@ -8,17 +8,10 @@ describe VagrantPlugins::AtlasPush::Push do let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN } - # let(:env) do - # double("env", - # root_path: File.expand_path("..", __FILE__) - # ) - # end - let(:env) do - # We have to create a Vagrantfile so there is a root path - env = isolated_environment - env.vagrantfile("") - env.create_vagrant_env + iso_env = isolated_environment + iso_env.vagrantfile("") + iso_env.create_vagrant_env end let(:config) do @@ -106,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