# other
self.run = True
self.event = Event()
+ self.has_device_pool = False
def is_valid_daemon_name(self, who):
l = who.split('.')
self.get_module_option(opt['name']))
self.log.debug(' %s = %s', opt['name'], getattr(self, opt['name']))
+ def notify(self, notify_type, notify_id):
+ # create device_health_metrics pool if it doesn't exist
+ if notify_type == "osd_map" and self.enable_monitoring:
+ if not self.has_device_pool:
+ self.create_device_pool()
+ self.has_device_pool = True
+
+ def create_device_pool(self):
+ self.log.debug('create %s pool' % self.pool_name)
+ # create pool
+ result = CommandResult('')
+ self.send_command(result, 'mon', '', json.dumps({
+ 'prefix': 'osd pool create',
+ 'format': 'json',
+ 'pool': self.pool_name,
+ 'pg_num': 1,
+ 'pg_num_min': 1,
+ }), '')
+ r, outb, outs = result.wait()
+ assert r == 0
+ # set pool application
+ result = CommandResult('')
+ self.send_command(result, 'mon', '', json.dumps({
+ 'prefix': 'osd pool application enable',
+ 'format': 'json',
+ 'pool': self.pool_name,
+ 'app': 'mgr_devicehealth',
+ }), '')
+ r, outb, outs = result.wait()
+ assert r == 0
+
def serve(self):
self.log.info("Starting")
self.config_notify()
self.event.set()
def open_connection(self, create_if_missing=True):
- pools = self.rados.list_pools()
- is_pool = False
- for pool in pools:
- if pool == self.pool_name:
- is_pool = True
- break
- if not is_pool:
+ osdmap = self.get("osd_map")
+ assert osdmap is not None
+ if len(osdmap['osds']) == 0:
+ return None
+ if not self.has_device_pool:
if not create_if_missing:
return None
- self.log.debug('create %s pool' % self.pool_name)
- # create pool
- result = CommandResult('')
- self.send_command(result, 'mon', '', json.dumps({
- 'prefix': 'osd pool create',
- 'format': 'json',
- 'pool': self.pool_name,
- 'pg_num': 1,
- 'pg_num_min': 1,
- }), '')
- r, outb, outs = result.wait()
- assert r == 0
-
- # set pool application
- result = CommandResult('')
- self.send_command(result, 'mon', '', json.dumps({
- 'prefix': 'osd pool application enable',
- 'format': 'json',
- 'pool': self.pool_name,
- 'app': 'mgr_devicehealth',
- }), '')
- r, outb, outs = result.wait()
- assert r == 0
-
+ if self.enable_monitoring:
+ self.create_device_pool()
+ self.has_device_pool = True
ioctx = self.rados.open_ioctx(self.pool_name)
return ioctx
def scrape_daemon(self, daemon_type, daemon_id):
ioctx = self.open_connection()
+ if not ioctx:
+ return 0, "", ""
raw_smart_data = self.do_scrape_daemon(daemon_type, daemon_id)
if raw_smart_data:
for device, raw_data in raw_smart_data.items():
osdmap = self.get("osd_map")
assert osdmap is not None
ioctx = self.open_connection()
+ if not ioctx:
+ return 0, "", ""
did_device = {}
ids = []
for osd in osdmap['osds']:
'device ' + devid + ' not claimed by any active daemons')
(daemon_type, daemon_id) = daemons[0].split('.')
ioctx = self.open_connection()
+ if not ioctx:
+ return 0, "", ""
raw_smart_data = self.do_scrape_daemon(daemon_type, daemon_id,
devid=devid)
if raw_smart_data: