diff --git a/zunclient/common/websocketclient/exceptions.py b/zunclient/common/websocketclient/exceptions.py old mode 100644 new mode 100755 index 91784a19..81ebaa25 --- a/zunclient/common/websocketclient/exceptions.py +++ b/zunclient/common/websocketclient/exceptions.py @@ -45,3 +45,7 @@ class InvalidWebSocketLink(ContainerWebSocketException): class ContainerFailtoStart(ContainerWebSocketException): message = "Container fail to start" + + +class ContainerStateError(ContainerWebSocketException): + message = "Container state is error, can not attach container" diff --git a/zunclient/tests/unit/v1/test_containers_shell.py b/zunclient/tests/unit/v1/test_containers_shell.py old mode 100644 new mode 100755 index 6c45a924..2ccd42c0 --- a/zunclient/tests/unit/v1/test_containers_shell.py +++ b/zunclient/tests/unit/v1/test_containers_shell.py @@ -13,6 +13,7 @@ import mock from zunclient.common import utils as zun_utils +from zunclient.common.websocketclient import exceptions from zunclient.tests.unit.v1 import shell_test_base from zunclient.v1 import containers_shell @@ -133,3 +134,18 @@ class ShellTest(shell_test_base.TestCommandLineArgument): 'run --image-pull-policy wrong x', self._invalid_choice_error) self.assertFalse(mock_run.called) + + @mock.patch('zunclient.v1.containers.ContainerManager.get') + @mock.patch('zunclient.v1.containers_shell._show_container') + @mock.patch('zunclient.v1.containers.ContainerManager.run') + def test_zun_container_run_interactive(self, mock_run, + mock_show_container, + mock_get_container): + fake_container = mock.MagicMock() + fake_container.uuid = 'fake_uuid' + mock_run.return_value = fake_container + fake_container.status = 'Error' + mock_get_container.return_value = fake_container + self.assertRaises(exceptions.ContainerStateError, + self.shell, + 'run -i x ') diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py old mode 100644 new mode 100755 index 760462b3..dd59e166 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -430,7 +430,7 @@ def do_run(cs, args): ready_for_attach = True break if zun_utils.check_container_status(container, 'Error'): - break + raise exceptions.ContainerStateError(container_uuid) print("Waiting for container start") time.sleep(1) if ready_for_attach is True: