Skip to content

Commit

Permalink
build providers: idempotent destroy for LXD (#2529)
Browse files Browse the repository at this point in the history
Fixes SNAPCRAFT-MB

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens authored Apr 9, 2019
1 parent d1c5f1b commit 1b29058
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions snapcraft/internal/build_providers/_lxd/_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ def _start(self):
self._run(command=["cloud-init", "status", "--wait"])

def _stop(self):
# If _container is still None here it means creation/starting was not
# successful.
if self._container is None:
return

self._container.sync()

if self._container.status.lower() != "stopped":
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/build_providers/lxd/test_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ def test_clean_project_new_instance(self):
container.delete_mock.assert_called_once_with(wait=True)
self.assertThat(instance.clean_project(), Equals(True))

def test_destroy_when_not_created(self):
instance = LXD(project=self.project, echoer=self.echoer_mock)
# This call should not fail
instance.destroy()


class LXDLaunchedTest(LXDBaseTest):
def setUp(self):
Expand Down

0 comments on commit 1b29058

Please sign in to comment.