diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 394ee31afb2..ab932ec7480 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -2528,7 +2528,6 @@ def _get_parser(): formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( '--image', - default=os.environ.get('CEPHADM_IMAGE', DEFAULT_IMAGE), help='container image. Can also be set via the "CEPHADM_IMAGE" ' 'env var') parser.add_argument( @@ -2835,6 +2834,19 @@ def _get_parser(): return parser +def _parse_args(av): + parser = _get_parser() + args = parser.parse_args(av) + + if not args.image: + if 'name' in args: + type_ = args.name.split('.', 1)[0] + if type_ in Monitoring.components: + args.image = Monitoring.components[type_]['image'] + if not args.image: + args.image = os.environ.get('CEPHADM_IMAGE', DEFAULT_IMAGE) + + return args if __name__ == "__main__": # allow argv to be injected @@ -2842,8 +2854,7 @@ if __name__ == "__main__": av = injected_argv # type: ignore except NameError: av = sys.argv[1:] - parser = _get_parser() - args = parser.parse_args(av) + args = _parse_args(av) if args.verbose: logging.basicConfig(level=logging.DEBUG) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 79b6db41825..b0dad3cd42d 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -18,22 +18,19 @@ class TestCephAdm(object): assert not cd.is_fsid('no-uuid') def test__get_parser_image(self): - p = cd._get_parser() - args = p.parse_args(['--image', 'foo', 'version']) + args = cd._parse_args(['--image', 'foo', 'version']) assert args.image == 'foo' @mock.patch.dict(os.environ,{'CEPHADM_IMAGE':'bar'}) def test__get_parser_image_with_envvar(self): - p = cd._get_parser() - args = p.parse_args(['version']) + args = cd._parse_args(['version']) assert args.image == 'bar' def test_CustomValidation(self): - p = cd._get_parser() - assert p.parse_args(['deploy', '--name', 'mon.a', '--fsid', 'fsid']) + assert cd._parse_args(['deploy', '--name', 'mon.a', '--fsid', 'fsid']) with pytest.raises(SystemExit): - p.parse_args(['deploy', '--name', 'wrong', '--fsid', 'fsid']) + cd._parse_args(['deploy', '--name', 'wrong', '--fsid', 'fsid']) @pytest.mark.parametrize("test_input, expected", [ ("podman version 1.6.2", (1,6,2)),