Skip to content

Commit ec5ef05

Browse files
cephadm: extend the container image inference test cases
This brings test coverage for container_lookup.py to 100%. Signed-off-by: John Mulligan <[email protected]>
1 parent d9846a7 commit ec5ef05

File tree

1 file changed

+115
-8
lines changed

1 file changed

+115
-8
lines changed

src/cephadm/tests/test_cephadm.py

Lines changed: 115 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,101 @@ def test_dict_get_join(self):
676676
),
677677
'expected': '1b58ca4f6dfd', # YIKES!
678678
},
679+
# multiple ceph deamons
680+
{
681+
'containers': [
682+
{
683+
'name': 'osd.8',
684+
'_container_info': _container_info(
685+
'7487e763ce4a103a60292a33269bb39d0abfaf688c7793a78251ce6489a9c52d',
686+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
687+
'1b58ca4f6dfd7553d99b923e6b7e8fd0ab4f8ca4db802b81c68de9b6c362ee7a',
688+
'2025-01-17 11:00:44.361121326 -0500 EST',
689+
'',
690+
),
691+
},
692+
{
693+
'name': 'mgr.cep0.aofdsasdi',
694+
'_container_info': _container_info(
695+
'44ec17226ffd4824cdfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
696+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
697+
'c17226ffd4824c0f7dfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
698+
'2025-01-17 11:00:44.361121326 -0500 EST',
699+
'',
700+
),
701+
},
702+
],
703+
'images_output': (
704+
'''quay.ceph.io/ceph-ci/ceph@sha256:d6d1f4ab7148145467d9b632efc89d75710196434cba00aec5571b01e15b8a99|1e6f059b33d7|main|2025-01-21 16:54:41 +0000 UTC
705+
quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789|c17226ffd482|test|2025-01-21 16:54:41 +0000 UTC
706+
'''
707+
),
708+
'expected': 'quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789',
709+
},
710+
# named ceph deamon
711+
{
712+
'name': 'osd.8',
713+
'containers': [
714+
{
715+
'name': 'osd.8',
716+
'_container_info': _container_info(
717+
'7487e763ce4a103a60292a33269bb39d0abfaf688c7793a78251ce6489a9c52d',
718+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
719+
'1b58ca4f6dfd7553d99b923e6b7e8fd0ab4f8ca4db802b81c68de9b6c362ee7a',
720+
'2025-01-17 11:00:44.361121326 -0500 EST',
721+
'',
722+
),
723+
},
724+
{
725+
'name': 'mgr.cep0.aofdsasdi',
726+
'_container_info': _container_info(
727+
'44ec17226ffd4824cdfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
728+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
729+
'c17226ffd4824c0f7dfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
730+
'2025-01-17 11:00:44.361121326 -0500 EST',
731+
'',
732+
),
733+
},
734+
],
735+
'images_output': (
736+
'''quay.ceph.io/ceph-ci/ceph@sha256:d6d1f4ab7148145467d9b632efc89d75710196434cba00aec5571b01e15b8a99|1b58ca4f6df|main|2025-01-21 16:54:41 +0000 UTC
737+
quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789|c17226ffd482|test|2025-01-21 16:54:41 +0000 UTC
738+
'''
739+
),
740+
'expected': 'quay.ceph.io/ceph-ci/ceph@sha256:d6d1f4ab7148145467d9b632efc89d75710196434cba00aec5571b01e15b8a99',
741+
},
742+
# named ceph deamon image unavailable
743+
{
744+
'name': 'osd.8',
745+
'containers': [
746+
{
747+
'name': 'osd.8',
748+
'_container_info': _container_info(
749+
'7487e763ce4a103a60292a33269bb39d0abfaf688c7793a78251ce6489a9c52d',
750+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
751+
'ccdb1b58cdfd7553d99b923e6b7e8fd0ab4f8ca4db802b81c68de9b6c362ee7a',
752+
'2025-01-17 11:00:44.361121326 -0500 EST',
753+
'',
754+
),
755+
},
756+
{
757+
'name': 'mgr.cep0.aofdsasdi',
758+
'_container_info': _container_info(
759+
'44ec17226ffd4824cdfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
760+
'quay.ceph.io/ceph-ci/ceph@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29',
761+
'c17226ffd4824c0f7dfebf0f8d628be9acb942ecbad47ae1699cfea38fb17f48',
762+
'2025-01-17 11:00:44.361121326 -0500 EST',
763+
'',
764+
),
765+
},
766+
],
767+
'images_output': (
768+
'''quay.ceph.io/ceph-ci/ceph@sha256:d6d1f4ab7148145467d9b632efc89d75710196434cba00aec5571b01e15b8a99|1b58ca4f6df|main|2025-01-21 16:54:41 +0000 UTC
769+
quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789|c17226ffd482|test|2025-01-21 16:54:41 +0000 UTC
770+
'''
771+
),
772+
'expected': 'quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789',
773+
},
679774
],
680775
)
681776
def test_infer_local_ceph_image(self, params, funkypatch):
@@ -684,17 +779,29 @@ def test_infer_local_ceph_image(self, params, funkypatch):
684779
ctx.container_engine = mock_podman()
685780

686781
cinfo = params.get('container_info', None)
782+
containers = params.get('containers', [])
783+
assert not (
784+
cinfo and containers
785+
), "test params must only have either cinfo OR containers"
786+
if not containers and cinfo:
787+
containers = [{'_container_info': cinfo, 'name': 'mon.foo'}]
788+
if params.get('name', None):
789+
ctx.name = params['name']
790+
687791
out = params.get('images_output', '')
688792
expected = params.get('expected', None)
689-
funkypatch.patch('cephadmlib.call_wrappers.call').return_value = out, '', 0
690-
funkypatch.patch('cephadmlib.listing_updaters.CoreStatusUpdater')().expand.return_value = {
691-
'_container_info': cinfo,
692-
'name': 'mon.foo',
693-
}
694-
funkypatch.patch('cephadmlib.listing.daemons_matching').return_value = [0] if cinfo else []
695-
image = _cephadm.infer_local_ceph_image(
696-
ctx, ctx.container_engine
793+
funkypatch.patch('cephadmlib.call_wrappers.call').return_value = (
794+
out,
795+
'',
796+
0,
697797
)
798+
funkypatch.patch(
799+
'cephadmlib.listing_updaters.CoreStatusUpdater'
800+
)().expand.side_effect = lambda ctx, v: v
801+
funkypatch.patch(
802+
'cephadmlib.listing.daemons_matching'
803+
).return_value = containers
804+
image = _cephadm.infer_local_ceph_image(ctx, ctx.container_engine)
698805
assert image == expected
699806

700807
@pytest.mark.parametrize('daemon_filter, by_name, daemon_list, container_stats, output',

0 commit comments

Comments
 (0)