Module: Pacemaker::Wait

Overview

functions that can wait for something repeatedly polling the system status until the condition is met

Instance Method Summary collapse

Instance Method Details

#online?TrueClass, FalseClass

check if pacemaker is online and we can work with it

  • pacemaker is online if cib can be downloaded

  • dc_version attribute can be obtained

  • DC have been designated

Times out a stuck command calls and catches failed command calls

Returns:

  • (TrueClass, FalseClass)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/pacemaker/wait.rb', line 223

def online?
  Timeout.timeout(pacemaker_options[:retry_timeout]) do
    return false unless dc_version
    return false unless dc
    return false unless cib_section_node_state
    true
  end
rescue Puppet::ExecutionFailure => e
  debug "Cluster is offline: #{e.message}"
  false
rescue Timeout::Error
  debug 'Online check timeout!'
  false
end

#retry_block(options = {}) ⇒ Object

retry the given command until it runs without errors or for RETRY_COUNT times with RETRY_STEP sec step print cluster status report on fail

Parameters:

  • options (Hash) (defaults to: {})


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pacemaker/wait.rb', line 9

def retry_block(options = {})
  options = pacemaker_options.merge options

  options[:retry_count].times do
    begin
      out = Timeout.timeout(options[:retry_timeout]) { yield }
      if options[:retry_false_is_failure]
        return out if out
      else
        return out
      end
    rescue => e
      debug "Execution failure: #{e.message}"
    end
    sleep options[:retry_step]
  end
  raise "Execution timeout after #{options[:retry_count] * options[:retry_step]} seconds!" if options[:retry_fail_on_timeout]
end

#wait_for_constraint_create(xml, constraint, scope = 'constraints') ⇒ Object

add a new constraint to CIB and wait for it to be actually created

Parameters:

  • xml (String, REXML::Element)

    XML block to add

  • constraint (String)

    the id of the new constraint

  • scope (String) (defaults to: 'constraints')

    XML root scope



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/pacemaker/wait.rb', line 168

def wait_for_constraint_create(xml, constraint, scope = 'constraints')
  message = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be created"
  debug message
  retry_block do
    if pacemaker_options[:cibadmin_idempotency_checks]
      cib_reset 'wait_for_constraint_create'
      break true if constraint_exists? constraint
    end
    cibadmin_create xml, scope
  end
  message = "Constraint '#{constraint}' was created"
  debug message
end

#wait_for_constraint_remove(xml, constraint, scope = 'constraints') ⇒ Object

remove a constraint from CIB and wait for it to be actually removed

Parameters:

  • xml (String, REXML::Element)

    XML block to remove

  • constraint (String)

    the id of the removed constraint

  • scope (String) (defaults to: 'constraints')

    XML root scope



187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/pacemaker/wait.rb', line 187

def wait_for_constraint_remove(xml, constraint, scope = 'constraints')
  message = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be removed"
  debug message
  retry_block do
    if pacemaker_options[:cibadmin_idempotency_checks]
      cib_reset 'wait_for_constraint_remove'
      break true unless constraint_exists? constraint
    end
    cibadmin_delete xml, scope
  end
  message = "Constraint '#{constraint}' was removed"
  debug message
end

#wait_for_constraint_update(xml, constraint, scope = 'constraints') ⇒ Object

update a constraint in CIB and wait for it to be actually updated

Parameters:

  • xml (String, REXML::Element)

    XML block to update

  • constraint (String)

    the id of the updated constraint

  • scope (String) (defaults to: 'constraints')

    XML root scope



206
207
208
209
210
211
212
213
214
215
# File 'lib/pacemaker/wait.rb', line 206

def wait_for_constraint_update(xml, constraint, scope = 'constraints')
  message = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be updated"
  debug message
  retry_block do
    # replace action is already idempotent
    cibadmin_replace xml, scope
  end
  message = "Constraint '#{constraint}' was updated"
  debug message
end

#wait_for_master(primitive, node = nil) ⇒ Object

wait for primitive to start as a master if node is given then start as a master on this node

Parameters:

  • primitive (String)

    primitive id

  • node (String) (defaults to: nil)

    on this node if given



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pacemaker/wait.rb', line 78

def wait_for_master(primitive, node = nil)
  message = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to start master"
  message += " on node '#{node}'" if node
  debug message
  retry_block do
    cib_reset 'wait_for_master'
    primitive_has_master_running? primitive, node
  end
  message = "Service '#{primitive}' have started master"
  message += " on node '#{node}'" if node
  debug message
end

#wait_for_online(comment = nil) ⇒ Object

wait for pacemaker to become online

Parameters:

  • comment (String) (defaults to: nil)

    log tag comment to trace calls



30
31
32
33
34
35
36
37
38
39
# File 'lib/pacemaker/wait.rb', line 30

def wait_for_online(comment = nil)
  message = "Waiting #{max_wait_time} seconds for Pacemaker to become online"
  message += " (#{comment})" if comment
  debug message
  retry_block do
    cib_reset 'wait_for_online'
    online?
  end
  debug 'Pacemaker is online'
end

#wait_for_primitive_create(xml, primitive, scope = 'resources') ⇒ Object

add a new primitive to CIB and wait for it to be actually created

Parameters:

  • xml (String, REXML::Element)

    XML block to add

  • primitive (String)

    the id of the new primitive

  • scope (String) (defaults to: 'resources')

    XML root scope



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/pacemaker/wait.rb', line 114

def wait_for_primitive_create(xml, primitive, scope = 'resources')
  message = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be created"
  debug message
  retry_block do
    if pacemaker_options[:cibadmin_idempotency_checks]
      cib_reset 'wait_for_primitive_create'
      break true if primitive_exists? primitive
    end
    cibadmin_create xml, scope
  end
  message = "Primitive '#{primitive}' was created"
  debug message
end

#wait_for_primitive_remove(xml, primitive, scope = 'resources') ⇒ Object

remove a primitive from CIB and wait for it to be actually removed

Parameters:

  • xml (String, REXML::Element)

    XML block to remove

  • primitive (String)

    the id of the removed primitive

  • scope (String) (defaults to: 'resources')

    XML root scope



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/pacemaker/wait.rb', line 133

def wait_for_primitive_remove(xml, primitive, scope = 'resources')
  message = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be removed"
  debug message
  retry_block do
    if pacemaker_options[:cibadmin_idempotency_checks]
      cib_reset 'wait_for_primitive_remove'
      break true unless primitive_exists? primitive
    end
    cibadmin_delete xml, scope
  end
  message = "Primitive '#{primitive}' was removed"
  debug message
end

#wait_for_primitive_update(xml, primitive, scope = 'resources') ⇒ Object

update a primitive in CIB and wait for it to be actually updated

Parameters:

  • xml (String, REXML::Element)

    XML block to update

  • primitive (String)

    the id of the updated primitive

  • scope (String) (defaults to: 'resources')

    XML root scope



152
153
154
155
156
157
158
159
160
161
# File 'lib/pacemaker/wait.rb', line 152

def wait_for_primitive_update(xml, primitive, scope = 'resources')
  message = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be updated"
  debug message
  retry_block do
    # replace action is already idempotent
    cibadmin_replace xml, scope
  end
  message = "Primitive '#{primitive}' was updated"
  debug message
end

#wait_for_start(primitive, node = nil) ⇒ Object

wait for primitive to start if node is given then start on this node

Parameters:

  • primitive (String)

    primitive id

  • node (String) (defaults to: nil)

    on this node if given



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pacemaker/wait.rb', line 61

def wait_for_start(primitive, node = nil)
  message = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to start"
  message += " on node '#{node}'" if node
  debug message
  retry_block do
    cib_reset 'wait_for_start'
    primitive_is_running? primitive, node
  end
  message = "Service '#{primitive}' have started"
  message += " on node '#{node}'" if node
  debug message
end

#wait_for_status(primitive, node = nil) ⇒ Object

wait until a primitive has known status

Parameters:

  • primitive (String)

    primitive name

  • node (String) (defaults to: nil)

    on this node if given



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pacemaker/wait.rb', line 44

def wait_for_status(primitive, node = nil)
  message = "Waiting #{max_wait_time} seconds for a known status of '#{primitive}'"
  message += " on node '#{node}'" if node
  debug message
  retry_block do
    cib_reset 'wait_for_status'
    !primitive_status(primitive).nil?
  end
  message = "Primitive '#{primitive}' has status '#{primitive_status primitive}'"
  message += " on node '#{node}'" if node
  debug message
end

#wait_for_stop(primitive, node = nil) ⇒ Object

wait for primitive to stop if node is given then start on this node

Parameters:

  • primitive (String)

    primitive id

  • node (String) (defaults to: nil)

    on this node if given



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/pacemaker/wait.rb', line 95

def wait_for_stop(primitive, node = nil)
  message = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to stop"
  message += " on node '#{node}'" if node
  debug message
  retry_block do
    cib_reset 'wait_for_stop'
    result = primitive_is_running? primitive, node
    result.is_a? FalseClass
  end
  message = "Service '#{primitive}' was stopped"
  message += " on node '#{node}'" if node
  debug message
end