From a6f0d24f6883ef030fde4b834bc3740a1bb16554 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 28 May 2019 18:12:23 -0700 Subject: [PATCH 01/12] Documenting local Vagrant vs package Vagrant. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index e4de36ff2..2c5c6ddb4 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,15 @@ Once your Vagrant bundle is installed from Git repository, you can run the test This will run the unit test suite, which should come back all green! +If you are developing Vagrant on a machine that already has a Vagrant package installation present, both will attempt to use the same folder for their configuration (location of this folder depends on system). In this case, override the +`VAGRANT_HOME` environment variable for your development version of Vagrant before running any commands. For example, in Bash: + + export VAGRANT_HOME=/path/to/project/.vagrant + +This folder will be ignored by Git. You can now run Vagrant commands against the development version: + + bundle exec vagrant + Please take time to read the [HashiCorp Community Guidelines](https://www.hashicorp.com/community-guidelines) and the [Vagrant Contributing Guide](https://github.com/hashicorp/vagrant/blob/master/.github/CONTRIBUTING.md). Then you're good to go! From c6a6fd34a3fb1b1bc0253d9aaa8970d7fad81598 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Wed, 29 May 2019 10:48:38 -0700 Subject: [PATCH 02/12] Adding machine-readable output to global-status --- plugins/commands/global-status/command.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/commands/global-status/command.rb b/plugins/commands/global-status/command.rb index da1399c0c..5cfadcc5e 100644 --- a/plugins/commands/global-status/command.rb +++ b/plugins/commands/global-status/command.rb @@ -65,6 +65,17 @@ module VagrantPlugins @env.machine_index.delete(deletable) if deletable end + # Machine-readable (non-formatted) output + @env.ui.machine("metadata", "machine-count", entries.length.to_s); + entries.each do |entry| + opts = { "target" => entry.send(:name).to_s } + @env.ui.machine("machine-id", entry.send(:id).to_s, opts) + @env.ui.machine("provider-name", entry.send(:provider).to_s, opts) + @env.ui.machine("machine-home", entry.send(:vagrantfile_path).to_s, opts) + @env.ui.machine("state", entry.send(:state).to_s, opts) + end + + # Human-readable (table formatted) output total_width = 0 columns.each do |header, method| header = header.ljust(widths[method]) if widths[method] From 731f249c5060dda2c3cb1cf974403f4c9fafa934 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Wed, 29 May 2019 11:10:33 -0700 Subject: [PATCH 03/12] Machine ID output should be 7 characters. --- plugins/commands/global-status/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/commands/global-status/command.rb b/plugins/commands/global-status/command.rb index 5cfadcc5e..ce8e30784 100644 --- a/plugins/commands/global-status/command.rb +++ b/plugins/commands/global-status/command.rb @@ -69,7 +69,7 @@ module VagrantPlugins @env.ui.machine("metadata", "machine-count", entries.length.to_s); entries.each do |entry| opts = { "target" => entry.send(:name).to_s } - @env.ui.machine("machine-id", entry.send(:id).to_s, opts) + @env.ui.machine("machine-id", entry.send(:id).to_s[0...7], opts) @env.ui.machine("provider-name", entry.send(:provider).to_s, opts) @env.ui.machine("machine-home", entry.send(:vagrantfile_path).to_s, opts) @env.ui.machine("state", entry.send(:state).to_s, opts) From 2088bfb60d3b7fdc1bc9f5adf28f4bb461b87388 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Wed, 29 May 2019 20:31:18 -0700 Subject: [PATCH 04/12] Adding note to README re: bsdtar dependency --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2c5c6ddb4..bbb53c96c 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ and you're welcome to give it a shot. Please review the installation page [here] ## Contributing to Vagrant +Package dependencies: Vagrant requires `bsdtar` to be available on your system PATH to run tests successfully. + Once your Vagrant bundle is installed from Git repository, you can run the test suite with: bundle exec rake From f626c53af2066709b20c3629eb8800d7f65955ee Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Thu, 30 May 2019 08:39:49 -0700 Subject: [PATCH 05/12] Suppressing UI output in machine-readable mode --- lib/vagrant/ui.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 70474d111..b9cb2ed4f 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -103,12 +103,6 @@ module Vagrant raise Errors::UIExpectsTTY end - [:detail, :warn, :error, :info, :output, :success].each do |method| - define_method(method) do |message, *args, **opts| - machine("ui", method.to_s, message, *args, **opts) - end - end - def machine(type, *data) opts = {} opts = data.pop if data.last.kind_of?(Hash) From f25427869c90a07cef8331e0909b89cb184c935c Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Thu, 30 May 2019 09:17:30 -0700 Subject: [PATCH 06/12] Updating unit tests w/ UI message suppression --- test/unit/vagrant/ui_test.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index c1eb89211..9365ff3a1 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -2,7 +2,7 @@ require File.expand_path("../../base", __FILE__) describe Vagrant::UI::Basic do context "in general" do - it "outputs within the a new thread" do + it "outputs within a new thread" do current = Thread.current.object_id expect(subject).to receive(:safe_puts).with(any_args) { |*args| @@ -231,16 +231,8 @@ describe Vagrant::UI::MachineReadable do [:detail, :warn, :error, :info, :output, :success].each do |method| describe "##{method}" do - it "outputs UI type to the machine-readable output" do - expect(subject).to receive(:safe_puts).with(any_args) { |message| - parts = message.split(",") - expect(parts.length).to eq(5) - expect(parts[1]).to eq("") - expect(parts[2]).to eq("ui") - expect(parts[3]).to eq(method.to_s) - expect(parts[4]).to eq("foo") - true - } + it "does not output UI type to the machine-readable output" do + expect(subject).to receive(:safe_puts).never subject.send(method, "foo") end From b57d467fa2f6f30b6030846ef374ce0e4e0c65b3 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 4 Jun 2019 20:58:46 -0700 Subject: [PATCH 07/12] Revert "Updating unit tests w/ UI message suppression" This reverts commit f25427869c90a07cef8331e0909b89cb184c935c. --- test/unit/vagrant/ui_test.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index 9365ff3a1..c1eb89211 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -2,7 +2,7 @@ require File.expand_path("../../base", __FILE__) describe Vagrant::UI::Basic do context "in general" do - it "outputs within a new thread" do + it "outputs within the a new thread" do current = Thread.current.object_id expect(subject).to receive(:safe_puts).with(any_args) { |*args| @@ -231,8 +231,16 @@ describe Vagrant::UI::MachineReadable do [:detail, :warn, :error, :info, :output, :success].each do |method| describe "##{method}" do - it "does not output UI type to the machine-readable output" do - expect(subject).to receive(:safe_puts).never + it "outputs UI type to the machine-readable output" do + expect(subject).to receive(:safe_puts).with(any_args) { |message| + parts = message.split(",") + expect(parts.length).to eq(5) + expect(parts[1]).to eq("") + expect(parts[2]).to eq("ui") + expect(parts[3]).to eq(method.to_s) + expect(parts[4]).to eq("foo") + true + } subject.send(method, "foo") end From 33a228a8e2be4df6486d81288b3c037f580ca6da Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 4 Jun 2019 20:58:52 -0700 Subject: [PATCH 08/12] Revert "Suppressing UI output in machine-readable mode" This reverts commit f626c53af2066709b20c3629eb8800d7f65955ee. --- lib/vagrant/ui.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index b9cb2ed4f..70474d111 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -103,6 +103,12 @@ module Vagrant raise Errors::UIExpectsTTY end + [:detail, :warn, :error, :info, :output, :success].each do |method| + define_method(method) do |message, *args, **opts| + machine("ui", method.to_s, message, *args, **opts) + end + end + def machine(type, *data) opts = {} opts = data.pop if data.last.kind_of?(Hash) From 8c03b5179af0a84f8d369b0cc2473fb5a1b39d6d Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 4 Jun 2019 21:16:03 -0700 Subject: [PATCH 09/12] Correcting suggested VAGRANT_HOME location in dev. --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bbb53c96c..e2e387dcf 100644 --- a/README.md +++ b/README.md @@ -58,12 +58,11 @@ Once your Vagrant bundle is installed from Git repository, you can run the test This will run the unit test suite, which should come back all green! -If you are developing Vagrant on a machine that already has a Vagrant package installation present, both will attempt to use the same folder for their configuration (location of this folder depends on system). In this case, override the -`VAGRANT_HOME` environment variable for your development version of Vagrant before running any commands. For example, in Bash: +If you are developing Vagrant on a machine that already has a Vagrant package installation present, both will attempt to use the same folder for their configuration (location of this folder depends on system). This can cause errors when Vagrant attempts to load plugins. In this case, override the `VAGRANT_HOME` environment variable for your development version of Vagrant before running any commands, to be some new folder within the project or elsewhere on your machine. For example, in Bash: - export VAGRANT_HOME=/path/to/project/.vagrant + export VAGRANT_HOME=~/.vagrant-dev -This folder will be ignored by Git. You can now run Vagrant commands against the development version: +You can now run Vagrant commands against the development version: bundle exec vagrant From ede2c295f4429431448d0bae8f2e83abab5784a1 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 4 Jun 2019 21:27:14 -0700 Subject: [PATCH 10/12] bsdtar appears to be required for all Vagrant use. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e2e387dcf..bfc453490 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ between Windows, Mac OS X, and Linux. ## Quick Start +Package dependencies: Vagrant requires `bsdtar` to be available on your system PATH to run successfully. + For the quick-start, we'll bring up a development machine on [VirtualBox](https://www.virtualbox.org/) because it is free and works on all major platforms. Vagrant can, however, work with almost any @@ -50,8 +52,6 @@ and you're welcome to give it a shot. Please review the installation page [here] ## Contributing to Vagrant -Package dependencies: Vagrant requires `bsdtar` to be available on your system PATH to run tests successfully. - Once your Vagrant bundle is installed from Git repository, you can run the test suite with: bundle exec rake From 2f818c0e2354b4819d699a41eb5461cda9b58753 Mon Sep 17 00:00:00 2001 From: Greg J Preece Date: Tue, 4 Jun 2019 21:35:37 -0700 Subject: [PATCH 11/12] Removing unneeded .send() calls in machine output. --- plugins/commands/global-status/command.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/commands/global-status/command.rb b/plugins/commands/global-status/command.rb index ce8e30784..f9c4207be 100644 --- a/plugins/commands/global-status/command.rb +++ b/plugins/commands/global-status/command.rb @@ -68,11 +68,11 @@ module VagrantPlugins # Machine-readable (non-formatted) output @env.ui.machine("metadata", "machine-count", entries.length.to_s); entries.each do |entry| - opts = { "target" => entry.send(:name).to_s } - @env.ui.machine("machine-id", entry.send(:id).to_s[0...7], opts) - @env.ui.machine("provider-name", entry.send(:provider).to_s, opts) - @env.ui.machine("machine-home", entry.send(:vagrantfile_path).to_s, opts) - @env.ui.machine("state", entry.send(:state).to_s, opts) + opts = { "target" => entry.name.to_s } + @env.ui.machine("machine-id", entry.id.to_s[0...7], opts) + @env.ui.machine("provider-name", entry.provider.to_s, opts) + @env.ui.machine("machine-home", entry.vagrantfile_path.to_s, opts) + @env.ui.machine("state", entry.state.to_s, opts) end # Human-readable (table formatted) output From fd34ea657b624b80001c8f565dcd7ec7f37d6745 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 5 Jun 2019 13:04:47 -0700 Subject: [PATCH 12/12] Add test coverage on expected machine-readable output --- .../commands/global-status/command_test.rb | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/unit/plugins/commands/global-status/command_test.rb b/test/unit/plugins/commands/global-status/command_test.rb index ebedcedb6..837735551 100644 --- a/test/unit/plugins/commands/global-status/command_test.rb +++ b/test/unit/plugins/commands/global-status/command_test.rb @@ -10,9 +10,11 @@ describe VagrantPlugins::CommandGlobalStatus::Command do # We have to create a Vagrantfile so there is a root path env = isolated_environment env.vagrantfile("") - env.create_vagrant_env + env.create_vagrant_env(env_opts) end + let(:env_opts) { {} } + let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) } let(:argv) { [] } @@ -37,6 +39,38 @@ describe VagrantPlugins::CommandGlobalStatus::Command do end end + describe "with --machine-readable" do + let(:env_opts) { {ui_class: Vagrant::UI::MachineReadable} } + + before do + iso_env.machine_index.set(new_entry("foo")) + iso_env.machine_index.set(new_entry("bar")) + allow($stdout).to receive(:puts) + end + + after { subject.execute } + + it "should include the machine id" do + expect($stdout).to receive(:puts).with(/,machine-id,/).twice + end + + it "should include the machine state" do + expect($stdout).to receive(:puts).with(/,state,/).twice + end + + it "should include the machine count" do + expect($stdout).to receive(:puts).with(/machine-count,2/) + end + + it "should include the machine home path" do + expect($stdout).to receive(:puts).with(/,machine-home,/).twice + end + + it "should include the provider name" do + expect($stdout).to receive(:puts).with(/,provider-name,/).twice + end + end + describe "execute with --prune" do let(:argv) { ["--prune"] }