]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: `stats` might return `--` for containers
authorSebastian Wagner <sewagner@redhat.com>
Mon, 19 Jul 2021 10:13:11 +0000 (12:13 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Wed, 4 Aug 2021 12:56:45 +0000 (14:56 +0200)
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index cd42a32637d2c92e3cbeae853217e09bb772b88a..58eac3677be63c955dd8ff7828fc04a0229713e2 100755 (executable)
@@ -4955,14 +4955,7 @@ def list_daemons(ctx, detail=True, legacy_dir=None):
         [container_path, 'stats', '--format', '{{.ID}},{{.MemUsage}}', '--no-stream'],
         verbosity=CallVerbosity.DEBUG
     )
-    seen_memusage_cid_len = 0
-    if not code:
-        for line in out.splitlines():
-            (cid, usage) = line.split(',')
-            (used, limit) = usage.split(' / ')
-            seen_memusage[cid] = with_units_to_int(used)
-            if not seen_memusage_cid_len:
-                seen_memusage_cid_len = len(cid)
+    seen_memusage_cid_len, seen_memusage = _parse_mem_usage(code, out)
 
     # /var/lib/ceph
     if os.path.exists(data_dir):
@@ -5145,6 +5138,24 @@ def list_daemons(ctx, detail=True, legacy_dir=None):
     return ls
 
 
+def _parse_mem_usage(code: int, out: str) -> Tuple[int, Dict[str, int]]:
+    # keep track of memory usage we've seen
+    seen_memusage = {}  # type: Dict[str, int]
+    seen_memusage_cid_len = 0
+    if not code:
+        for line in out.splitlines():
+            (cid, usage) = line.split(',')
+            (used, limit) = usage.split(' / ')
+            try:
+                seen_memusage[cid] = with_units_to_int(used)
+                if not seen_memusage_cid_len:
+                    seen_memusage_cid_len = len(cid)
+            except ValueError:
+                logger.info('unable to parse memory usage line\n>{}'.format(line))
+                pass
+    return seen_memusage_cid_len, seen_memusage
+
+
 def get_daemon_description(ctx, fsid, name, detail=False, legacy_dir=None):
     # type: (CephadmContext, str, str, bool, Optional[str]) -> Dict[str, str]
 
index 5eeac11fb932ca4c5cae1bbd02bf3ad2abc1faca..4fa0d63d37423bd7ef2a538a5f90d556c51b9f73 100644 (file)
@@ -159,6 +159,11 @@ class TestCephAdm(object):
         args = cd._parse_args(['--image', 'foo', 'version'])
         assert args.image == 'foo'
 
+    def test_parse_mem_usage(self):
+        cd.logger = mock.Mock()
+        len, summary = cd._parse_mem_usage(0, 'c6290e3f1489,-- / --')
+        assert summary == {}
+
     def test_CustomValidation(self):
         assert cd._parse_args(['deploy', '--name', 'mon.a', '--fsid', 'fsid'])