diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 5b2ad778..fd9e0227 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -355,6 +355,9 @@ class FilesystemController(BaseController): def delete_volgroup(self, vg): for lv in vg._partitions: self.delete_logical_volume(lv) + for d in vg.devices: + if d.type == "dm_crypt": + self.model.remove_dm_crypt(d) self.model.remove_volgroup(vg) delete_lvm_volgroup = delete_volgroup diff --git a/subiquity/controllers/tests/__init__.py b/subiquity/controllers/tests/__init__.py new file mode 100644 index 00000000..792d6005 --- /dev/null +++ b/subiquity/controllers/tests/__init__.py @@ -0,0 +1 @@ +# diff --git a/subiquity/controllers/tests/test_filesystem.py b/subiquity/controllers/tests/test_filesystem.py new file mode 100644 index 00000000..e12d0ab2 --- /dev/null +++ b/subiquity/controllers/tests/test_filesystem.py @@ -0,0 +1,54 @@ +# Copyright 2019 Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from collections import defaultdict +import unittest + +from subiquity.controllers.filesystem import ( + FilesystemController, + ) +from subiquity.models.tests.test_filesystem import ( + make_model_and_disk, + ) + + +class FakeBaseModel: + pass + + +def make_controller_and_disk(): + common = defaultdict(type(None)) + bm = FakeBaseModel() + bm.filesystem, disk = make_model_and_disk() + common['base_model'] = bm + common['answers'] = {} + controller = FilesystemController(common) + return controller, disk + + +class TestFilesystemController(unittest.TestCase): + + def test_delete_encrypted_vg(self): + controller, disk = make_controller_and_disk() + spec = { + 'password': 'passw0rd', + 'devices': {disk}, + 'name': 'vg0', + } + vg = controller.create_volgroup(spec) + controller.delete_volgroup(vg) + dm_crypts = [ + a for a in controller.model._actions if a.type == 'dm_crypt'] + self.assertEqual(dm_crypts, [])