Detect container failure when checking create complete
Change-Id: I77f56ec544a82e13cd5a00a3adcfde6c0dda822e
This commit is contained in:
parent
dd934d6657
commit
0f368be6b9
@ -290,6 +290,11 @@ class DockerContainer(resource.Resource):
|
||||
|
||||
def check_create_complete(self, container_id):
|
||||
status = self._get_container_status(container_id)
|
||||
exit_status = status.get('ExitCode')
|
||||
if exit_status is not None and exit_status != 0:
|
||||
logs = self.get_client().logs(self.resource_id)
|
||||
raise resource.ResourceInError(resource_status=self.FAILED,
|
||||
status_reason=logs)
|
||||
return status['Running']
|
||||
|
||||
def handle_delete(self):
|
||||
|
@ -16,10 +16,12 @@
|
||||
|
||||
import mock
|
||||
from oslo.utils import importutils
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.engine import resource
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
@ -108,6 +110,26 @@ class DockerContainerTest(common.HeatTestCase):
|
||||
self.assertEqual(['samalba/wordpress'], client.pulled_images)
|
||||
self.assertEqual('super-blog', client.container_create[0]['name'])
|
||||
|
||||
@mock.patch.object(docker_container.DockerContainer, 'get_client')
|
||||
def test_create_failed(self, test_client):
|
||||
mock_client = mock.Mock()
|
||||
mock_client.inspect_container.return_value = {
|
||||
"State": {
|
||||
"ExitCode": -1
|
||||
}
|
||||
}
|
||||
mock_client.logs.return_value = "Container startup failed"
|
||||
test_client.return_value = mock_client
|
||||
mock_stack = mock.Mock()
|
||||
mock_stack.db_resource_get.return_value = None
|
||||
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
|
||||
docker_res = docker_container.DockerContainer("test", res_def,
|
||||
mock_stack)
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
docker_res.check_create_complete,
|
||||
'foo')
|
||||
self.assertIn("Container startup failed", six.text_type(exc))
|
||||
|
||||
def test_start_with_bindings_and_links(self):
|
||||
t = template_format.parse(template)
|
||||
stack = utils.parse_stack(t)
|
||||
|
Loading…
Reference in New Issue
Block a user