Add cluster_status action, correct actions.py typo
Closes-Bug: #1716981 Change-Id: I100b4615dfb256f981da636d8e6cab211df59255
This commit is contained in:
parent
b20863b46c
commit
69cc374d11
|
@ -2,3 +2,5 @@ pause:
|
|||
description: Pause the rabbitmq unit.
|
||||
resume:
|
||||
descrpition: Resume the rabbitmq unit.
|
||||
cluster-status:
|
||||
description: Show the current cluster status.
|
|
@ -16,10 +16,18 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
from subprocess import (
|
||||
check_output,
|
||||
CalledProcessError,
|
||||
)
|
||||
|
||||
sys.path.append('hooks/')
|
||||
|
||||
from charmhelpers.core.hookenv import action_fail
|
||||
from charmhelpers.core.hookenv import (
|
||||
action_fail,
|
||||
action_set,
|
||||
)
|
||||
|
||||
from rabbit_utils import (
|
||||
ConfigRenderer,
|
||||
CONFIG_FILES,
|
||||
|
@ -29,21 +37,33 @@ from rabbit_utils import (
|
|||
|
||||
|
||||
def pause(args):
|
||||
"""Pause the Ceilometer services.
|
||||
"""Pause the RabbitMQ services.
|
||||
@raises Exception should the service fail to stop.
|
||||
"""
|
||||
pause_unit_helper(ConfigRenderer(CONFIG_FILES))
|
||||
|
||||
|
||||
def resume(args):
|
||||
"""Resume the Ceilometer services.
|
||||
"""Resume the RabbitMQ services.
|
||||
@raises Exception should the service fail to start."""
|
||||
resume_unit_helper(ConfigRenderer(CONFIG_FILES))
|
||||
|
||||
|
||||
def cluster_status(args):
|
||||
"""Return the output of 'rabbitmqctl cluster_status'."""
|
||||
try:
|
||||
clusterstat = check_output(['rabbitmqctl', 'cluster_status'])
|
||||
action_set({'output': clusterstat})
|
||||
except CalledProcessError as e:
|
||||
action_set({'output': e.output})
|
||||
action_fail('Failed to run rabbitmqctl cluster_status')
|
||||
except Exception:
|
||||
raise
|
||||
|
||||
|
||||
# A dictionary of all the defined actions to callables (which take
|
||||
# parsed arguments).
|
||||
ACTIONS = {"pause": pause, "resume": resume}
|
||||
ACTIONS = {"pause": pause, "resume": resume, "cluster-status": cluster_status}
|
||||
|
||||
|
||||
def main(args):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
actions.py
|
|
@ -706,3 +706,12 @@ class RmqBasicDeployment(OpenStackAmuletDeployment):
|
|||
self.d.sentry.wait(timeout=900)
|
||||
u.rmq_wait_for_cluster(self)
|
||||
u.log.debug('OK')
|
||||
|
||||
def test_911_cluster_status(self):
|
||||
""" rabbitmqctl cluster_status action can be returned. """
|
||||
u.log.debug('Checking cluster status action...')
|
||||
|
||||
action_id = u.run_action(self.rmq0_sentry, "cluster-status")
|
||||
assert u.wait_on_action(action_id), "Cluster status action failed."
|
||||
|
||||
u.log.debug('OK')
|
||||
|
|
|
@ -52,6 +52,29 @@ class ResumeTestCase(CharmTestCase):
|
|||
self.resume_unit_helper.assert_called_once_with('test-config')
|
||||
|
||||
|
||||
class ClusterStatusTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ClusterStatusTestCase, self).setUp(
|
||||
actions, ["check_output", "action_set", "action_fail"])
|
||||
|
||||
def test_cluster_status(self):
|
||||
self.check_output.return_value = 'Cluster status OK'
|
||||
actions.cluster_status([])
|
||||
self.check_output.assert_called_once_with(['rabbitmqctl',
|
||||
'cluster_status'])
|
||||
self.action_set.assert_called()
|
||||
|
||||
def test_cluster_status_execption(self):
|
||||
self.check_output.side_effect = actions.CalledProcessError(1,
|
||||
"Failure")
|
||||
actions.cluster_status([])
|
||||
self.check_output.assert_called_once_with(['rabbitmqctl',
|
||||
'cluster_status'])
|
||||
self.action_set.assert_called()
|
||||
self.action_fail.assert_called()
|
||||
|
||||
|
||||
class MainTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue