Convert file injection code to use the VFS APIs

Remove the requirement to mount disk images on the host
filesystem for file injection, by switching over to use
the new VFS APIs. The mount code is now solely used for
setting up LXC disk images

blueprint: virt-disk-api-refactoring
Change-Id: I1335bf7a8266d3d1d410a66538969f1213766cb9
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2012-11-13 11:21:09 +00:00
parent 87e912dee6
commit a1a5ebbbd6
2 changed files with 163 additions and 46 deletions

View File

@@ -149,49 +149,3 @@ class TestVirtDisk(test.TestCase):
self.executes.pop()
self.assertEqual(self.executes, expected_commands)
class TestVirtDiskPaths(test.TestCase):
def setUp(self):
super(TestVirtDiskPaths, self).setUp()
real_execute = utils.execute
def nonroot_execute(*cmd_parts, **kwargs):
kwargs.pop('run_as_root', None)
return real_execute(*cmd_parts, **kwargs)
self.stubs.Set(utils, 'execute', nonroot_execute)
def test_check_safe_path(self):
if tests.utils.is_osx():
self.skipTest("Unable to test on OSX")
ret = disk_api._join_and_check_path_within_fs('/foo', 'etc',
'something.conf')
self.assertEquals(ret, '/foo/etc/something.conf')
def test_check_unsafe_path(self):
if tests.utils.is_osx():
self.skipTest("Unable to test on OSX")
self.assertRaises(exception.Invalid,
disk_api._join_and_check_path_within_fs,
'/foo', 'etc/../../../something.conf')
def test_inject_files_with_bad_path(self):
if tests.utils.is_osx():
self.skipTest("Unable to test on OSX")
self.assertRaises(exception.Invalid,
disk_api._inject_file_into_fs,
'/tmp', '/etc/../../../../etc/passwd',
'hax')
def test_inject_metadata(self):
if tests.utils.is_osx():
self.skipTest("Unable to test on OSX")
with utils.tempdir() as tmpdir:
meta_objs = [{"key": "foo", "value": "bar"}]
metadata = {"foo": "bar"}
disk_api._inject_metadata_into_fs(meta_objs, tmpdir)
json_file = os.path.join(tmpdir, 'meta.js')
json_data = jsonutils.loads(open(json_file).read())
self.assertEqual(metadata, json_data)