From 6bfab5d29937989deca5a2c4eed5d98ab2690849 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 17 Jun 2017 21:54:49 +0300 Subject: Fix: move virtual fs mounting to its own step Can't mount them until after debootstrap is finished or things break. --- vmdb/plugins/mount_plugin.py | 35 +------------------ vmdb/plugins/virtuals_plugin.py | 75 +++++++++++++++++++++++++++++++++++++++++ without-tests | 1 + 3 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 vmdb/plugins/virtuals_plugin.py 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 . +# +# =*= 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 -- cgit v1.2.1