Comment 7 for bug 1630290

Revision history for this message
Nemanja Miletic (nmiletic) wrote :

- OK I have finally managed to install

Replaced "/etc/puppet/liberty-8.0/modules/rabbitmq/lib/puppet/provider/rabbitmqctl.rb" in rabbitmq image with:

class Puppet::Provider::Rabbitmqctl < Puppet::Provider
  initvars
  commands :rabbitmqctl => 'rabbitmqctl'

  def self.rabbitmq_version
    output = rabbitmqctl('-q', 'status')
    version = output.match(/\{rabbit,"RabbitMQ","([\d\.]+)"\}/)
    version[1] if version
  end

  # Retry the given code block 'count' retries or until the
  # command suceeeds. Use 'step' delay between retries.
  # Limit each query time by 'timeout'.
  # For example:
  # users = self.class.run_with_retries { rabbitmqctl 'list_users' }
  def self.run_with_retries(count=30, step=6, timeout=10)
    count.times do |n|
      begin
        output = Timeout::timeout(timeout) do
          yield
        end
      rescue Puppet::ExecutionFailure, Timeout::Error => e
        if e.to_s.include? "already_exists"
          return output
        else
          Puppet.debug "Fail: #{e.to_s} Retry: #{n + 1}"
          sleep step
        end
      else
        Puppet.debug 'Command succeeded'
        return output
      end
    end
    raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!"
  end

end

- Now when executing expires it is retried and succeeds even if object exists. Patch is not nice but worked for me.

/var/log/docker-logs/puppet/rabbitmq.log:

2016-10-06 13:00:53 +0000 Puppet (debug): Executing '/usr/sbin/rabbitmqctl -q list_vhosts'
2016-10-06 13:00:54 +0000 Puppet (debug): Command succeeded
2016-10-06 13:00:54 +0000 Puppet (debug): Executing '/usr/sbin/rabbitmqctl add_vhost /'
2016-10-06 13:01:04 +0000 Puppet (debug): Fail: execution expired Retry: 1
2016-10-06 13:01:10 +0000 Puppet (debug): Executing '/usr/sbin/rabbitmqctl add_vhost /'
2016-10-06 13:01:10 +0000 /Stage[main]/Nailgun::Rabbitmq/Rabbitmq_vhost[/]/ensure (notice): created
2016-10-06 13:01:10 +0000 /Stage[main]/Nailgun::Rabbitmq/Rabbitmq_vhost[/] (debug): The container Class[Nailgun::Rabbitmq] will propagate my refresh event
2016-10-06 13:01:10 +0000 Puppet (debug): Executing '/usr/sbin/rabbitmqctl -q list_user_permissions naily'
2016-10-06 13:01:11 +0000 Puppet (debug): Command succeeded