Browse Source

Quote the health check command argument during a debug with print-cmd.

This is one of the few arguments that sometimes requires the use of
spaces. `paunch debug --action print-cmd` will now display a command
to stdout that can be copied, pasted, and executed reliability.

Change-Id: I04d2f141370cd88787422d6adf4b22cc54ecf028
Resolves: rhbz#1694572
Signed-off-by: Luke Short <ekultails@gmail.com>
(cherry picked from commit a304153948)
tags/4.5.0^0
Luke Short 3 months ago
parent
commit
210c0d662e
3 changed files with 16 additions and 2 deletions
  1. 12
    0
      paunch/__init__.py
  2. 2
    1
      paunch/builder/compose1.py
  3. 2
    1
      paunch/tests/test_builder_compose1.py

+ 12
- 0
paunch/__init__.py View File

@@ -194,6 +194,18 @@ def debug(config_id, container_name, action, config, managed_by, labels=None,
194 194
             r.unique_container_name(container_name)
195 195
         ]
196 196
         builder.container_run_args(cmd, container_name)
197
+
198
+        if '--health-cmd' in cmd:
199
+            health_check_arg_index = cmd.index('--health-cmd') + 1
200
+
201
+            # The argument given needs to be quoted to work properly with a
202
+            # copy and paste of the full command.
203
+            try:
204
+                cmd[health_check_arg_index] = (
205
+                    '"%s"' % cmd[health_check_arg_index])
206
+            except IndexError:
207
+                log.warning("No argument provided to --health-cmd.")
208
+
197 209
         print(' '.join(cmd))
198 210
     elif action == 'run':
199 211
         cmd = [

+ 2
- 1
paunch/builder/compose1.py View File

@@ -44,7 +44,8 @@ class ComposeV1Builder(base.BaseBuilder):
44 44
         if 'healthcheck' in cconfig:
45 45
             hconfig = cconfig['healthcheck']
46 46
             if 'test' in hconfig:
47
-                cmd.append('--health-cmd=%s' % hconfig['test'])
47
+                cmd.append('--health-cmd')
48
+                cmd.append(str(hconfig['test']))
48 49
             if 'interval' in hconfig:
49 50
                 cmd.append('--health-interval=%s' % hconfig['interval'])
50 51
             if 'timeout' in hconfig:

+ 2
- 1
paunch/tests/test_builder_compose1.py View File

@@ -53,7 +53,8 @@ class TestComposeV1Builder(tbb.TestBaseBuilder):
53 53
             ['docker', 'run', '--name', 'one',
54 54
              '--detach=true', '--env-file=/tmp/foo.env',
55 55
              '--net=host', '--ipc=host', '--pid=container:bar',
56
-             '--uts=host', '--health-cmd=/bin/true', '--health-interval=30s',
56
+             '--uts=host', '--health-cmd', '/bin/true',
57
+             '--health-interval=30s',
57 58
              '--health-timeout=10s', '--health-retries=3',
58 59
              '--privileged=true', '--restart=always', '--user=bar',
59 60
              '--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}',

Loading…
Cancel
Save