summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMate Lakat <mate.lakat@citrix.com>2012-10-23 16:00:31 +0100
committerMate Lakat <mate.lakat@citrix.com>2012-10-23 16:09:37 +0100
commit20b349337eccaa7e1f49742a70f90488af7993fa (patch)
tree1baac5a4bfd2a9ae79d97ab1cb40fbf813b3204d
parenta0fcd1248071ad66b610eac4903adf36b314390b (diff)
downloadnova-20b349337eccaa7e1f49742a70f90488af7993fa.tar.gz
nova-20b349337eccaa7e1f49742a70f90488af7993fa.tar.xz
nova-20b349337eccaa7e1f49742a70f90488af7993fa.zip
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
-rw-r--r--nova/tests/fake_libvirt_utils.py4
-rw-r--r--nova/tests/test_configdrive2.py7
-rw-r--r--nova/tests/test_libvirt.py9
-rw-r--r--nova/tests/test_utils.py12
-rw-r--r--nova/utils.py21
-rw-r--r--nova/virt/configdrive.py3
-rw-r--r--nova/virt/libvirt/driver.py4
-rw-r--r--nova/virt/libvirt/utils.py21
8 files changed, 39 insertions, 42 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_configdrive2.py b/nova/tests/test_configdrive2.py
index 77c9d12a6..922dc3613 100644
--- a/nova/tests/test_configdrive2.py
+++ b/nova/tests/test_configdrive2.py
@@ -26,7 +26,6 @@ from nova import flags
from nova.openstack.common import log
from nova import utils
from nova.virt import configdrive
-from nova.virt.libvirt import utils as virtutils
FLAGS = flags.FLAGS
@@ -67,12 +66,12 @@ class ConfigDriveTestCase(test.TestCase):
def test_create_configdrive_vfat(self):
imagefile = None
try:
- self.mox.StubOutWithMock(virtutils, 'mkfs')
+ self.mox.StubOutWithMock(utils, 'mkfs')
self.mox.StubOutWithMock(utils, 'execute')
self.mox.StubOutWithMock(utils, 'trycmd')
- virtutils.mkfs('vfat', mox.IgnoreArg(),
- label='config-2').AndReturn(None)
+ utils.mkfs('vfat', mox.IgnoreArg(),
+ label='config-2').AndReturn(None)
utils.trycmd('mount', '-o', 'loop', mox.IgnoreArg(),
mox.IgnoreArg(),
run_as_root=True).AndReturn((None, None))
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/tests/test_utils.py b/nova/tests/test_utils.py
index 531778212..dbd2c1cbe 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -768,6 +768,18 @@ class DiffDict(test.TestCase):
self.assertEqual(diff, dict(b=['-']))
+class MkfsTestCase(test.TestCase):
+
+ 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()
+
+ utils.mkfs('ext4', '/my/block/dev')
+ utils.mkfs('swap', '/my/swap/block/dev')
+
+
class EnsureTree(test.TestCase):
def test_ensure_tree(self):
with utils.tempdir() as tmpdir:
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)
diff --git a/nova/virt/configdrive.py b/nova/virt/configdrive.py
index bc9ef55c4..7ae97f2ec 100644
--- a/nova/virt/configdrive.py
+++ b/nova/virt/configdrive.py
@@ -27,7 +27,6 @@ from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova import utils
from nova import version
-from nova.virt.libvirt import utils as virtutils
LOG = logging.getLogger(__name__)
@@ -95,7 +94,7 @@ class ConfigDriveBuilder(object):
with open(path, 'w') as f:
f.truncate(64 * 1024 * 1024)
- virtutils.mkfs('vfat', path, label='config-2')
+ utils.mkfs('vfat', path, label='config-2')
mounted = False
try:
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 2d3b1d954..1dda6893e 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -1213,7 +1213,7 @@ class LibvirtDriver(driver.ComputeDriver):
libvirt_utils.create_image('raw', target,
'%d%c' % (local_size, unit))
if fs_format:
- libvirt_utils.mkfs(fs_format, target, label)
+ utils.mkfs(fs_format, target, label)
def _create_ephemeral(self, target, ephemeral_size, fs_label, os_type):
self._create_local(target, ephemeral_size)
@@ -1223,7 +1223,7 @@ class LibvirtDriver(driver.ComputeDriver):
def _create_swap(target, swap_mb):
"""Create a swap file of specified size"""
libvirt_utils.create_image('raw', target, '%dM' % swap_mb)
- libvirt_utils.mkfs('swap', target)
+ utils.mkfs('swap', target)
@staticmethod
def _get_console_log_path(instance_name):
diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py
index 17c9efdda..a9b951b7f 100644
--- a/nova/virt/libvirt/utils.py
+++ b/nova/virt/libvirt/utils.py
@@ -279,27 +279,6 @@ def copy_image(src, dest, host=None):
execute('rsync', '--sparse', '--compress', src, dest)
-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)
-
-
def write_to_file(path, contents, umask=None):
"""Write the given contents to a file