summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-06-17 21:54:49 +0300
committerLars Wirzenius <liw@liw.fi>2017-06-18 15:55:14 +0300
commit6bfab5d29937989deca5a2c4eed5d98ab2690849 (patch)
treeb1a22acb02cfb859ceec1716e389414e72f3b76b
parent0d7a471bb90436f05fa06fd886b37f211ece5d4c (diff)
downloadvmdb2-6bfab5d29937989deca5a2c4eed5d98ab2690849.tar.gz
Fix: move virtual fs mounting to its own step
Can't mount them until after debootstrap is finished or things break.
-rw-r--r--vmdb/plugins/mount_plugin.py35
-rw-r--r--vmdb/plugins/virtuals_plugin.py75
-rw-r--r--without-tests1
3 files changed, 77 insertions, 34 deletions
diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py
index da038ad..0b06401 100644
--- a/vmdb/plugins/mount_plugin.py
+++ b/vmdb/plugins/mount_plugin.py
@@ -17,7 +17,6 @@
-import logging
import os
import tempfile
@@ -34,25 +33,13 @@ class MountPlugin(cliapp.Plugin):
class MountStepRunner(vmdb.StepRunnerInterface):
- virtuals = [
- ['none', '/proc', 'proc'],
- ['none', '/dev', 'devtmpfs'],
- ['none', '/dev/pts', 'devpts'],
- ['none', '/dev/shm', 'tmpfs'],
- ['none', '/run', 'tmpfs'],
- ['none', '/run/lock', 'tmpfs'],
- ['none', '/sys', 'sysfs'],
- ]
-
def get_required_keys(self):
return ['mount', 'fs-tag']
def run(self, step, settings, state):
- rootfs = self.mount_rootfs(step, settings, state)
- self.mount_virtuals(rootfs, state)
+ self.mount_rootfs(step, settings, state)
def teardown(self, step, settings, state):
- self.unmount_virtuals(state)
self.unmount_rootfs(step, settings, state)
def mount_rootfs(self, step, settings, state):
@@ -78,23 +65,3 @@ class MountStepRunner(vmdb.StepRunnerInterface):
vmdb.runcmd(['umount', mount_point])
os.rmdir(mount_point)
-
- def mount_virtuals(self, rootfs, state):
- if not hasattr(state, 'virtuals'):
- state.virtuals = []
-
- for device, mount_point, fstype in self.virtuals:
- path = os.path.join(rootfs, './' + mount_point)
- if not os.path.exists(path):
- os.mkdir(path)
- vmdb.runcmd(['mount', '-t', fstype, device, path])
- state.virtuals.append(path)
- logging.debug('mounted virtuals: %r', state.virtuals)
-
- def unmount_virtuals(self, state):
- logging.debug('unmounting virtuals: %r', state.virtuals)
- for mount_point in reversed(state.virtuals):
- try:
- vmdb.runcmd(['umount', mount_point])
- except cliapp.AppException:
- vmdb.error('Something went wrong while unmounting. Ignoring.')
diff --git a/vmdb/plugins/virtuals_plugin.py b/vmdb/plugins/virtuals_plugin.py
new file mode 100644
index 0000000..60639ac
--- /dev/null
+++ b/vmdb/plugins/virtuals_plugin.py
@@ -0,0 +1,75 @@
+# Copyright 2017 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+
+import logging
+import os
+
+import cliapp
+
+import vmdb
+
+
+class VirtualFilesystemMountPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.step_runners.add(VirtualFilesystemMountStepRunner())
+
+
+class VirtualFilesystemMountStepRunner(vmdb.StepRunnerInterface):
+
+ virtuals = [
+ ['none', '/proc', 'proc'],
+ ['none', '/dev', 'devtmpfs'],
+ ['none', '/dev/pts', 'devpts'],
+ ['none', '/dev/shm', 'tmpfs'],
+ ['none', '/run', 'tmpfs'],
+ ['none', '/run/lock', 'tmpfs'],
+ ['none', '/sys', 'sysfs'],
+ ]
+
+ def get_required_keys(self):
+ return ['mount-virtual-filesystems']
+
+ def run(self, step, settings, state):
+ fstag = step['mount-virtual-filesystems']
+ mount_point = state.mounts[fstag]
+ self.mount_virtuals(mount_point, state)
+
+ def teardown(self, step, settings, state):
+ self.unmount_virtuals(state)
+
+ def mount_virtuals(self, rootfs, state):
+ if not hasattr(state, 'virtuals'):
+ state.virtuals = []
+
+ for device, mount_point, fstype in self.virtuals:
+ path = os.path.join(rootfs, './' + mount_point)
+ if not os.path.exists(path):
+ os.mkdir(path)
+ vmdb.runcmd(['mount', '-t', fstype, device, path])
+ state.virtuals.append(path)
+ logging.debug('mounted virtuals: %r', state.virtuals)
+
+ def unmount_virtuals(self, state):
+ logging.debug('unmounting virtuals: %r', state.virtuals)
+ for mount_point in reversed(state.virtuals):
+ try:
+ vmdb.runcmd(['umount', mount_point])
+ except cliapp.AppException:
+ vmdb.error('Something went wrong while unmounting. Ignoring.')
diff --git a/without-tests b/without-tests
index abde546..dffc1cd 100644
--- a/without-tests
+++ b/without-tests
@@ -18,3 +18,4 @@ vmdb/plugins/mkimg_plugin.py
vmdb/plugins/mount_plugin.py
vmdb/plugins/partition_plugin.py
vmdb/plugins/rootfs_cache_plugin.py
+vmdb/plugins/virtuals_plugin.py