From b13122cab7a8e36ff62c4b61626e9f93cde28940 Mon Sep 17 00:00:00 2001 From: Andy Fowler Date: Sat, 9 Nov 2013 18:16:47 -0500 Subject: [PATCH] use Retryable for virtualbox customize + defaults when up-ing several boxes at once, VBoxManage modifyvm gets cranky and throws random lock errors. this adds the existing retryable logic to the customize and sane_defaults actions, both of which fire a bunch of modifyvm commands, all of which are fine to run multiple times. --- plugins/providers/virtualbox/action/customize.rb | 9 +++++---- plugins/providers/virtualbox/action/sane_defaults.rb | 12 ++++++++++-- plugins/providers/virtualbox/driver/base.rb | 5 +++++ plugins/providers/virtualbox/driver/version_4_0.rb | 2 +- plugins/providers/virtualbox/driver/version_4_1.rb | 2 +- plugins/providers/virtualbox/driver/version_4_2.rb | 2 +- plugins/providers/virtualbox/driver/version_4_3.rb | 2 +- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/providers/virtualbox/action/customize.rb b/plugins/providers/virtualbox/action/customize.rb index 0bcb84a6d..f2bfda255 100644 --- a/plugins/providers/virtualbox/action/customize.rb +++ b/plugins/providers/virtualbox/action/customize.rb @@ -25,11 +25,12 @@ module VagrantPlugins arg.to_s end - result = env[:machine].provider.driver.execute_command(processed_command) - if result.exit_code != 0 + begin + env[:machine].provider.driver.execute_command(processed_command + [:retryable => true]) + rescue Vagrant::Errors::VBoxManageError => e raise Vagrant::Errors::VMCustomizationFailed, { - :command => processed_command.inspect, - :error => result.stderr + :command => command, + :error => e.inspect } end end diff --git a/plugins/providers/virtualbox/action/sane_defaults.rb b/plugins/providers/virtualbox/action/sane_defaults.rb index fc3f66ead..1dcac0a74 100644 --- a/plugins/providers/virtualbox/action/sane_defaults.rb +++ b/plugins/providers/virtualbox/action/sane_defaults.rb @@ -55,11 +55,19 @@ module VagrantPlugins # the given string to the log, and also includes the exit status in # the log message. # + # We assume every command is idempotent and pass along the `retryable` + # flag. This is because VBoxManage is janky about running simultaneously + # on the same box, and if we up multiple boxes at the same time, a bunch + # of modifyvm commands get fired + # # @param [Array] command Command to run # @param [String] log Log message to write. def attempt_and_log(command, log) - result = @env[:machine].provider.driver.execute_command(command) - @logger.info("#{log} (exit status = #{result.exit_code})") + begin + @env[:machine].provider.driver.execute_command(command + [:retryable => true]) + rescue Vagrant::Errors::VBoxManageError => e + @logger.info("#{log} (error = #{e.inspect})") + end end # This uses some heuristics to determine if the NAT DNS proxy should diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index d06898b2d..1e0795739 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -108,6 +108,11 @@ module VagrantPlugins # Execute a raw command straight through to VBoxManage. # + # Accepts a :retryable => true option if the command should be retried + # upon failure. + # + # Raises a VBoxManage error if it fails. + # # @param [Array] command Command to execute. def execute_command(command) end diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 9341a0362..e0ce73cac 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -129,7 +129,7 @@ module VagrantPlugins end def execute_command(command) - raw(*command) + execute(*command) end def export(path) diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index 2854e39ba..ab2bbfd8d 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -129,7 +129,7 @@ module VagrantPlugins end def execute_command(command) - raw(*command) + execute(*command) end def export(path) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index a537c4a60..a1aba3c8f 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -127,7 +127,7 @@ module VagrantPlugins end def execute_command(command) - raw(*command) + execute(*command) end def export(path) diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 123906502..44025361c 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -127,7 +127,7 @@ module VagrantPlugins end def execute_command(command) - raw(*command) + execute(*command) end def export(path)