Merge "Move mkfs from libvirt.utils to utils"
This commit is contained in:
@@ -48,10 +48,6 @@ def copy_image(src, dest):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def mkfs(fs, path):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def resize2fs(path):
|
def resize2fs(path):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -3753,15 +3753,6 @@ disk size: 4.4M''', ''))
|
|||||||
finally:
|
finally:
|
||||||
os.unlink(dst_path)
|
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):
|
def test_write_to_file(self):
|
||||||
dst_fd, dst_path = tempfile.mkstemp()
|
dst_fd, dst_path = tempfile.mkstemp()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1328,3 +1328,24 @@ def ensure_tree(path):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
raise
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user