Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mgr/cephadm: normalize_image_digest: reworked
Reworked to only care about known short names. I coudn't
find any algorithm, as this problem is ambiguous.

Fixes: https://tracker.ceph.com/issues/53594

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
(cherry picked from commit a48b834)
  • Loading branch information
sebastian-philipp authored and adk3798 committed Feb 21, 2022
1 parent 9771daa commit 9271e72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/pybind/mgr/cephadm/tests/test_upgrade.py
Expand Up @@ -17,19 +17,19 @@ def test_upgrade_start(cephadm_module: CephadmOrchestrator):
with with_host(cephadm_module, 'test2'):
with with_service(cephadm_module, ServiceSpec('mgr', placement=PlacementSpec(count=2)), status_running=True):
assert wait(cephadm_module, cephadm_module.upgrade_start(
'image_id', None)) == 'Initiating upgrade to docker.io/image_id'
'image_id', None)) == 'Initiating upgrade to image_id'

assert wait(cephadm_module, cephadm_module.upgrade_status()
).target_image == 'docker.io/image_id'
).target_image == 'image_id'

assert wait(cephadm_module, cephadm_module.upgrade_pause()
) == 'Paused upgrade to docker.io/image_id'
) == 'Paused upgrade to image_id'

assert wait(cephadm_module, cephadm_module.upgrade_resume()
) == 'Resumed upgrade to docker.io/image_id'
) == 'Resumed upgrade to image_id'

assert wait(cephadm_module, cephadm_module.upgrade_stop()
) == 'Stopped upgrade to docker.io/image_id'
) == 'Stopped upgrade to image_id'


@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
Expand Down Expand Up @@ -57,10 +57,10 @@ def test_upgrade_run(use_repo_digest, cephadm_module: CephadmOrchestrator):
}):
version_mock.return_value = 'ceph version 18.2.1 (somehash)'
assert wait(cephadm_module, cephadm_module.upgrade_start(
'to_image', None)) == 'Initiating upgrade to docker.io/to_image'
'to_image', None)) == 'Initiating upgrade to to_image'

assert wait(cephadm_module, cephadm_module.upgrade_status()
).target_image == 'docker.io/to_image'
).target_image == 'to_image'

def _versions_mock(cmd):
return json.dumps({
Expand Down Expand Up @@ -113,7 +113,7 @@ def _versions_mock(cmd):
if use_repo_digest:
assert image == 'to_image@repo_digest'
else:
assert image == 'docker.io/to_image'
assert image == 'to_image'


def test_upgrade_state_null(cephadm_module: CephadmOrchestrator):
Expand Down
18 changes: 11 additions & 7 deletions src/pybind/mgr/cephadm/upgrade.py
Expand Up @@ -27,20 +27,24 @@ def normalize_image_digest(digest: str, default_registry: str) -> str:
>>> normalize_image_digest('ceph/ceph', 'docker.io')
'docker.io/ceph/ceph'
Edge cases that shouldn't ever come up. (ubuntu alias for library/ubuntu)
>>> normalize_image_digest('ubuntu', 'docker.io')
'docker.io/ubuntu'
No change:
>>> normalize_image_digest('quay.ceph.io/ceph/ceph', 'docker.io')
'quay.ceph.io/ceph/ceph'
>>> normalize_image_digest('docker.io/ubuntu', 'docker.io')
'docker.io/ubuntu'
>>> normalize_image_digest('localhost/ceph', 'docker.io')
'localhost/ceph'
"""
bits = digest.split('/')
if '.' not in bits[0] or len(bits) < 3:
digest = 'docker.io/' + digest
known_shortnames = [
'ceph/ceph',
'ceph/daemon',
'ceph/daemon-base',
]
for image in known_shortnames:
if digest.startswith(image):
return f'{default_registry}/{digest}'
return digest


Expand Down

0 comments on commit 9271e72

Please sign in to comment.