e2a0270f2d92 — Alain Leufroy 3 years ago
edit: prevent broken mount point

Do not allow users to edit layers having active descendants.
2 files changed, 18 insertions(+), 1 deletions(-)

M overlayctl
M test_overlayctl.py
M overlayctl +7 -1
@@ 610,7 610,13 @@ def editer(name, appended=None, prepende
     of the edited overlay.
     """
     layer = build_layer(name)
-    # XXX check descendants not active
+    to_stop = [layer for layer in _iter_descendants(layer) if layer.automountunit.is_active()]
+    if to_stop:
+        # XXX automatic stop/start
+        logger.error(
+            'You should prefere to stop the following overlays: \n\n%s\n',
+            ', '.join(x.name for x in to_stop))
+        return
     if not appended and not prepended and not removed:
         with NamedTemporaryFile() as fobj:
             fobj.write(b'# -*- encoding: utf-8 -*-\n')

          
M test_overlayctl.py +11 -0
@@ 471,6 471,17 @@ class TestEdit(BaseTest):
             self.get_mount_dir('base1'),
         ])
 
+    def test_cannot_edit_layer_with_active_descendant(self):
+        # Because OverlayFS does not like it, we protect users from
+        # having broken mount point.
+        self.get_mount_dir('base').mkdir()
+        overlayctl.creater('lower', ['base'])
+        overlayctl.creater('layer', ['lower'])
+        self.systemctl.reset_mock()
+        self.systemctl.status.return_value = {'Active': 'active'}
+        overlayctl.editer('lower', removed=['base'])
+        self.check_mount_unit('lower', [self.get_mount_dir('base')])
+
 
 class TestMove(BaseTest):
     """Tests for the `move` command."""