Sha256: 0ee72959571936445fe35c8a47cb6b8070a1251a7ae7f305b8c5d0943db9aa28

Contents?: true

Size: 1.82 KB

Versions: 9

Compression:

Stored size: 1.82 KB

Contents

require 'timeout'
require "log4r"

module VagrantPlugins
  module Skytap
    module Action
      # Extends the builtin WaitForCommunicator action to retry on
      # "network unreachable" errors, which can sometimes occur when
      # a Skytap environment is started.
      class WaitForCommunicator < Vagrant::Action::Builtin::WaitForCommunicator

        def initialize(app, env, states=nil)
          super
          @logger = Log4r::Logger.new("vagrant_skytap::action::wait_for_communicator")
        end

        alias_method :builtin_action_call, :call

        def call(env)
          # The SSH communicator handles certain exceptions by raising a
          # corresponding VagrantError which can be handled gracefully,
          # i.e. by the #wait_for_ready method, which continues to retry
          # until the boot_timeout expires.
          #
          # The communicator does a limited number of retries for
          # Errno::ENETUNREACH, but then allows the exception to bubble up
          # to the user. Here we swallow this exception and essentially
          # retry the original WaitForCommunicator action.
          begin
            Timeout.timeout(env[:machine].config.vm.boot_timeout) do
              while true do
                begin
                  # TODO Is there a clean way to just invoke the built-in action?
                  break builtin_action_call(env)
                rescue Errno::ENETUNREACH
                  @logger.info("Rescued Errno::ENETUNREACH and retrying original WaitForCommunicator action.")
                  env[:ui].detail("Warning: The network was unreachable. Retrying...")
                end
                return if env[:interrupted]
              end
            end
          rescue Timeout::Error
            raise Vagrant::Errors::VMBootTimeout
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vagrant-skytap-0.2.3 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.2.2 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.2.1 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.2.0 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.1.11 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.1.10 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.1.9 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.1.8 lib/vagrant-skytap/action/wait_for_communicator.rb
vagrant-skytap-0.1.7 lib/vagrant-skytap/action/wait_for_communicator.rb