Class: Puppet::Provider::RabbitmqCli

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/rabbitmq_cli.rb

Class Method Summary collapse

Class Method Details

.home_tmp_command(name, path) ⇒ Object



28
29
30
31
32
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 28

def self.home_tmp_command(name, path)
  has_command name, path do
    environment HOME: '/tmp', LC_ALL: 'en_US.UTF-8'
  end
end

.rabbitmq_runningObject



67
68
69
70
71
72
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 67

def self.rabbitmq_running
  rabbitmqctl('-q', 'status')
  true
rescue Puppet::ExecutionFailure, Timeout::Error
  false
end

.rabbitmq_versionObject



39
40
41
42
43
44
45
46
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 39

def self.rabbitmq_version
  return @rabbitmq_version if defined? @rabbitmq_version

  output = rabbitmqctl('-q', 'status')
  version = output.match(%r{RabbitMQ.*?([\d.]+)})
  @rabbitmq_version = version[1] if version
  @rabbitmq_version
end

.rabbitmqctl_list(resource, *opts) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 48

def self.rabbitmqctl_list(resource, *opts)
  version = rabbitmq_version
  list_opts =
    if version && Puppet::Util::Package.versioncmp(version, '3.7.9') >= 0
      ['-q', '--no-table-headers']
    else
      ['-q']
    end
  rabbitmqctl("list_#{resource}", *list_opts, *opts)
rescue Puppet::MissingCommand
  # rabbitmqctl is not present. Normally we would have installed a package
  # that provides rabbitmqctl by now, but if we're running under --noop or
  # with a restrictive set of tags, the package may not have been installed.
  # Return an empty string to avoid error. This may give false positives for
  # resources under --noop!
  Puppet.debug('rabbitmqctl command not found; assuming rabbitmq is not installed')
  ''
end

.run_with_retries(count = 30, step = 6, timeout = 10, &block) ⇒ Object

Retry the given code block ‘count’ retries or until the command succeeds. Use ‘step’ delay between retries. Limit each query time by ‘timeout’. For example:

users = self.class.run_with_retries { rabbitmqctl 'list_users' }

Raises:

  • (Puppet::Error)


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 79

def self.run_with_retries(count = 30, step = 6, timeout = 10, &block)
  count.times do |_n|
    output = Timeout.timeout(timeout, &block)
  rescue Puppet::ExecutionFailure, Timeout::Error
    Puppet.debug 'Command failed, retrying'
    sleep step
  else
    Puppet.debug 'Command succeeded'
    return output
  end
  raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!"
end