mirror of
https://github.com/ceph/ceph
synced 2025-02-21 01:47:25 +00:00
Merge pull request #51172 from adk3798/require-image-for-inspect
cephadm: require --image is passed to inspect-image Reviewed-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
commit
b5eb2e79b4
@ -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
|
||||
-------------
|
||||
|
@ -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:
|
||||
@ -4880,6 +4893,7 @@ def _pull_image(ctx, image, insecure=False):
|
||||
##################################
|
||||
|
||||
|
||||
@require_image
|
||||
@infer_image
|
||||
def command_inspect_image(ctx):
|
||||
# type: (CephadmContext) -> int
|
||||
|
@ -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,-- / --')
|
||||
|
Loading…
Reference in New Issue
Block a user