From 46ad7af00d78415983b078cec9322f340cc4c465 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Tue, 9 Feb 2021 15:26:16 +0530 Subject: [PATCH] mgr/rook: Add timezone info Recently time zone info was added[1] to various properties like created, started and others in cephadm and changes were made to orchestrator module too. Let's add timezone info to rook as well, which will fix the type error. [1] https://github.com/ceph/ceph/pull/37920 Fixes: https://tracker.ceph.com/issues/49126 Signed-off-by: Varsha Rao (cherry picked from commit d7fac54c2e78d70ba0ecce7231d3e8f6fa84efcd) Conflicts: src/pybind/mgr/rook/module.py src/pybind/mgr/rook/rook_cluster.py --- src/pybind/mgr/rook/module.py | 4 ++-- src/pybind/mgr/rook/rook_cluster.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index 68763eb4ed42f..d8e5ad31b4819 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -1,4 +1,3 @@ -import datetime import threading import functools import os @@ -6,6 +5,7 @@ import json from ceph.deployment import inventory from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, PlacementSpec +from ceph.utils import datetime_now try: from typing import List, Dict, Optional, Callable, Any @@ -255,7 +255,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): @deferred_read def describe_service(self, service_type=None, service_name=None, refresh=False): - now = datetime.datetime.utcnow() + now = datetime_now() # CephCluster cl = self.rook_cluster.rook_api_get( diff --git a/src/pybind/mgr/rook/rook_cluster.py b/src/pybind/mgr/rook/rook_cluster.py index 05c533ae85762..d6b44d5a31fe5 100644 --- a/src/pybind/mgr/rook/rook_cluster.py +++ b/src/pybind/mgr/rook/rook_cluster.py @@ -22,6 +22,7 @@ from urllib3.exceptions import ProtocolError from ceph.deployment.drive_group import DriveGroupSpec from ceph.deployment.service_spec import ServiceSpec +from ceph.utils import datetime_now from mgr_util import merge_dicts try: @@ -315,7 +316,7 @@ class RookCluster(object): return False return True - refreshed = datetime.datetime.utcnow() + refreshed = datetime_now() pods = [i for i in self.rook_pods.items if predicate(i)] pods_summary = [] @@ -341,13 +342,13 @@ class RookCluster(object): 'created': None, } - # note: we want UTC but no tzinfo + # note: we want UTC if d['metadata'].get('creation_timestamp', None): s['created'] = d['metadata']['creation_timestamp'].astimezone( - tz=datetime.timezone.utc).replace(tzinfo=None) + tz=datetime.timezone.utc) if d['status'].get('start_time', None): s['started'] = d['status']['start_time'].astimezone( - tz=datetime.timezone.utc).replace(tzinfo=None) + tz=datetime.timezone.utc) pods_summary.append(s) -- 2.39.5