mirror of
https://github.com/ceph/ceph
synced 2025-02-24 19:47:44 +00:00
Merge PR #39173 into master
* refs/pull/39173/head: mgr/devicehealth: make CLI commands error when pool doesn't exist mgr/devicehealth: only create pool when we have some osds Reviewed-by: Kefu Chai <kchai@redhat.com> Reviewed-by: Sunny Kumar <sunkumar@redhat.com> Reviewed-by: Neha Ojha <nojha@redhat.com>
This commit is contained in:
commit
576a89fdaf
@ -131,3 +131,4 @@ vkmc Victoria Martinez de la Cruz <vkmc@redhat.com>
|
||||
gouthampacha Goutham Pacha Ravi <gouthamr@redhat.com>
|
||||
zdover23 Zac Dover <zac.dover@gmail.com>
|
||||
ShyamsundarR Shyamsundar R <srangana@redhat.com>
|
||||
sunnyku Sunny Kumar <sunkumar@redhat.com>
|
||||
|
@ -221,11 +221,28 @@ class Module(MgrModule):
|
||||
self.log.debug(' %s = %s', opt['name'], getattr(self, opt['name']))
|
||||
|
||||
def notify(self, notify_type: str, notify_id: str) -> None:
|
||||
# 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
|
||||
# create device_health_metrics pool if it doesn't exist
|
||||
self.maybe_create_device_pool()
|
||||
|
||||
def have_enough_osds(self) -> bool:
|
||||
# wait until we have enough OSDs to allow the pool to be healthy
|
||||
up = 0
|
||||
for osd in self.get("osd_map")["osds"]:
|
||||
if osd["up"]:
|
||||
up += 1
|
||||
|
||||
need = cast(int, self.get_ceph_option("osd_pool_default_size"))
|
||||
return up >= need
|
||||
|
||||
def maybe_create_device_pool(self) -> bool:
|
||||
if not self.has_device_pool:
|
||||
if not self.have_enough_osds():
|
||||
self.log.warning("Not enough OSDs yet to create monitoring pool")
|
||||
return False
|
||||
self.create_device_pool()
|
||||
self.has_device_pool = True
|
||||
return True
|
||||
|
||||
def create_device_pool(self) -> None:
|
||||
self.log.debug('create %s pool' % self.pool_name)
|
||||
@ -304,23 +321,16 @@ class Module(MgrModule):
|
||||
self.event.set()
|
||||
|
||||
def open_connection(self, create_if_missing: bool = True) -> rados.Ioctx:
|
||||
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:
|
||||
if create_if_missing:
|
||||
if not self.maybe_create_device_pool():
|
||||
return None
|
||||
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: str, daemon_id: str) -> Tuple[int, str, str]:
|
||||
ioctx = self.open_connection()
|
||||
if not ioctx:
|
||||
return 0, "", ""
|
||||
return -errno.EAGAIN, "", "device_health_metrics pool not yet available"
|
||||
raw_smart_data = self.do_scrape_daemon(daemon_type, daemon_id)
|
||||
if raw_smart_data:
|
||||
for device, raw_data in raw_smart_data.items():
|
||||
@ -335,7 +345,7 @@ class Module(MgrModule):
|
||||
assert osdmap is not None
|
||||
ioctx = self.open_connection()
|
||||
if not ioctx:
|
||||
return 0, "", ""
|
||||
return -errno.EAGAIN, "", "device_health_metrics pool not yet available"
|
||||
did_device = {}
|
||||
ids = []
|
||||
for osd in osdmap['osds']:
|
||||
@ -369,7 +379,7 @@ class Module(MgrModule):
|
||||
(daemon_type, daemon_id) = daemons[0].split('.')
|
||||
ioctx = self.open_connection()
|
||||
if not ioctx:
|
||||
return 0, "", ""
|
||||
return -errno.EAGAIN, "", "device_health_metrics pool not yet available"
|
||||
raw_smart_data = self.do_scrape_daemon(daemon_type, daemon_id,
|
||||
devid=devid)
|
||||
if raw_smart_data:
|
||||
|
Loading…
Reference in New Issue
Block a user