Skip to content

Commit

Permalink
instance_status on create
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiusens committed Apr 25, 2018
1 parent 3ebd7fb commit 6d6f976
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 5 additions & 1 deletion snapcraft/internal/build_providers/_base_provider.py
Expand Up @@ -65,7 +65,11 @@ def create(self):

@abc.abstractmethod
def destroy(self):
"""Provider steps needed to ensure the instance is destroyed."""
"""Provider steps needed to ensure the instance is destroyed.
This method should be safe to call multiple times and do nothing
if the instance to destroy is already destroyed.
"""

@abc.abstractmethod
def provision_project(self, tarball: str) -> None:
Expand Down
11 changes: 4 additions & 7 deletions snapcraft/internal/build_providers/_multipass/_multipass.py
Expand Up @@ -43,24 +43,21 @@ def launcher() -> None:
def __init__(self, *, project, echoer) -> None:
super().__init__(project=project, echoer=echoer)
self._multipass_cmd = MultipassCommand()
self._instance_info = None

def create(self):
"""Create the multipass instance and setup the build environment."""
self.launch_instance()
self._instance_info = self._get_instance_info()
self.setup_snapcraft()

def destroy(self):
"""Destroy the instance, trying to stop it first."""
try:
instance_info = self._get_instance_info()
except errors.ProviderInfoError as info_error:
self.echoer.warning(
'Failed to obtain the status of {!r} when trying to '
'delete: {}'.format(self.instance_name, info_error))
if self._instance_info is None:
return

try:
if not instance_info.is_stopped():
if not self._instance_info.is_stopped():
self._multipass_cmd.stop(instance_name=self.instance_name)
self._multipass_cmd.delete(instance_name=self.instance_name)
except errors.ProviderStopError as stop_error:
Expand Down

0 comments on commit 6d6f976

Please sign in to comment.