Repository: typesafehub/conductr-cli

Issue:
Sandbox startup failing to start haproxy doesn't result in error
* Run a program that binds on port 9000
* Start the sandbox. Notice docker complains, but the sandbox doesn't notice.

We should fail fast and tell the user about the `--bundle-http-port` flag / `BUNDLE_HTTP_PORT` env variable

Discussion:

Patch:
diff --git a/conductr_cli/terminal.py b/conductr_cli/terminal.py
index 2c27df4..84205cb 100644
--- a/conductr_cli/terminal.py
+++ b/conductr_cli/terminal.py
@@ -28,7 +28,9 @@ def docker_inspect(container_id, inspect_format=None):
 
 def docker_run(optional_args, image, positional_args):
     cmd = ['docker', 'run'] + optional_args + [image] + positional_args
-    return subprocess.call(cmd)
+    status = subprocess.call(cmd)
+    assert status == 0, 'docker exited with {}'.format(status)
+    return 0
 
 
 def docker_rm(containers):


Test patch:
diff --git a/conductr_cli/test/test_terminal.py b/conductr_cli/test/test_terminal.py
index d6ff783..0337492 100644
--- a/conductr_cli/test/test_terminal.py
+++ b/conductr_cli/test/test_terminal.py
@@ -72,7 +72,7 @@ class TestTerminal(CliTestCase):
         image = 'image:version'
         positional_args = ['--discover-host-ip']
         stdout = MagicMock()
-        subprocess_call_mock = MagicMock()
+        subprocess_call_mock = MagicMock(return_value=0)
 
         with patch('subprocess.call', subprocess_call_mock), \
                 patch('sys.stdout', stdout):
@@ -81,6 +81,21 @@ class TestTerminal(CliTestCase):
         self.assertEqual('', self.output(stdout))
         subprocess_call_mock.assert_called_with(['docker', 'run'] + optional_args + [image] + positional_args)
 
+    def test_docker_run_fail(self):
+        optional_args = ['-p', '9001:9001', '-e', 'AKKA_LOGLEVEL=info']
+        image = 'image:version'
+        positional_args = ['--discover-host-ip']
+        stdout = MagicMock()
+        subprocess_call_mock = MagicMock(return_value=1)
+
+        with patch('subprocess.call', subprocess_call_mock), \
+                patch('sys.stdout', stdout), \
+                self.assertRaises(AssertionError):
+            terminal.docker_run(optional_args, image, positional_args)
+
+        self.assertEqual('', self.output(stdout))
+        subprocess_call_mock.assert_called_with(['docker', 'run'] + optional_args + [image] + positional_args)
+
     def test_docker_rm(self):
         containers = ['cond-0', 'cond-1']
         stdout = MagicMock()