for daemon in daemons:
svc_type, svc_id = daemon.split('.')
- try:
- dev_smart_data = CephService.send_command(
- svc_type, 'smart', svc_id, devid=device['devid'])
- except SendCommandError:
- # Try to retrieve SMART data from another daemon.
- continue
+ if 'osd' in svc_type:
+ try:
+ dev_smart_data = CephService.send_command(
+ svc_type, 'smart', svc_id, devid=device['devid'])
+ except SendCommandError:
+ # Try to retrieve SMART data from another daemon.
+ continue
+ else:
+ try:
+ dev_smart_data = CephService.send_command(
+ svc_type, 'device get-health-metrics', svc_id, devid=device['devid'])
+ except SendCommandError:
+ # Try to retrieve SMART data from another daemon.
+ continue
for dev_id, dev_data in dev_smart_data.items():
if 'error' in dev_data:
logger.warning(
CephService._get_smart_data_by_device.assert_not_called()
assert smart_data == {}
assert log in caplog.text
+
+
+@mock.patch.object(CephService, 'send_command')
+def test_get_smart_data_from_appropriate_ceph_command(send_command):
+ # pylint: disable=protected-access
+ send_command.side_effect = [
+ {'nodes': [{'name': 'osd.1', 'status': 'up'}, {'name': 'mon.1', 'status': 'down'}]},
+ {'fake': {'device': {'name': '/dev/sda'}}}
+ ]
+ CephService._get_smart_data_by_device({'devid': '1', 'daemons': ['osd.1', 'mon.1']})
+ send_command.assert_has_calls([mock.call('mon', 'osd tree'),
+ mock.call('osd', 'smart', '1', devid='1')])
+
+ send_command.side_effect = [
+ {'nodes': [{'name': 'osd.1', 'status': 'down'}, {'name': 'mon.1', 'status': 'up'}]},
+ {'fake': {'device': {'name': '/dev/sda'}}}
+ ]
+ CephService._get_smart_data_by_device({'devid': '1', 'daemons': ['osd.1', 'mon.1']})
+ send_command.assert_has_calls([mock.call('mon', 'osd tree'),
+ mock.call('mon', 'device get-health-metrics', '1', devid='1')])