Podman,
check_container_engine,
find_container_engine,
+ parsed_container_mem_usage,
pull_command,
registry_login,
)
normalize_image_digest,
try_convert_datetime,
read_config,
- with_units_to_int,
_extract_host_info_from_applied_spec,
)
from cephadmlib.file_utils import (
daemons: Dict[str, Dict[str, Any]] = {}
data_dir = self.ctx.data_dir
seen_memusage = {} # type: Dict[str, int]
- out, err, code = call(
- self.ctx,
- [self.ctx.container_engine.path, 'stats', '--format', '{{.ID}},{{.MemUsage}}', '--no-stream'],
- verbosity=CallVerbosity.DEBUG
- )
- seen_memusage_cid_len, seen_memusage = _parse_mem_usage(code, out)
+ seen_memusage_cid_len, seen_memusage = parsed_container_mem_usage(self.ctx)
# we need a mapping from container names to ids. Later we will convert daemon
# names to container names to get daemons container id to see if it has changed
out, err, code = call(
# keep track of memory and cpu usage we've seen
seen_memusage = {} # type: Dict[str, int]
seen_cpuperc = {} # type: Dict[str, str]
- out, err, code = call(
- ctx,
- [container_path, 'stats', '--format', '{{.ID}},{{.MemUsage}}', '--no-stream'],
- verbosity=CallVerbosity.QUIET
- )
- seen_memusage_cid_len, seen_memusage = _parse_mem_usage(code, out)
+ seen_memusage_cid_len, seen_memusage = parsed_container_mem_usage(ctx)
out, err, code = call(
ctx,
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 _parse_cpu_perc(code: int, out: str) -> Tuple[int, Dict[str, str]]:
seen_cpuperc = {}
seen_cpuperc_cid_len = 0
@mock.patch('cephadm.logger')
def test_parse_mem_usage(self, _logger):
- len, summary = _cephadm._parse_mem_usage(0, 'c6290e3f1489,-- / --')
+ from cephadmlib.container_engines import _parse_mem_usage
+
+ len, summary = _parse_mem_usage(0, 'c6290e3f1489,-- / --')
assert summary == {}
def test_CustomValidation(self):
class TestShell(object):
- def test_fsid(self, cephadm_fs):
+ def test_fsid(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
fsid = '00000000-0000-0000-0000-0000deadbeef'
cmd = ['shell', '--fsid', fsid]
assert retval == 1
assert ctx.fsid == None
- def test_name(self, cephadm_fs):
+ def test_name(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell', '--name', 'foo']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
retval = _cephadm.command_shell(ctx)
assert retval == 0
- def test_config(self, cephadm_fs):
+ def test_config(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
assert retval == 0
assert ctx.config == 'foo'
- def test_keyring(self, cephadm_fs):
+ def test_keyring(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
assert retval == 0
assert ctx.keyring == 'foo'
- @mock.patch('cephadm.CephContainer')
- def test_mount_no_dst(self, _ceph_container, cephadm_fs):
+ def test_mount_no_dst(self, cephadm_fs, funkypatch):
+ _ceph_container = funkypatch.patch('cephadm.CephContainer')
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell', '--mount', '/etc/foo']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
assert retval == 0
assert _ceph_container.call_args.kwargs['volume_mounts']['/etc/foo'] == '/mnt/foo'
- @mock.patch('cephadm.CephContainer')
- def test_mount_with_dst_no_opt(self, _ceph_container, cephadm_fs):
+ def test_mount_with_dst_no_opt(self, cephadm_fs, funkypatch):
+ _ceph_container = funkypatch.patch('cephadm.CephContainer')
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell', '--mount', '/etc/foo:/opt/foo/bar']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
assert retval == 0
assert _ceph_container.call_args.kwargs['volume_mounts']['/etc/foo'] == '/opt/foo/bar'
- @mock.patch('cephadm.CephContainer')
- def test_mount_with_dst_and_opt(self, _ceph_container, cephadm_fs):
+ def test_mount_with_dst_and_opt(self, cephadm_fs, funkypatch):
+ _ceph_container = funkypatch.patch('cephadm.CephContainer')
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = ['shell', '--mount', '/etc/foo:/opt/foo/bar:Z']
with with_cephadm_ctx(cmd) as ctx:
retval = _cephadm.command_shell(ctx)
'--', 'inventory', '--format', 'json'
]
- def test_noop(self, cephadm_fs):
+ def test_noop(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = self._get_cmd()
with with_cephadm_ctx(cmd) as ctx:
_cephadm.command_ceph_volume(ctx)
assert ctx.keyring == None
assert ctx.config_json == None
- def test_fsid(self, cephadm_fs):
+ def test_fsid(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
fsid = '00000000-0000-0000-0000-0000deadbeef'
cmd = self._get_cmd('--fsid', fsid)
_cephadm.command_ceph_volume(ctx)
assert ctx.fsid == None
- def test_config(self, cephadm_fs):
+ def test_config(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = self._get_cmd('--config', 'foo')
with with_cephadm_ctx(cmd) as ctx:
err = r'No such file or directory'
_cephadm.command_ceph_volume(ctx)
assert ctx.config == 'bar'
- def test_keyring(self, cephadm_fs):
+ def test_keyring(self, cephadm_fs, funkypatch):
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
+ _call.side_effect = lambda *args, **kwargs: ('', '', 0)
+
cmd = self._get_cmd('--keyring', 'foo')
with with_cephadm_ctx(cmd) as ctx:
err = r'No such file or directory'
funkypatch.patch('cephadm.logger')
_giifi = funkypatch.patch('cephadm.get_image_info_from_inspect')
_giifi.return_value = {}
- _call = funkypatch.patch('cephadmlib.call_wrappers.call')
+ _call = funkypatch.patch('cephadmlib.call_wrappers.call', force=True)
ctx = _cephadm.CephadmContext()
ctx.container_engine = mock_podman()
ctx.insecure = False