def test_update_clients(self, mock_leader_node_is_ready, mock_client_node_is_ready, mock_amqp_changed): # Not ready mock_client_node_is_ready.return_value = False mock_leader_node_is_ready.return_value = False rabbitmq_server_relations.update_clients() self.assertFalse(mock_amqp_changed.called) # Leader Ready self.relation_ids.return_value = ['amqp:0'] self.related_units.return_value = ['client/0'] mock_leader_node_is_ready.return_value = True mock_client_node_is_ready.return_value = False rabbitmq_server_relations.update_clients() mock_amqp_changed.assert_called_with(relation_id='amqp:0', remote_unit='client/0') # Client Ready self.relation_ids.return_value = ['amqp:0'] self.related_units.return_value = ['client/0'] mock_leader_node_is_ready.return_value = False mock_client_node_is_ready.return_value = True rabbitmq_server_relations.update_clients() mock_amqp_changed.assert_called_with(relation_id='amqp:0', remote_unit='client/0') # Both Ready self.relation_ids.return_value = ['amqp:0'] self.related_units.return_value = ['client/0'] mock_leader_node_is_ready.return_value = True mock_client_node_is_ready.return_value = True rabbitmq_server_relations.update_clients() mock_amqp_changed.assert_called_with(relation_id='amqp:0', remote_unit='client/0')
def _run_deferred_hooks(): """Run supported deferred hooks as needed. Run supported deferred hooks as needed. If support for deferring a new hook is added to the charm then this method will need updating. """ if not deferred_events.is_restart_permitted(): if 'config-changed' in deferred_events.get_deferred_hooks(): log("Running hook config-changed", level=INFO) rabbitmq_server_relations.config_changed( check_deferred_restarts=False) deferred_events.clear_deferred_hook('config-changed') if 'amqp-relation-changed' in deferred_events.get_deferred_hooks(): log("Running hook amqp-relation-changed", level=INFO) # update_clients cycles through amqp relations running # amqp-relation-changed hook. rabbitmq_server_relations.update_clients( check_deferred_restarts=False) deferred_events.clear_deferred_hook('amqp-relation-changed') log("Remaining hooks: {}".format(deferred_events.get_deferred_hooks()), level=INFO)