Module: Pacemaker::Wait
- Included in:
- Puppet::Provider::PacemakerPCS, Puppet::Provider::PacemakerXML, Serverspec::Type::PacemakerXML
- Defined in:
- lib/pacemaker/wait.rb
Overview
functions that can wait for something repeatedly polling the system status until the condition is met
Instance Method Summary collapse
-
#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.
-
#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.
-
#wait_for_constraint_create(xml, constraint, scope = 'constraints') ⇒ Object
add a new constraint to CIB and wait for it to be actually created.
-
#wait_for_constraint_remove(xml, constraint, scope = 'constraints') ⇒ Object
remove a constraint from CIB and wait for it to be actually removed.
-
#wait_for_constraint_update(xml, constraint, scope = 'constraints') ⇒ Object
update a constraint in CIB and wait for it to be actually updated.
-
#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.
-
#wait_for_online(comment = nil) ⇒ Object
wait for pacemaker to become online.
-
#wait_for_primitive_create(xml, primitive, scope = 'resources') ⇒ Object
add a new primitive to CIB and wait for it to be actually created.
-
#wait_for_primitive_remove(xml, primitive, scope = 'resources') ⇒ Object
remove a primitive from CIB and wait for it to be actually removed.
-
#wait_for_primitive_update(xml, primitive, scope = 'resources') ⇒ Object
update a primitive in CIB and wait for it to be actually updated.
-
#wait_for_start(primitive, node = nil) ⇒ Object
wait for primitive to start if node is given then start on this node.
-
#wait_for_status(primitive, node = nil) ⇒ Object
wait until a primitive has known status.
-
#wait_for_stop(primitive, node = nil) ⇒ Object
wait for primitive to stop if node is given then start on this node.
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
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([: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.}" 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
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( = {}) = .merge [:retry_count].times do begin out = Timeout.timeout([:retry_timeout]) { yield } if [:retry_false_is_failure] return out if out else return out end rescue => e debug "Execution failure: #{e.}" end sleep [:retry_step] end raise "Execution timeout after #{[:retry_count] * [:retry_step]} seconds!" if [: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
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') = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be created" debug retry_block do if [:cibadmin_idempotency_checks] cib_reset 'wait_for_constraint_create' break true if constraint_exists? constraint end cibadmin_create xml, scope end = "Constraint '#{constraint}' was created" debug end |
#wait_for_constraint_remove(xml, constraint, scope = 'constraints') ⇒ Object
remove a constraint from CIB and wait for it to be actually removed
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') = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be removed" debug retry_block do if [:cibadmin_idempotency_checks] cib_reset 'wait_for_constraint_remove' break true unless constraint_exists? constraint end cibadmin_delete xml, scope end = "Constraint '#{constraint}' was removed" debug end |
#wait_for_constraint_update(xml, constraint, scope = 'constraints') ⇒ Object
update a constraint in CIB and wait for it to be actually updated
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') = "Waiting #{max_wait_time} seconds for the constraint '#{constraint}' to be updated" debug retry_block do # replace action is already idempotent cibadmin_replace xml, scope end = "Constraint '#{constraint}' was updated" debug 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
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) = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to start master" += " on node '#{node}'" if node debug retry_block do cib_reset 'wait_for_master' primitive_has_master_running? primitive, node end = "Service '#{primitive}' have started master" += " on node '#{node}'" if node debug end |
#wait_for_online(comment = nil) ⇒ Object
wait for pacemaker to become online
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pacemaker/wait.rb', line 30 def wait_for_online(comment = nil) = "Waiting #{max_wait_time} seconds for Pacemaker to become online" += " (#{comment})" if comment debug 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
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') = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be created" debug retry_block do if [:cibadmin_idempotency_checks] cib_reset 'wait_for_primitive_create' break true if primitive_exists? primitive end cibadmin_create xml, scope end = "Primitive '#{primitive}' was created" debug end |
#wait_for_primitive_remove(xml, primitive, scope = 'resources') ⇒ Object
remove a primitive from CIB and wait for it to be actually removed
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') = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be removed" debug retry_block do if [:cibadmin_idempotency_checks] cib_reset 'wait_for_primitive_remove' break true unless primitive_exists? primitive end cibadmin_delete xml, scope end = "Primitive '#{primitive}' was removed" debug end |
#wait_for_primitive_update(xml, primitive, scope = 'resources') ⇒ Object
update a primitive in CIB and wait for it to be actually updated
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') = "Waiting #{max_wait_time} seconds for the primitive '#{primitive}' to be updated" debug retry_block do # replace action is already idempotent cibadmin_replace xml, scope end = "Primitive '#{primitive}' was updated" debug end |
#wait_for_start(primitive, node = nil) ⇒ Object
wait for primitive to start if node is given then start on this node
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) = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to start" += " on node '#{node}'" if node debug retry_block do cib_reset 'wait_for_start' primitive_is_running? primitive, node end = "Service '#{primitive}' have started" += " on node '#{node}'" if node debug end |
#wait_for_status(primitive, node = nil) ⇒ Object
wait until a primitive has known status
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) = "Waiting #{max_wait_time} seconds for a known status of '#{primitive}'" += " on node '#{node}'" if node debug retry_block do cib_reset 'wait_for_status' !primitive_status(primitive).nil? end = "Primitive '#{primitive}' has status '#{primitive_status primitive}'" += " on node '#{node}'" if node debug end |
#wait_for_stop(primitive, node = nil) ⇒ Object
wait for primitive to stop if node is given then start on this node
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) = "Waiting #{max_wait_time} seconds for the service '#{primitive}' to stop" += " on node '#{node}'" if node debug retry_block do cib_reset 'wait_for_stop' result = primitive_is_running? primitive, node result.is_a? FalseClass end = "Service '#{primitive}' was stopped" += " on node '#{node}'" if node debug end |