Skip to content

Commit 9ac5cea

Browse files
committed
Submit raises ResourceError with reason
Small change, container.submit() now raises a ResourceError, with the human readable cause from the zun container. For debugging, the traceback includes the original WaitError with more info. This should preserve compatability with anything that currently calls "submit" inside a try except block.
1 parent cd08340 commit 9ac5cea

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

chi/container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from .clients import connection, zun
3030
from .context import session
31-
from .exception import ContainerCreateWaitError, ServiceError
31+
from .exception import ContainerCreateWaitError, ResourceError, ServiceError
3232
from .network import bind_floating_ip, get_free_floating_ip
3333

3434
DEFAULT_IMAGE_DRIVER = "docker"
@@ -131,7 +131,7 @@ def submit(
131131
idempotent (bool, optional): Whether to update the existing container if it already exists. Defaults to False.
132132
133133
Raises:
134-
ContainerCreateWaitError: If the container creation fails.
134+
ResourceError: If the container creation fails.
135135
136136
Returns:
137137
None
@@ -169,7 +169,7 @@ def submit(
169169
# ensure container object gets params even on error
170170
self.id = exc.zun_container.uuid
171171
self._status = exc.zun_container.status
172-
raise
172+
raise ResourceError(message=exc.zun_container.status_reason) from exc
173173

174174
if wait_for_active and self.status != "Running":
175175
self.wait(status="Running", timeout=wait_timeout)

chi/exception.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def __init__(self, message):
3030
super().__init__(message)
3131

3232

33-
class ContainerCreateWaitError(RuntimeError):
33+
class ContainerCreateWaitError(ResourceError):
3434
"""Raised when Zun creates a container but waiting for target status fails."""
3535

3636
def __init__(self, zun_container, cause):
3737
self.zun_container = zun_container
3838
self.cause = cause
3939
message = (
40-
f"Container {self.zun_container.uuid} was created, but waiting for target status failed: {cause}"
40+
"Container {} was created, but waiting for target status failed: {}".format(
41+
self.zun_container.uuid,
42+
cause,
43+
)
4144
)
4245
super().__init__(message)

tests/test_container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from zunclient.exceptions import Conflict
2222

2323
from chi.container import Container, download, upload
24-
from chi.exception import ContainerCreateWaitError
24+
from chi.exception import ContainerCreateWaitError, ResourceError
2525

2626

2727
@pytest.fixture()
@@ -170,7 +170,7 @@ def test_submit_preserves_reference_on_create_wait_failure(mocker):
170170
zun_mock = mocker.patch("chi.container.zun")()
171171
zun_mock.containers.get.return_value = leaked_zun_container
172172

173-
with pytest.raises(ContainerCreateWaitError):
173+
with pytest.raises(ResourceError):
174174
chi_container.submit(wait_for_active=False, show=None)
175175

176176
assert chi_container.id == "leaked-uuid"

0 commit comments

Comments
 (0)