]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fix extra container/entrypoint args with spaces 49851/head
authorAdam King <adking@redhat.com>
Mon, 9 Jan 2023 19:50:12 +0000 (14:50 -0500)
committerAdam King <adking@redhat.com>
Fri, 3 Mar 2023 15:10:55 +0000 (10:10 -0500)
Fixes: https://tracker.ceph.com/issues/57338
Prior, doing extra container args like

- "--cpus"
- "2"

would work fine as the two args would be passed separately and
eventually placed in the final podman/docker run command
with a space between them. However, trying to do something like

- "--cpus 2"

instead would fail, as it would be translated to

--extra-container-args=--cpus 2

causing "2" to be considered its own arg, which cephadm
wouldn't know how to handle. Another way this can cause problems
is listed in the linked tracker. Either way, leaving the spaces
in the args was causing problems, and the simplest way to handle
it seems to be to just split on the original arg on the spaces
into multiple args

Signed-off-by: Adam King <adking@redhat.com>
(cherry picked from commit a161381ba816609b5041d2072e7e6cec39eaa753)

src/pybind/mgr/cephadm/serve.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index d0676d8a6f26737c04ef502719b1091ac16ffc0a..b0060c75c2a6182d598475ce7d5af2c445e950c8 100644 (file)
@@ -1244,14 +1244,24 @@ class CephadmServe:
             eca = daemon_spec.extra_container_args
             if eca:
                 for a in eca:
-                    daemon_spec.extra_args.append(f'--extra-container-args={a}')
+                    # args with spaces need to be split into multiple args
+                    # in order to work properly
+                    args = a.split(' ')
+                    for arg in args:
+                        if arg:
+                            daemon_spec.extra_args.append(f'--extra-container-args={arg}')
         except AttributeError:
             eca = None
         try:
             eea = daemon_spec.extra_entrypoint_args
             if eea:
                 for a in eea:
-                    daemon_spec.extra_args.append(f'--extra-entrypoint-args={a}')
+                    # args with spaces need to be split into multiple args
+                    # in order to work properly
+                    args = a.split(' ')
+                    for arg in args:
+                        if arg:
+                            daemon_spec.extra_args.append(f'--extra-entrypoint-args={arg}')
         except AttributeError:
             eea = None
         return daemon_spec, eca, eea
index 5deddb983dd102dcf393e3651cc4993ea6b6c613..ad3b119d97f49ba0c02f14005c152ffc66607b5b 100644 (file)
@@ -529,6 +529,35 @@ class TestCephadm(object):
                     image='',
                 )
 
+    @mock.patch("cephadm.serve.CephadmServe._run_cephadm")
+    def test_extra_entrypoint_and_container_args_with_spaces(self, _run_cephadm, cephadm_module: CephadmOrchestrator):
+        _run_cephadm.side_effect = async_side_effect(('{}', '', 0))
+        with with_host(cephadm_module, 'test'):
+            with with_service(cephadm_module, ServiceSpec(service_type='node-exporter',
+                              extra_entrypoint_args=['--entrypoint-arg-with-value value', '--some-other-arg   3'],
+                              extra_container_args=['--cpus    2', '--container-arg-with-value value']),
+                              CephadmOrchestrator.apply_node_exporter):
+                _run_cephadm.assert_called_with(
+                    'test', 'node-exporter.test', 'deploy', [
+                        '--name', 'node-exporter.test',
+                        '--meta-json', ('{"service_name": "node-exporter", "ports": [9100], "ip": null, "deployed_by": [], "rank": null, '
+                                        '"rank_generation": null, "extra_container_args": ["--cpus    2", "--container-arg-with-value value"], '
+                                        '"extra_entrypoint_args": ["--entrypoint-arg-with-value value", "--some-other-arg   3"]}'),
+                        '--config-json', '-',
+                        '--tcp-ports', '9100',
+                        '--extra-container-args=--cpus',
+                        '--extra-container-args=2',
+                        '--extra-container-args=--container-arg-with-value',
+                        '--extra-container-args=value',
+                        '--extra-entrypoint-args=--entrypoint-arg-with-value',
+                        '--extra-entrypoint-args=value',
+                        '--extra-entrypoint-args=--some-other-arg',
+                        '--extra-entrypoint-args=3'
+                    ],
+                    stdin='{}',
+                    image='',
+                )
+
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm")
     def test_custom_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator):
         _run_cephadm.side_effect = async_side_effect(('{}', '', 0))