Merge "disk/vfs: introduce new method get_image_fs"
This commit is contained in:
@@ -186,3 +186,6 @@ class GuestFS(object):
|
||||
|
||||
def set_event_callback(self, func, events):
|
||||
self.event_callback = (func, events)
|
||||
|
||||
def vfs_type(self, dev):
|
||||
return 'ext3'
|
||||
|
||||
@@ -262,3 +262,10 @@ class VirtDiskVFSGuestFSTest(test.NoDBTestCase):
|
||||
self.assertTrue(vfs.handle.trace_enabled)
|
||||
self.assertTrue(vfs.handle.verbose_enabled)
|
||||
self.assertIsNotNone(vfs.handle.event_callback)
|
||||
|
||||
def test_get_format_fs(self):
|
||||
vfs = vfsimpl.VFSGuestFS("dummy.img")
|
||||
vfs.setup()
|
||||
self.assertIsNotNone(vfs.handle)
|
||||
self.assertTrue('ext3', vfs.get_image_fs())
|
||||
vfs.teardown()
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
from oslo_concurrency import processutils
|
||||
|
||||
@@ -383,3 +384,34 @@ class VirtDiskVFSLocalFSTest(test.NoDBTestCase):
|
||||
'/scratch/dir/some/file'),
|
||||
'kwargs': {'run_as_root': True,
|
||||
'root_helper': root_helper}}])
|
||||
|
||||
@mock.patch.object(nova.utils, 'execute')
|
||||
def test_get_format_fs(self, execute):
|
||||
vfs = vfsimpl.VFSLocalFS("dummy.img")
|
||||
vfs.setup = mock.MagicMock()
|
||||
vfs.teardown = mock.MagicMock()
|
||||
|
||||
def fake_setup():
|
||||
vfs.mount = mock.MagicMock()
|
||||
vfs.mount.device = None
|
||||
vfs.mount.get_dev.side_effect = fake_get_dev
|
||||
|
||||
def fake_teardown():
|
||||
vfs.mount.device = None
|
||||
|
||||
def fake_get_dev():
|
||||
vfs.mount.device = '/dev/xyz'
|
||||
return True
|
||||
|
||||
vfs.setup.side_effect = fake_setup
|
||||
vfs.teardown.side_effect = fake_teardown
|
||||
execute.return_value = ('ext3\n', '')
|
||||
|
||||
vfs.setup()
|
||||
self.assertEqual('ext3', vfs.get_image_fs())
|
||||
vfs.teardown()
|
||||
vfs.mount.get_dev.assert_called_once_with()
|
||||
execute.assert_called_once_with('blkid', '-o',
|
||||
'value', '-s',
|
||||
'TYPE', '/dev/xyz',
|
||||
run_as_root=True)
|
||||
|
||||
@@ -139,3 +139,11 @@ class VFS(object):
|
||||
this call.
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_image_fs(self):
|
||||
"""Returns the filesystem type or an empty string.
|
||||
|
||||
Determine the filesystem type whether the disk image is
|
||||
partition less.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -302,3 +302,6 @@ class VFSGuestFS(vfs.VFS):
|
||||
LOG.debug("chown uid=%(uid)d gid=%(gid)s",
|
||||
{'uid': uid, 'gid': gid})
|
||||
self.handle.chown(uid, gid, path)
|
||||
|
||||
def get_image_fs(self):
|
||||
return self.handle.vfs_type('/dev/sda')
|
||||
|
||||
@@ -157,3 +157,12 @@ class VFSLocalFS(vfs.VFS):
|
||||
|
||||
if owner is not None:
|
||||
utils.execute(cmd, owner, canonpath, run_as_root=True)
|
||||
|
||||
def get_image_fs(self):
|
||||
if self.mount.device or self.mount.get_dev():
|
||||
out, err = utils.execute('blkid', '-o',
|
||||
'value', '-s',
|
||||
'TYPE', self.mount.device,
|
||||
run_as_root=True)
|
||||
return out.strip()
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user