]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: require --image is passed to inspect-image 51649/head
authorAdam King <adking@redhat.com>
Fri, 21 Apr 2023 14:07:09 +0000 (10:07 -0400)
committerAdam King <adking@redhat.com>
Sun, 21 May 2023 19:45:14 +0000 (15:45 -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>
(cherry picked from commit 110fcb04adf31881f2f41bd0c27f7ce25438f3b9)

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 2ed41a24df05a845d5c4f7295d17dc1895b7a54e..60e61748f1e0ae7657171d26a239ebb1604a90c9 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 07b71b5fa97f896daa8391feca24336f8f358c2c..082b0305ec1ce2b5b13bc9e60d18e46b1be62310 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,-- / --')