Skip to content

Commit

Permalink
Fix error message containing rich char '[' + handling rollback action
Browse files Browse the repository at this point in the history
  • Loading branch information
Dramelac committed Jul 20, 2023
1 parent c5ab46d commit e2cfedf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions exegol/model/ContainerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,19 @@ def prepareShare(self, share_name: str):
# Skip default volume workspace if disabled
return
else:
# Add shared-data-volumes private workspace bind volume
# Add dedicated private workspace bind volume
volume_path = str(UserConfig().private_volume_path.joinpath(share_name))
self.addVolume(volume_path, '/workspace', enable_sticky_group=True)

def rollback_preparation(self, share_name: str):
"""Undo preparation in case of container creation failure"""
if self.__workspace_custom_path is None and not self.__disable_workspace:
# Remove dedicated workspace volume
logger.info("Rollback: removing dedicated workspace directory")
directory_path = UserConfig().private_volume_path.joinpath(share_name)
if directory_path.is_dir():
directory_path.rmdir()

def setNetworkMode(self, host_mode: Optional[bool]):
"""Set container's network mode, true for host, false for bridge"""
if host_mode is None:
Expand Down Expand Up @@ -852,7 +861,7 @@ def removeVolume(self, host_path: Optional[str] = None, container_path: Optional
"""Remove a volume from the container configuration (Only before container creation)"""
if host_path is None and container_path is None:
# This is a dev problem
raise ReferenceError('At least one parameter must be set')
raise ValueError('At least one parameter must be set')
for i in range(len(self.__mounts)):
# For each Mount object compare the host_path if supplied or the container_path si supplied
if host_path is not None and self.__mounts[i].get("Source") == host_path:
Expand Down
4 changes: 4 additions & 0 deletions exegol/model/ExegolContainerTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def prepare(self):
"""Prepare the model before creating the docker container"""
self.config.prepareShare(self.name)

def rollback(self):
"""Rollback change in case of container creation fail."""
self.config.rollback_preparation(self.name)

def getDisplayName(self) -> str:
"""Getter of the container's name for TUI purpose"""
if self.container_name != self.hostname:
Expand Down
5 changes: 4 additions & 1 deletion exegol/utils/DockerUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ def createContainer(cls, model: ExegolContainerTemplate, temporary: bool = False
auto_remove=temporary,
working_dir=model.config.getWorkingDir())
except APIError as err:
logger.error(err.explanation.decode('utf-8') if type(err.explanation) is bytes else err.explanation)
message = err.explanation.decode('utf-8').replace('[', '\\[') if type(err.explanation) is bytes else err.explanation
message = message.replace('[', '\\[')
logger.error(message)
logger.debug(err)
model.rollback()
logger.critical("Error while creating exegol container. Exiting.")
# Not reachable, critical logging will exit
return # type: ignore
Expand Down

0 comments on commit e2cfedf

Please sign in to comment.