Merge "Rewrite get_health action with the Operator framework"
This commit is contained in:
commit
4ac36718f3
|
@ -83,20 +83,6 @@ def get_versions_report():
|
||||||
return json.dumps(report, indent=4)
|
return json.dumps(report, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def get_health():
|
|
||||||
"""
|
|
||||||
Returns the output of 'ceph health'.
|
|
||||||
|
|
||||||
On error, 'unknown' is returned.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
value = check_output(['ceph', 'health']).decode('UTF-8')
|
|
||||||
return value
|
|
||||||
except CalledProcessError as e:
|
|
||||||
action_fail(str(e))
|
|
||||||
return 'Getting health failed, health unknown'
|
|
||||||
|
|
||||||
|
|
||||||
def pool_get():
|
def pool_get():
|
||||||
"""
|
"""
|
||||||
Returns a key from a pool using 'ceph osd pool get'.
|
Returns a key from a pool using 'ceph osd pool get'.
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
get_health.py
|
|
|
@ -181,6 +181,8 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
|
||||||
self._observe_action(
|
self._observe_action(
|
||||||
self.on.create_erasure_profile_action,
|
self.on.create_erasure_profile_action,
|
||||||
ops_actions.create_erasure_profile.create_erasure_profile_action)
|
ops_actions.create_erasure_profile.create_erasure_profile_action)
|
||||||
|
self._observe_action(self.on.get_health_action,
|
||||||
|
ops_actions.get_health.get_health_action)
|
||||||
|
|
||||||
fw.observe(self.on.install, self.on_install)
|
fw.observe(self.on.install, self.on_install)
|
||||||
fw.observe(self.on.config_changed, self.on_config)
|
fw.observe(self.on.config_changed, self.on_config)
|
||||||
|
|
|
@ -17,4 +17,5 @@ from . import ( # noqa: F401
|
||||||
copy_pool,
|
copy_pool,
|
||||||
create_crush_rule,
|
create_crush_rule,
|
||||||
create_erasure_profile,
|
create_erasure_profile,
|
||||||
|
get_health,
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,15 +14,18 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from subprocess import CalledProcessError
|
from subprocess import check_output, CalledProcessError
|
||||||
|
import logging
|
||||||
|
|
||||||
from ceph_ops import get_health
|
|
||||||
from charmhelpers.core.hookenv import log, action_set, action_fail
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_health_action(event):
|
||||||
try:
|
try:
|
||||||
action_set({'message': get_health()})
|
event.set_results(
|
||||||
|
{'message': check_output(['ceph', 'health']).decode('UTF-8')})
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
log(e)
|
logger.warning(e)
|
||||||
action_fail(
|
event.fail(
|
||||||
"ceph health failed with message: {}".format(str(e)))
|
"ceph health failed with message: {}".format(str(e)))
|
|
@ -49,11 +49,6 @@ class OpsTestCase(CharmTestCase):
|
||||||
"action_fail",
|
"action_fail",
|
||||||
"open"])
|
"open"])
|
||||||
|
|
||||||
def test_get_health(self):
|
|
||||||
actions.get_health()
|
|
||||||
cmd = ['ceph', 'health']
|
|
||||||
self.check_output.assert_called_once_with(cmd)
|
|
||||||
|
|
||||||
def test_get_version_report_ok(self):
|
def test_get_version_report_ok(self):
|
||||||
def _call_rslt():
|
def _call_rslt():
|
||||||
with open('unit_tests/ceph_ls_node.json') as f:
|
with open('unit_tests/ceph_ls_node.json') as f:
|
||||||
|
|
|
@ -230,3 +230,29 @@ class CreateErasureProfileTestCase(test_utils.CharmTestCase):
|
||||||
coding_chunks=None, helper_chunks=2,
|
coding_chunks=None, helper_chunks=2,
|
||||||
scalar_mds='jerasure', failure_domain='disk', device_class=None
|
scalar_mds='jerasure', failure_domain='disk', device_class=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class GetHealthTestCase(test_utils.CharmTestCase):
|
||||||
|
"""Run tests for action."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.harness = Harness(CephMonCharm)
|
||||||
|
self.harness.begin()
|
||||||
|
self.addCleanup(self.harness.cleanup)
|
||||||
|
|
||||||
|
@mock.patch('ops_actions.get_health.check_output')
|
||||||
|
def test_get_health_action(self, mock_check_output):
|
||||||
|
mock_check_output.return_value = b'yay'
|
||||||
|
event = test_utils.MockActionEvent({})
|
||||||
|
self.harness.charm.on_get_health_action(event)
|
||||||
|
event.set_results.assert_called_once_with(({'message': 'yay'}))
|
||||||
|
|
||||||
|
@mock.patch('ops_actions.get_health.check_output')
|
||||||
|
def test_get_health_action_error(self, mock_check_output):
|
||||||
|
mock_check_output.side_effect = subprocess.CalledProcessError(
|
||||||
|
1, 'test')
|
||||||
|
event = test_utils.MockActionEvent({})
|
||||||
|
self.harness.charm.on_get_health_action(event)
|
||||||
|
event.fail.assert_called_once_with(
|
||||||
|
'ceph health failed with message: '
|
||||||
|
"Command 'test' returned non-zero exit status 1.")
|
||||||
|
|
Loading…
Reference in New Issue