summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorKei Masumoto <masumotok@nttdata.co.jp>2011-08-15 20:31:43 +0000
committerTarmac <>2011-08-15 20:31:43 +0000
commitea53d0f37a4f478ffbe18516f99ca26192117e80 (patch)
tree3a56196e11ead6af9ead0eb13a345f6c7e63dcf8 /nova/tests
parenta18d8597c2fb52d77b8b827f2c440787b1165150 (diff)
parent7393a114f421f1b54019099777fea34a09a80737 (diff)
Adding kvm-block-migration feature.
I wrote some description the below URL. I hope it may help for reviewing. <http://etherpad.openstack.org/kvm-block-migration>
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_extensions.py97
-rw-r--r--nova/tests/api/openstack/test_limits.py178
-rw-r--r--nova/tests/api/openstack/test_servers.py3
-rw-r--r--nova/tests/scheduler/test_scheduler.py55
-rw-r--r--nova/tests/test_compute.py30
-rw-r--r--nova/tests/test_libvirt.py107
6 files changed, 263 insertions, 207 deletions
diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py
index 03aa82f3d..9a613681d 100644
--- a/nova/tests/api/openstack/test_extensions.py
+++ b/nova/tests/api/openstack/test_extensions.py
@@ -127,9 +127,7 @@ class ExtensionControllerTest(test.TestCase):
"updated": "2011-01-22T13:25:27-06:00",
"description": "The Fox In Socks Extension",
"alias": "FOXNSOX",
- "links": [],
- },
- )
+ "links": []})
def test_list_extensions_xml(self):
app = openstack.APIRouterV11()
@@ -336,27 +334,18 @@ class ExtensionsXMLSerializerTest(test.TestCase):
def test_serialize_extenstion(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {
- 'extension': {
- 'name': 'ext1',
- 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
- 'alias': 'RS-PIE',
- 'updated': '2011-01-22T13:25:27-06:00',
- 'description': 'Adds the capability to share an image.',
- 'links': [
- {
- 'rel': 'describedby',
- 'type': 'application/pdf',
- 'href': 'http://docs.rack.com/servers/api/ext/cs.pdf',
- },
- {
- 'rel': 'describedby',
- 'type': 'application/vnd.sun.wadl+xml',
- 'href': 'http://docs.rack.com/servers/api/ext/cs.wadl',
- },
- ],
- },
- }
+ data = {'extension': {
+ 'name': 'ext1',
+ 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
+ 'alias': 'RS-PIE',
+ 'updated': '2011-01-22T13:25:27-06:00',
+ 'description': 'Adds the capability to share an image.',
+ 'links': [{'rel': 'describedby',
+ 'type': 'application/pdf',
+ 'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
+ {'rel': 'describedby',
+ 'type': 'application/vnd.sun.wadl+xml',
+ 'href': 'http://docs.rack.com/servers/api/ext/cs.wadl'}]}}
xml = serializer.serialize(data, 'show')
print xml
@@ -378,48 +367,30 @@ class ExtensionsXMLSerializerTest(test.TestCase):
def test_serialize_extensions(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {
- "extensions": [
- {
- "name": "Public Image Extension",
- "namespace": "http://foo.com/api/ext/pie/v1.0",
- "alias": "RS-PIE",
- "updated": "2011-01-22T13:25:27-06:00",
- "description": "Adds the capability to share an image.",
- "links": [
- {
- "rel": "describedby",
+ data = {"extensions": [{
+ "name": "Public Image Extension",
+ "namespace": "http://foo.com/api/ext/pie/v1.0",
+ "alias": "RS-PIE",
+ "updated": "2011-01-22T13:25:27-06:00",
+ "description": "Adds the capability to share an image.",
+ "links": [{"rel": "describedby",
"type": "application/pdf",
- "href": "http://foo.com/api/ext/cs-pie.pdf",
- },
- {
- "rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-pie.wadl",
- },
- ],
- },
- {
- "name": "Cloud Block Storage",
- "namespace": "http://foo.com/api/ext/cbs/v1.0",
- "alias": "RS-CBS",
- "updated": "2011-01-12T11:22:33-06:00",
- "description": "Allows mounting cloud block storage.",
- "links": [
- {
- "rel": "describedby",
- "type": "application/pdf",
- "href": "http://foo.com/api/ext/cs-cbs.pdf",
- },
- {
- "rel": "describedby",
+ "href": "http://foo.com/api/ext/cs-pie.pdf"},
+ {"rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-cbs.wadl",
- },
- ],
- },
- ],
- }
+ "href": "http://foo.com/api/ext/cs-pie.wadl"}]},
+ {"name": "Cloud Block Storage",
+ "namespace": "http://foo.com/api/ext/cbs/v1.0",
+ "alias": "RS-CBS",
+ "updated": "2011-01-12T11:22:33-06:00",
+ "description": "Allows mounting cloud block storage.",
+ "links": [{"rel": "describedby",
+ "type": "application/pdf",
+ "href": "http://foo.com/api/ext/cs-cbs.pdf"},
+ {"rel": "describedby",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://foo.com/api/ext/cs-cbs.wadl"}]}]}
xml = serializer.serialize(data, 'index')
print xml
diff --git a/nova/tests/api/openstack/test_limits.py b/nova/tests/api/openstack/test_limits.py
index 1dc3c3a17..801b06230 100644
--- a/nova/tests/api/openstack/test_limits.py
+++ b/nova/tests/api/openstack/test_limits.py
@@ -915,86 +915,56 @@ class LimitsViewBuilderV11Test(test.TestCase):
def setUp(self):
self.view_builder = views.limits.ViewBuilderV11()
- self.rate_limits = [
- {
- "URI": "*",
- "regex": ".*",
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "resetTime": 1311272226,
- },
- {
- "URI": "*/servers",
- "regex": "^/servers",
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "resetTime": 1311272226,
- },
- ]
- self.absolute_limits = {
- "metadata_items": 1,
- "injected_files": 5,
- "injected_file_content_bytes": 5,
- }
+ self.rate_limits = [{"URI": "*",
+ "regex": ".*",
+ "value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "resetTime": 1311272226},
+ {"URI": "*/servers",
+ "regex": "^/servers",
+ "value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "resetTime": 1311272226}]
+ self.absolute_limits = {"metadata_items": 1,
+ "injected_files": 5,
+ "injected_file_content_bytes": 5}
def tearDown(self):
pass
def test_build_limits(self):
- expected_limits = {
- "limits": {
- "rate": [
- {
- "uri": "*",
- "regex": ".*",
- "limit": [
- {
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-07-21T18:17:06Z",
- },
- ]
- },
- {
- "uri": "*/servers",
- "regex": "^/servers",
- "limit": [
- {
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "next-available": "2011-07-21T18:17:06Z",
- },
- ]
- },
- ],
- "absolute": {
- "maxServerMeta": 1,
- "maxImageMeta": 1,
- "maxPersonality": 5,
- "maxPersonalitySize": 5
- }
- }
- }
+ expected_limits = {"limits": {
+ "rate": [{
+ "uri": "*",
+ "regex": ".*",
+ "limit": [{"value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-07-21T18:17:06Z"}]},
+ {"uri": "*/servers",
+ "regex": "^/servers",
+ "limit": [{"value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "next-available": "2011-07-21T18:17:06Z"}]}],
+ "absolute": {"maxServerMeta": 1,
+ "maxImageMeta": 1,
+ "maxPersonality": 5,
+ "maxPersonalitySize": 5}}}
output = self.view_builder.build(self.rate_limits,
self.absolute_limits)
self.assertDictMatch(output, expected_limits)
def test_build_limits_empty_limits(self):
- expected_limits = {
- "limits": {
- "rate": [],
- "absolute": {},
- }
- }
+ expected_limits = {"limits": {"rate": [],
+ "absolute": {}}}
abs_limits = {}
rate_limits = []
@@ -1012,45 +982,28 @@ class LimitsXMLSerializationTest(test.TestCase):
def test_index(self):
serializer = limits.LimitsXMLSerializer()
-
- fixture = {
- "limits": {
- "rate": [
- {
- "uri": "*",
- "regex": ".*",
- "limit": [
- {
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-12-15T22:42:45Z",
- },
- ]
- },
- {
- "uri": "*/servers",
- "regex": "^/servers",
- "limit": [
- {
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "next-available": "2011-12-15T22:42:45Z"
- },
- ]
- },
- ],
- "absolute": {
- "maxServerMeta": 1,
- "maxImageMeta": 1,
- "maxPersonality": 5,
- "maxPersonalitySize": 10240
- }
- }
- }
+ fixture = {"limits": {
+ "rate": [{
+ "uri": "*",
+ "regex": ".*",
+ "limit": [{
+ "value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-12-15T22:42:45Z"}]},
+ {"uri": "*/servers",
+ "regex": "^/servers",
+ "limit": [{
+ "value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "next-available": "2011-12-15T22:42:45Z"}]}],
+ "absolute": {"maxServerMeta": 1,
+ "maxImageMeta": 1,
+ "maxPersonality": 5,
+ "maxPersonalitySize": 10240}}}
output = serializer.serialize(fixture, 'index')
actual = minidom.parseString(output.replace(" ", ""))
@@ -1083,12 +1036,9 @@ class LimitsXMLSerializationTest(test.TestCase):
def test_index_no_limits(self):
serializer = limits.LimitsXMLSerializer()
- fixture = {
- "limits": {
- "rate": [],
- "absolute": {},
- }
- }
+ fixture = {"limits": {
+ "rate": [],
+ "absolute": {}}}
output = serializer.serialize(fixture, 'index')
actual = minidom.parseString(output.replace(" ", ""))
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 1a4288ae7..a510d7d97 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -3056,8 +3056,7 @@ class ServersViewBuilderV11Test(test.TestCase):
address_builder,
flavor_builder,
image_builder,
- base_url,
- )
+ base_url)
return view_builder
def test_build_server(self):
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index d70a6779f..33461025f 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -644,10 +644,13 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(driver_i, '_live_migration_dest_check')
self.mox.StubOutWithMock(driver_i, '_live_migration_common_check')
driver_i._live_migration_src_check(nocare, nocare)
- driver_i._live_migration_dest_check(nocare, nocare, i_ref['host'])
- driver_i._live_migration_common_check(nocare, nocare, i_ref['host'])
+ driver_i._live_migration_dest_check(nocare, nocare,
+ i_ref['host'], False)
+ driver_i._live_migration_common_check(nocare, nocare,
+ i_ref['host'], False)
self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
- kwargs = {'instance_id': instance_id, 'dest': i_ref['host']}
+ kwargs = {'instance_id': instance_id, 'dest': i_ref['host'],
+ 'block_migration': False}
rpc.cast(self.context,
db.queue_get_for(nocare, FLAGS.compute_topic, i_ref['host']),
{"method": 'live_migration', "args": kwargs})
@@ -655,7 +658,8 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.scheduler.live_migration(self.context, FLAGS.compute_topic,
instance_id=instance_id,
- dest=i_ref['host'])
+ dest=i_ref['host'],
+ block_migration=False)
i_ref = db.instance_get(self.context, instance_id)
self.assertTrue(i_ref['state_description'] == 'migrating')
@@ -736,7 +740,7 @@ class SimpleDriverTestCase(test.TestCase):
self.assertRaises(exception.ComputeServiceUnavailable,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, i_ref['host'])
+ self.context, i_ref, i_ref['host'], False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -749,7 +753,7 @@ class SimpleDriverTestCase(test.TestCase):
self.assertRaises(exception.UnableToMigrateToSelf,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, i_ref['host'])
+ self.context, i_ref, i_ref['host'], False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -757,15 +761,33 @@ class SimpleDriverTestCase(test.TestCase):
def test_live_migration_dest_check_service_lack_memory(self):
"""Confirms exception raises when dest doesn't have enough memory."""
instance_id = self._create_instance()
+ instance_id2 = self._create_instance(host='somewhere',
+ memory_mb=12)
i_ref = db.instance_get(self.context, instance_id)
- s_ref = self._create_compute_service(host='somewhere',
- memory_mb_used=12)
+ s_ref = self._create_compute_service(host='somewhere')
+
+ self.assertRaises(exception.MigrationError,
+ self.scheduler.driver._live_migration_dest_check,
+ self.context, i_ref, 'somewhere', False)
+
+ db.instance_destroy(self.context, instance_id)
+ db.instance_destroy(self.context, instance_id2)
+ db.service_destroy(self.context, s_ref['id'])
+
+ def test_block_migration_dest_check_service_lack_disk(self):
+ """Confirms exception raises when dest doesn't have enough disk."""
+ instance_id = self._create_instance()
+ instance_id2 = self._create_instance(host='somewhere',
+ local_gb=70)
+ i_ref = db.instance_get(self.context, instance_id)
+ s_ref = self._create_compute_service(host='somewhere')
self.assertRaises(exception.MigrationError,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, 'somewhere')
+ self.context, i_ref, 'somewhere', True)
db.instance_destroy(self.context, instance_id)
+ db.instance_destroy(self.context, instance_id2)
db.service_destroy(self.context, s_ref['id'])
def test_live_migration_dest_check_service_works_correctly(self):
@@ -777,7 +799,8 @@ class SimpleDriverTestCase(test.TestCase):
ret = self.scheduler.driver._live_migration_dest_check(self.context,
i_ref,
- 'somewhere')
+ 'somewhere',
+ False)
self.assertTrue(ret is None)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -810,9 +833,10 @@ class SimpleDriverTestCase(test.TestCase):
"args": {'filename': fpath}})
self.mox.ReplayAll()
- self.assertRaises(exception.SourceHostUnavailable,
+ #self.assertRaises(exception.SourceHostUnavailable,
+ self.assertRaises(exception.FileNotFound,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -836,7 +860,7 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.InvalidHypervisorType,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -862,7 +886,7 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.DestinationHypervisorTooOld,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -894,7 +918,8 @@ class SimpleDriverTestCase(test.TestCase):
try:
self.scheduler.driver._live_migration_common_check(self.context,
i_ref,
- dest)
+ dest,
+ False)
except rpc.RemoteError, e:
c = (e.message.find(_("doesn't have compatibility to")) >= 0)
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 9d6e5aee5..e2fa3b140 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -714,11 +714,15 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}})
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}})
+
self.mox.StubOutWithMock(self.compute.driver, 'live_migration')
self.compute.driver.live_migration(c, i_ref, i_ref['host'],
self.compute.post_live_migration,
- self.compute.recover_live_migration)
+ self.compute.rollback_live_migration,
+ False)
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -739,13 +743,18 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}}).\
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}}).\
AndRaise(rpc.RemoteError('', '', ''))
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
'state': power_state.RUNNING,
'host': i_ref['host']})
for v in i_ref['volumes']:
dbmock.volume_update(c, v['id'], {'status': 'in-use'})
+ # mock for volume_api.remove_from_compute
+ rpc.call(c, topic, {"method": "remove_volume",
+ "args": {'volume_id': v['id']}})
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -766,7 +775,9 @@ class ComputeTestCase(test.TestCase):
AndReturn(topic)
self.mox.StubOutWithMock(rpc, 'call')
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}}).\
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}}).\
AndRaise(rpc.RemoteError('', '', ''))
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
'state': power_state.RUNNING,
@@ -791,11 +802,14 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}})
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}})
self.mox.StubOutWithMock(self.compute.driver, 'live_migration')
self.compute.driver.live_migration(c, i_ref, i_ref['host'],
self.compute.post_live_migration,
- self.compute.recover_live_migration)
+ self.compute.rollback_live_migration,
+ False)
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -829,6 +843,10 @@ class ComputeTestCase(test.TestCase):
self.compute.volume_manager.remove_compute_volume(c, v['id'])
self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance')
self.compute.driver.unfilter_instance(i_ref, [])
+ self.mox.StubOutWithMock(rpc, 'call')
+ rpc.call(c, db.queue_get_for(c, FLAGS.compute_topic, dest),
+ {"method": "post_live_migration_at_destination",
+ "args": {'instance_id': i_ref['id'], 'block_migration': False}})
# executing
self.mox.ReplayAll()
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 97f6aaec3..688518bb8 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -21,6 +21,7 @@ import os
import re
import shutil
import sys
+import tempfile
from xml.etree.ElementTree import fromstring as xml_to_tree
from xml.dom.minidom import parseString as xml_to_dom
@@ -696,17 +697,20 @@ class LibvirtConnTestCase(test.TestCase):
return vdmock
self.create_fake_libvirt_mock(lookupByName=fake_lookup)
- self.mox.StubOutWithMock(self.compute, "recover_live_migration")
- self.compute.recover_live_migration(self.context, instance_ref,
- dest='dest')
-
- # Start test
+# self.mox.StubOutWithMock(self.compute, "recover_live_migration")
+ self.mox.StubOutWithMock(self.compute, "rollback_live_migration")
+# self.compute.recover_live_migration(self.context, instance_ref,
+# dest='dest')
+ self.compute.rollback_live_migration(self.context, instance_ref,
+ 'dest', False)
+
+ #start test
self.mox.ReplayAll()
conn = connection.LibvirtConnection(False)
self.assertRaises(libvirt.libvirtError,
conn._live_migration,
- self.context, instance_ref, 'dest', '',
- self.compute.recover_live_migration)
+ self.context, instance_ref, 'dest', False,
+ self.compute.rollback_live_migration)
instance_ref = db.instance_get(self.context, instance_ref['id'])
self.assertTrue(instance_ref['state_description'] == 'running')
@@ -717,6 +721,95 @@ class LibvirtConnTestCase(test.TestCase):
db.volume_destroy(self.context, volume_ref['id'])
db.instance_destroy(self.context, instance_ref['id'])
+ def test_pre_block_migration_works_correctly(self):
+ """Confirms pre_block_migration works correctly."""
+
+ # Skip if non-libvirt environment
+ if not self.lazy_load_library_exists():
+ return
+
+ # Replace instances_path since this testcase creates tmpfile
+ tmpdir = tempfile.mkdtemp()
+ store = FLAGS.instances_path
+ FLAGS.instances_path = tmpdir
+
+ # Test data
+ instance_ref = db.instance_create(self.context, self.test_instance)
+ dummyjson = '[{"path": "%s/disk", "local_gb": "10G", "type": "raw"}]'
+
+ # Preparing mocks
+ # qemu-img should be mockd since test environment might not have
+ # large disk space.
+ self.mox.StubOutWithMock(utils, "execute")
+ utils.execute('sudo', 'qemu-img', 'create', '-f', 'raw',
+ '%s/%s/disk' % (tmpdir, instance_ref.name), '10G')
+
+ self.mox.ReplayAll()
+ conn = connection.LibvirtConnection(False)
+ conn.pre_block_migration(self.context, instance_ref,
+ dummyjson % tmpdir)
+
+ self.assertTrue(os.path.exists('%s/%s/' %
+ (tmpdir, instance_ref.name)))
+
+ shutil.rmtree(tmpdir)
+ db.instance_destroy(self.context, instance_ref['id'])
+ # Restore FLAGS.instances_path
+ FLAGS.instances_path = store
+
+ def test_get_instance_disk_info_works_correctly(self):
+ """Confirms pre_block_migration works correctly."""
+ # Skip if non-libvirt environment
+ if not self.lazy_load_library_exists():
+ return
+
+ # Test data
+ instance_ref = db.instance_create(self.context, self.test_instance)
+ dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
+ "<devices>"
+ "<disk type='file'><driver name='qemu' type='raw'/>"
+ "<source file='/test/disk'/>"
+ "<target dev='vda' bus='virtio'/></disk>"
+ "<disk type='file'><driver name='qemu' type='qcow2'/>"
+ "<source file='/test/disk.local'/>"
+ "<target dev='vdb' bus='virtio'/></disk>"
+ "</devices></domain>")
+
+ ret = ("image: /test/disk\nfile format: raw\n"
+ "virtual size: 20G (21474836480 bytes)\ndisk size: 3.1G\n")
+
+ # Preparing mocks
+ vdmock = self.mox.CreateMock(libvirt.virDomain)
+ self.mox.StubOutWithMock(vdmock, "XMLDesc")
+ vdmock.XMLDesc(0).AndReturn(dummyxml)
+
+ def fake_lookup(instance_name):
+ if instance_name == instance_ref.name:
+ return vdmock
+ self.create_fake_libvirt_mock(lookupByName=fake_lookup)
+
+ self.mox.StubOutWithMock(os.path, "getsize")
+ # based on above testdata, one is raw image, so getsize is mocked.
+ os.path.getsize("/test/disk").AndReturn(10 * 1024 * 1024 * 1024)
+ # another is qcow image, so qemu-img should be mocked.
+ self.mox.StubOutWithMock(utils, "execute")
+ utils.execute('sudo', 'qemu-img', 'info', '/test/disk.local').\
+ AndReturn((ret, ''))
+
+ self.mox.ReplayAll()
+ conn = connection.LibvirtConnection(False)
+ info = conn.get_instance_disk_info(self.context, instance_ref)
+ info = utils.loads(info)
+
+ self.assertTrue(info[0]['type'] == 'raw' and
+ info[1]['type'] == 'qcow2' and
+ info[0]['path'] == '/test/disk' and
+ info[1]['path'] == '/test/disk.local' and
+ info[0]['local_gb'] == '10G' and
+ info[1]['local_gb'] == '20G')
+
+ db.instance_destroy(self.context, instance_ref['id'])
+
def test_spawn_with_network_info(self):
# Skip if non-libvirt environment
if not self.lazy_load_library_exists():