Updates for ceph module regarding info gathering
Related-PROD: PROD-36845
Change-Id: I1903af0c3ff8bc9c7d047c06917fc5bffa733224
diff --git a/cfg_checker/modules/ceph/info.py b/cfg_checker/modules/ceph/info.py
index 0eb1f15..a3006af 100644
--- a/cfg_checker/modules/ceph/info.py
+++ b/cfg_checker/modules/ceph/info.py
@@ -6,7 +6,7 @@
import tarfile
import io
from time import sleep
-
+from datetime import datetime
from cfg_checker.common import logger_cli
from cfg_checker.common.exception import KubeException
@@ -25,6 +25,22 @@
self.env_config = config
return
+ def get_info_archive_filename(self, client, project):
+ # prefill known data
+ _tags = ["CephCollectData"]
+ _tags.append(client)
+ _tags.append(project)
+
+ # generate date for tgz
+ _file_datetime_fmt = "%Y-%m-%d"
+ _dt = datetime.now().strftime(_file_datetime_fmt)
+ _tags.append(_dt)
+
+ # extension
+ _tags.append("tar")
+ _tags.append("gz")
+ return ".".join(_tags)
+
def get_transposed_latency_table(self):
_table = {
"<dev>": []
@@ -164,6 +180,9 @@
self.ceph_info = json.load(_f)
def generate_archive(self, tgzfilename):
+ def _ensure_fname(ext):
+ return key + ext if _fname is None else _fname
+
if not self.ceph_info:
logger_cli.warning(
"WARNING: Ceph Info Data not detected. "
@@ -178,18 +197,23 @@
)
# Iterate every key and write data to tar file
for key, d in self.ceph_info.items():
- _filename = None
+ _fname = None
# Cast buf to a proper type
_buf = None
+ if "filename" in d:
+ _fname = d["filename"]
if isinstance(d["data"], dict) or isinstance(d["data"], list):
_buf = json.dumps(d["data"], indent=2)
- _filename = key + ".json"
+ # _filename = key + ".json" if _fname is not None else _fname
+ _filename = _ensure_fname(".json")
elif isinstance(d["data"], str):
_buf = d["data"]
- _filename = key + ".txt"
+ # _filename = key + ".txt"
+ _filename = _ensure_fname(".txt")
else:
_buf = str(d["data"])
- _filename = key + ".txt"
+ # _filename = key + ".txt"
+ _filename = _ensure_fname(".txt")
logger_cli.debug("... writing '{}'".format(_filename))
_tgz.add_file(_filename, buf=_buf, replace=True)
@@ -332,7 +356,8 @@
logger_cli.debug("... found '{}'".format(_names[0]))
return _names[0]
- def _add_ceph_info_item(self, key, title, data):
+ def _add_ceph_info_item(self, key, title, data, filename=None):
+ # handle data
if key in self.ceph_info:
self.ceph_info[key]["title"] = title
self.ceph_info[key]["data"] = data
@@ -341,6 +366,8 @@
"title": title,
"data": data
}
+ if filename:
+ self.ceph_info[key]["filename"] = filename
def _parse_dev_classes(self, deviceClasses):
_devClasses = []
@@ -439,13 +466,15 @@
self._add_ceph_info_item(
"crushmap_json",
"Crush Map (json)",
- _cj("crushtool -i " + _cmap_tmp_path + " --dump")
+ _cj("crushtool -i " + _cmap_tmp_path + " --dump"),
+ filename="crushmap.json"
)
# _crushmap = _cj("crushtool -i " + _cmap_tmp_path + " --dump")
self._add_ceph_info_item(
"crushmap_text",
"Crush Map (text)",
- _c("crushtool -d " + _cmap_tmp_path)
+ _c("crushtool -d " + _cmap_tmp_path),
+ filename="crushmap.json"
)
logger_cli.info("-> Collecting ceph osd crush dump")