From 0b4ae5ff1267f2cf6da7504373a47295131adf7b Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 13 Apr 2016 22:28:28 +0300 Subject: [PATCH] driver: Add retries for snapshot commands Sometimes prlctl could fail on "snapshot-delete'" and "snapshot-switch" commands with an error: "The operation cannot be performed at the moment. Data synchronization is currently in progress. Try to perform the operation later." --- lib/vagrant-parallels/driver/base.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 2437a869..55c727b9 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -3,6 +3,7 @@ require 'vagrant/util/busy' require 'vagrant/util/network_ip' require 'vagrant/util/platform' +require 'vagrant/util/retryable' require 'vagrant/util/subprocess' require 'vagrant/util/which' @@ -161,7 +162,11 @@ def delete_disabled_adapters # @param [String] uuid Name or UUID of the target VM # @param [String] snapshot_id Snapshot ID def delete_snapshot(uuid, snapshot_id) - execute_prlctl('snapshot-delete', uuid, '--id', snapshot_id) + # Sometimes this command fails with 'Data synchronization is currently + # in progress'. Just wait and retry. + retryable(on: VagrantPlugins::Parallels::Errors::ExecutionError, tries: 2, sleep: 2) do + execute_prlctl('snapshot-delete', uuid, '--id', snapshot_id) + end end # Deletes any host only networks that aren't being used for anything. @@ -537,7 +542,11 @@ def register(pvm_file, opts=[]) # @param [String] uuid Name or UUID of the target VM # @param [String] snapshot_id Snapshot ID def restore_snapshot(uuid, snapshot_id) - execute_prlctl('snapshot-switch', uuid, '-i', snapshot_id) + # Sometimes this command fails with 'Data synchronization is currently + # in progress'. Just wait and retry. + retryable(on: VagrantPlugins::Parallels::Errors::ExecutionError, tries: 2, sleep: 2) do + execute_prlctl('snapshot-switch', uuid, '-i', snapshot_id) + end end # Resumes the virtual machine.