]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: require --image is passed to inspect-image 51172/head
authorAdam King <adking@redhat.com>
Fri, 21 Apr 2023 14:07:09 +0000 (10:07 -0400)
committerAdam King <adking@redhat.com>
Tue, 2 May 2023 21:16:06 +0000 (17:16 -0400)
The selection of an image by default was likely unused and
has always been a bit of a flaky thing, especially if multiple
clusters are making use of the host where this is run. It seems
preferable to just require this argument. Additionally, the
command without the image specified is currently untested
and prone to being broken. All uses of inspect-image done
through the cephadm mgr module specify the image.

Signed-off-by: Adam King <adking@redhat.com>
doc/man/8/cephadm.rst
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index 9e32ce39a0bb761ec8f5e13aa924100c5f65aa59..0847066b66daa666b376fe780a3398465019f5ed 100644 (file)
@@ -19,7 +19,7 @@ Synopsis
 
 | **cephadm** **pull**
 
-| **cephadm** **inspect-image**
+| **cephadm** --image IMAGE_NAME **inspect-image**
 
 | **cephadm** **ls** [-h] [--no-detail] [--legacy-dir LEGACY_DIR]
 
@@ -334,7 +334,10 @@ Positional arguments:
 inspect-image
 -------------
 
-inspect local ceph container image.
+Inspect local Ceph container image. From Reef onward, requires specifying
+the image to inspect with ``--image``::
+
+    cephadm --image IMAGE_NAME inspect-image
 
 list-networks
 -------------
index c5a2a6f44d74f1b6fbbac3af95739b3fd93bb2b6..7629e77322df98072c95df573a30048384bbd5de 100755 (executable)
@@ -2243,6 +2243,19 @@ def infer_image(func: FuncT) -> FuncT:
     return cast(FuncT, _infer_image)
 
 
+def require_image(func: FuncT) -> FuncT:
+    """
+    Require the global --image flag to be set
+    """
+    @wraps(func)
+    def _require_image(ctx: CephadmContext) -> Any:
+        if not ctx.image:
+            raise Error('This command requires the global --image option to be set')
+        return func(ctx)
+
+    return cast(FuncT, _require_image)
+
+
 def default_image(func: FuncT) -> FuncT:
     @wraps(func)
     def _default_image(ctx: CephadmContext) -> Any:
@@ -4882,6 +4895,7 @@ def _pull_image(ctx, image, insecure=False):
 ##################################
 
 
+@require_image
 @infer_image
 def command_inspect_image(ctx):
     # type: (CephadmContext) -> int
index 00862b1d1e76bacd68b0d42d1c242dc3c8527541..697a66f04479e0b26ffc3f4441a3f1ed5d0d5db5 100644 (file)
@@ -152,6 +152,18 @@ class TestCephAdm(object):
         args = _cephadm._parse_args(['--image', 'foo', 'version'])
         assert args.image == 'foo'
 
+    def test_check_required_global_args(self):
+        ctx = _cephadm.CephadmContext()
+        mock_fn = mock.Mock()
+        mock_fn.return_value = 0
+        require_image = _cephadm.require_image(mock_fn)
+
+        with pytest.raises(_cephadm.Error, match='This command requires the global --image option to be set'):
+            require_image(ctx)
+
+        ctx.image = 'sample-image'
+        require_image(ctx)
+
     @mock.patch('cephadm.logger')
     def test_parse_mem_usage(self, _logger):
         len, summary = _cephadm._parse_mem_usage(0, 'c6290e3f1489,-- / --')