[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):
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]
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'])