From 00881adf55cac6116887bfffc506444473f0ee82 Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Thu, 23 Apr 2020 18:09:15 +0800 Subject: [PATCH] mgr/dashboard: fixing RBD purge error in backend Current UTC datetime should be used as `now`, otherwise the expiration comparison might fail on machines with non-UTC localtime. Fixes: https://tracker.ceph.com/issues/45149 Signed-off-by: Kiefer Chang --- src/pybind/mgr/dashboard/controllers/rbd.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 6bfff994d223..ec959949381f 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -3,6 +3,7 @@ # pylint: disable=too-many-statements,too-many-branches from __future__ import absolute_import +import logging import math from functools import partial from datetime import datetime @@ -21,6 +22,8 @@ from ..tools import ViewCache, str_to_bool from ..services.exception import handle_rados_error, handle_rbd_error, \ serialize_dashboard_exception +logger = logging.getLogger(__name__) + # pylint: disable=not-callable def RbdTask(name, metadata, wait_for): # noqa: N802 @@ -363,12 +366,14 @@ class RbdTrash(RESTController): @DeletePermission def purge(self, pool_name=None): """Remove all expired images from trash.""" - now = "{}Z".format(datetime.now().isoformat()) + now = "{}Z".format(datetime.utcnow().isoformat()) pools = self._trash_list(pool_name) for pool in pools: for image in pool['value']: if image['deferment_end_time'] < now: + logger.info('Removing trash image %s (pool=%s, namespace=%s, name=%s)', + image['id'], pool['pool_name'], image['namespace'], image['name']) rbd_call(pool['pool_name'], image['namespace'], self.rbd_inst.trash_remove, image['id'], 0) -- 2.47.3