summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-06-06 15:59:20 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-06-06 15:59:20 -0400
commit9fca0b2156f1e7f3d007916ef18b2ed9fbc761df (patch)
tree857d74864232a81eead0977a96aaafd49ac93043
parent14cd6f4f506588006104277132c7bae416381e45 (diff)
downloadnova-9fca0b2156f1e7f3d007916ef18b2ed9fbc761df.tar.gz
nova-9fca0b2156f1e7f3d007916ef18b2ed9fbc761df.tar.xz
nova-9fca0b2156f1e7f3d007916ef18b2ed9fbc761df.zip
Added test case for snapshoting base image without architecture.
-rw-r--r--nova/tests/test_libvirt.py92
1 files changed, 66 insertions, 26 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index b6b36745a..d0bdaa738 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import copy
import eventlet
import mox
import os
@@ -125,6 +126,7 @@ class CacheConcurrencyTestCase(test.TestCase):
class LibvirtConnTestCase(test.TestCase):
+
def setUp(self):
super(LibvirtConnTestCase, self).setUp()
connection._late_load_cheetah()
@@ -207,6 +209,31 @@ class LibvirtConnTestCase(test.TestCase):
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
connection.LibvirtConnection._conn = fake
+ def fake_lookup(self, instance_name):
+ class FakeVirtDomain(object):
+
+ def __init__(self):
+ pass
+
+ def snapshotCreateXML(self, *args):
+ return None
+
+ def XMLDesc(self, *args):
+ return """
+ <domain type='kvm'>
+ <devices>
+ <disk type='file'>
+ <source file='filename'/>
+ </disk>
+ </devices>
+ </domain>
+ """
+
+ return FakeVirtDomain()
+
+ def fake_execute(self, *args):
+ open(args[-1], "a").close()
+
def create_service(self, **kwargs):
service_ref = {'host': kwargs.get('host', 'dummy'),
'binary': 'nova-compute',
@@ -283,43 +310,56 @@ class LibvirtConnTestCase(test.TestCase):
self._check_xml_and_container(instance_data)
def test_snapshot(self):
+ if not self.lazy_load_library_exists():
+ return
+
FLAGS.image_service = 'nova.image.fake.FakeImageService'
- # Only file-based instance storages are supported at the moment
- test_xml = """
- <domain type='kvm'>
- <devices>
- <disk type='file'>
- <source file='filename'/>
- </disk>
- </devices>
- </domain>
- """
+ # Start test
+ image_service = utils.import_object(FLAGS.image_service)
- class FakeVirtDomain(object):
+ # Assuming that base image already exists in image_service
+ instance_ref = db.instance_create(self.context, self.test_instance)
+ properties = {'instance_id': instance_ref['id'],
+ 'user_id': str(self.context.user_id)}
+ snapshot_name = 'test-snap'
+ sent_meta = {'name': snapshot_name, 'is_public': False,
+ 'status': 'creating', 'properties': properties}
+ # Create new image. It will be updated in snapshot method
+ # To work with it from snapshot, the single image_service is needed
+ recv_meta = image_service.create(context, sent_meta)
- def __init__(self):
- pass
+ self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
+ connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
+ self.mox.StubOutWithMock(connection.utils, 'execute')
+ connection.utils.execute = self.fake_execute
- def snapshotCreateXML(self, *args):
- return None
+ self.mox.ReplayAll()
- def XMLDesc(self, *args):
- return test_xml
+ conn = connection.LibvirtConnection(False)
+ conn.snapshot(instance_ref, recv_meta['id'])
- def fake_lookup(instance_name):
- if instance_name == instance_ref.name:
- return FakeVirtDomain()
+ snapshot = image_service.show(context, recv_meta['id'])
+ self.assertEquals(snapshot['properties']['image_state'], 'available')
+ self.assertEquals(snapshot['status'], 'active')
+ self.assertEquals(snapshot['name'], snapshot_name)
- def fake_execute(*args):
- # Touch filename to pass 'with open(out_path)'
- open(args[-1], "a").close()
+ def test_snapshot_no_image_architecture(self):
+ if not self.lazy_load_library_exists():
+ return
+
+ FLAGS.image_service = 'nova.image.fake.FakeImageService'
# Start test
image_service = utils.import_object(FLAGS.image_service)
+ # Assign image_ref = 2 from nova/images/fakes for testing different
+ # base image
+ test_instance = copy.deepcopy(self.test_instance)
+ test_instance["image_ref"] = "2"
+
# Assuming that base image already exists in image_service
- instance_ref = db.instance_create(self.context, self.test_instance)
+ instance_ref = db.instance_create(self.context, test_instance)
properties = {'instance_id': instance_ref['id'],
'user_id': str(self.context.user_id)}
snapshot_name = 'test-snap'
@@ -330,9 +370,9 @@ class LibvirtConnTestCase(test.TestCase):
recv_meta = image_service.create(context, sent_meta)
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
- connection.LibvirtConnection._conn.lookupByName = fake_lookup
+ connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
self.mox.StubOutWithMock(connection.utils, 'execute')
- connection.utils.execute = fake_execute
+ connection.utils.execute = self.fake_execute
self.mox.ReplayAll()