check_container_engine,
find_container_engine,
normalize_container_id,
+ parsed_container_image_list,
parsed_container_mem_usage,
pull_command,
registry_login,
:return: The most recent local ceph image (already pulled)
"""
- # '|' special character is used to separate the output fields into:
- # - Repository@digest
- # - Image Id
- # - Image Tag
- # - Image creation date
- out, _, _ = call_throws(ctx,
- [container_path, 'images',
- '--filter', 'label=ceph=True',
- '--filter', 'dangling=false',
- '--format', '{{.Repository}}@{{.Digest}}|{{.ID}}|{{.Tag}}|{{.CreatedAt}}'])
+ images = parsed_container_image_list(
+ ctx,
+ filters=['dangling=false', 'label=ceph=True'],
+ container_path=container_path,
+ )
container_info = None
daemon_name = ctx.name if ('name' in ctx and ctx.name and '.' in ctx.name) else None
logger.debug(f"Using container info for daemon '{daemon}'")
break
- for image in out.splitlines():
- if image and not image.isspace():
- (digest, image_id, tag, created_date) = image.lstrip().split('|')
- if container_info is not None and image_id not in container_info.image_id:
- continue
- if digest and not digest.endswith('@'):
- logger.info(f"Using ceph image with id '{image_id}' and tag '{tag}' created on {created_date}\n{digest}")
- return digest
+ for image in images:
+ if container_info is not None and image.image_id not in container_info.image_id:
+ continue
+ if image.digest:
+ logger.info(f"Using ceph image with id '{image.image_id}' and tag '{image.tag}' created on {image.created}\n{image.name}")
+ return image.name
if container_info is not None:
logger.warning(f"Not using image '{container_info.image_id}' as it's not in list of non-dangling images with ceph=True label")
return None
<none>@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29|1b58ca4f6dfd|<none>|2025-01-16 22:53:46 +0000 UTC
'''
),
- 'expected': '<none>@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29', # YIKES!
+ 'expected': '1b58ca4f6dfd', # YIKES!
},
],
)
- @mock.patch('os.listdir', return_value=[])
- @mock.patch('cephadm.logger')
- def test_infer_local_ceph_image(self, _logger, _listdir, params):
+ def test_infer_local_ceph_image(self, params, funkypatch):
ctx = _cephadm.CephadmContext()
ctx.fsid = '00000000-0000-0000-0000-0000deadbeez'
ctx.container_engine = mock_podman()
cinfo = params.get('container_info', None)
out = params.get('images_output', '')
expected = params.get('expected', None)
- with mock.patch('cephadm.call_throws', return_value=(out, '', '')):
- with mock.patch('cephadm.get_container_info', return_value=cinfo):
- image = _cephadm.infer_local_ceph_image(
- ctx, ctx.container_engine
- )
- assert image == expected
+ funkypatch.patch('cephadmlib.call_wrappers.call').return_value = out, '', 0
+ funkypatch.patch('cephadm.get_container_info').return_value = cinfo
+ image = _cephadm.infer_local_ceph_image(
+ ctx, ctx.container_engine
+ )
+ assert image == expected
@pytest.mark.parametrize('daemon_filter, by_name, daemon_list, container_stats, output',
[