summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_lxd.py12
-rw-r--r--tests/unittests/test_handler/test_handler_lxd.py2
2 files changed, 9 insertions, 5 deletions
diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py
index 7129c9c6..486037d9 100644
--- a/cloudinit/config/cc_lxd.py
+++ b/cloudinit/config/cc_lxd.py
@@ -283,14 +283,18 @@ def maybe_cleanup_default(net_name, did_init, create, attach,
fail_assume_enoent = "failed. Assuming it did not exist."
succeeded = "succeeded."
if create:
- msg = "Deletion of lxd network '%s' %s"
+ msg = "Detach of lxd network '%s' from profile '%s' %s"
try:
- _lxc(["network", "delete", net_name])
- LOG.debug(msg, net_name, succeeded)
+ _lxc(["network", "detach-profile", net_name, profile])
+ LOG.debug(msg, net_name, profile, succeeded)
except subp.ProcessExecutionError as e:
if e.exit_code != 1:
raise e
- LOG.debug(msg, net_name, fail_assume_enoent)
+ LOG.debug(msg, net_name, profile, fail_assume_enoent)
+ else:
+ msg = "Deletion of lxd network '%s' %s"
+ _lxc(["network", "delete", net_name])
+ LOG.debug(msg, net_name, succeeded)
if attach:
msg = "Removal of device '%s' from profile '%s' %s"
diff --git a/tests/unittests/test_handler/test_handler_lxd.py b/tests/unittests/test_handler/test_handler_lxd.py
index 21011204..b2181992 100644
--- a/tests/unittests/test_handler/test_handler_lxd.py
+++ b/tests/unittests/test_handler/test_handler_lxd.py
@@ -214,7 +214,7 @@ class TestLxdMaybeCleanupDefault(t_help.CiTestCase):
"""deletion of network should occur if create is True."""
cc_lxd.maybe_cleanup_default(
net_name=self.defnet, did_init=True, create=True, attach=False)
- m_lxc.assert_called_once_with(["network", "delete", self.defnet])
+ m_lxc.assert_called_with(["network", "delete", self.defnet])
@mock.patch("cloudinit.config.cc_lxd._lxc")
def test_device_removed_if_attach_true(self, m_lxc):