From f63c9e08e95b5132d301c8a364cedaee627fc81a Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Tue, 23 Oct 2012 16:00:31 +0100 Subject: [PATCH] Move mkfs from libvirt.utils to utils Related to blueprint xenapi-config-drive Move mkfs function to nova.utils, so configdrive module does not depend on the libvirt module. This way, the configdrive module could be used by other virt modules. Change-Id: Ibda2aacfa0b66bc087e397df1474b5dfbe86d923 --- nova/tests/fake_libvirt_utils.py | 4 ---- nova/tests/test_libvirt.py | 9 --------- nova/utils.py | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/nova/tests/fake_libvirt_utils.py b/nova/tests/fake_libvirt_utils.py index 4f7c96d4f..020ff8192 100644 --- a/nova/tests/fake_libvirt_utils.py +++ b/nova/tests/fake_libvirt_utils.py @@ -48,10 +48,6 @@ def copy_image(src, dest): pass -def mkfs(fs, path): - pass - - def resize2fs(path): pass diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 43b4d4813..b12a7a3ea 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -3566,15 +3566,6 @@ disk size: 4.4M''', '')) finally: os.unlink(dst_path) - def test_mkfs(self): - self.mox.StubOutWithMock(utils, 'execute') - utils.execute('mkfs', '-t', 'ext4', '-F', '/my/block/dev') - utils.execute('mkswap', '/my/swap/block/dev') - self.mox.ReplayAll() - - libvirt_utils.mkfs('ext4', '/my/block/dev') - libvirt_utils.mkfs('swap', '/my/swap/block/dev') - def test_write_to_file(self): dst_fd, dst_path = tempfile.mkstemp() try: diff --git a/nova/utils.py b/nova/utils.py index 015ff915a..f49f3bc43 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1328,3 +1328,24 @@ def ensure_tree(path): raise else: raise + + +def mkfs(fs, path, label=None): + """Format a file or block device + + :param fs: Filesystem type (examples include 'swap', 'ext3', 'ext4' + 'btrfs', etc.) + :param path: Path to file or block device to format + :param label: Volume label to use + """ + if fs == 'swap': + execute('mkswap', path) + else: + args = ['mkfs', '-t', fs] + #add -F to force no interactive excute on non-block device. + if fs in ['ext3', 'ext4']: + args.extend(['-F']) + if label: + args.extend(['-n', label]) + args.append(path) + execute(*args)