1050
1050
def test_pre_block_migration_works_correctly(self):
1051
1051
"""Confirms pre_block_migration works correctly."""
1052
1052
# Replace instances_path since this testcase creates tmpfile
1053
tmpdir = tempfile.mkdtemp()
1054
self.flags(instances_path=tmpdir)
1057
instance_ref = db.instance_create(self.context, self.test_instance)
1058
dummyjson = ('[{"path": "%s/disk", "disk_size": "10737418240",'
1059
' "type": "raw", "backing_file": ""}]')
1062
# qemu-img should be mockd since test environment might not have
1064
self.mox.ReplayAll()
1065
conn = connection.LibvirtConnection(False)
1066
conn.pre_block_migration(self.context, instance_ref,
1069
self.assertTrue(os.path.exists('%s/%s/' %
1070
(tmpdir, instance_ref.name)))
1072
shutil.rmtree(tmpdir)
1053
with utils.tempdir() as tmpdir:
1054
self.flags(instances_path=tmpdir)
1057
instance_ref = db.instance_create(self.context, self.test_instance)
1058
dummyjson = ('[{"path": "%s/disk", "disk_size": "10737418240",'
1059
' "type": "raw", "backing_file": ""}]')
1062
# qemu-img should be mockd since test environment might not have
1064
self.mox.ReplayAll()
1065
conn = connection.LibvirtConnection(False)
1066
conn.pre_block_migration(self.context, instance_ref,
1069
self.assertTrue(os.path.exists('%s/%s/' %
1070
(tmpdir, instance_ref.name)))
1073
1072
db.instance_destroy(self.context, instance_ref['id'])
1075
1074
@test.skip_if(missing_libvirt(), "Test requires libvirt")
1926
1925
libvirt_utils.mkfs('swap', '/my/swap/block/dev')
1928
1927
def test_ensure_tree(self):
1929
tmpdir = tempfile.mkdtemp()
1928
with utils.tempdir() as tmpdir:
1931
1929
testdir = '%s/foo/bar/baz' % (tmpdir,)
1932
1930
libvirt_utils.ensure_tree(testdir)
1933
1931
self.assertTrue(os.path.isdir(testdir))
1935
shutil.rmtree(tmpdir)
1937
1933
def test_write_to_file(self):
1938
1934
dst_fd, dst_path = tempfile.mkstemp()