summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_compute.py41
-rw-r--r--nova/tests/test_libvirt.py14
2 files changed, 52 insertions, 3 deletions
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 6b74a14f0..543f6823c 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -1995,6 +1995,47 @@ class ComputeAPITestCase(BaseTestCase):
self.compute_api.add_fixed_ip(self.context, instance, '1')
self.compute_api.remove_fixed_ip(self.context, instance, '192.168.1.1')
+ def test_attach_volume_invalid(self):
+ self.assertRaises(exception.ApiError,
+ self.compute_api.attach_volume,
+ None,
+ None,
+ None,
+ '/dev/invalid')
+
+ def test_attach_volume(self):
+ instance_id = 1
+ volume_id = 1
+
+ for device in ('/dev/sda', '/dev/xvda'):
+ # creating mocks
+ self.mox.StubOutWithMock(self.compute_api.volume_api,
+ 'check_attach')
+ self.mox.StubOutWithMock(self.compute_api, 'get')
+ self.mox.StubOutWithMock(rpc, 'cast')
+
+ rpc.cast(
+ mox.IgnoreArg(),
+ mox.IgnoreArg(), {"method": "attach_volume",
+ "args": {'volume_id': volume_id,
+ 'instance_id': instance_id,
+ 'mountpoint': device}})
+
+ self.compute_api.volume_api.check_attach(
+ mox.IgnoreArg(),
+ volume_id=volume_id).AndReturn(
+ {'id': volume_id, 'status': 'available',
+ 'attach_status': 'detached'})
+
+ self.compute_api.get(
+ mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn({'id': instance_id,
+ 'host': 'fake'})
+
+ self.mox.ReplayAll()
+ self.compute_api.attach_volume(None, None, volume_id, device)
+ self.mox.UnsetStubs()
+
def test_vnc_console(self):
"""Make sure we can a vnc console for an instance."""
def vnc_rpc_call_wrapper(*args, **kwargs):
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 6420aa01c..61ba21692 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -109,11 +109,19 @@ class LibvirtVolumeTestCase(test.TestCase):
super(LibvirtVolumeTestCase, self).setUp()
self.stubs.Set(utils, 'execute', self.fake_execute)
+ class FakeLibvirtConnection(object):
+ def __init__(self, hyperv="QEMU"):
+ self.hyperv = hyperv
+
+ def get_hypervisor_type(self):
+ return self.hyperv
+ self.fake_conn = FakeLibvirtConnection("Xen")
+
def test_libvirt_iscsi_driver(self):
# NOTE(vish) exists is to make driver assume connecting worked
self.stubs.Set(os.path, 'exists', lambda x: True)
vol_driver = volume_driver.ISCSIDriver()
- libvirt_driver = volume.LibvirtISCSIVolumeDriver('fake')
+ libvirt_driver = volume.LibvirtISCSIVolumeDriver(self.fake_conn)
name = 'volume-00000001'
vol = {'id': 1,
'name': name,
@@ -133,7 +141,7 @@ class LibvirtVolumeTestCase(test.TestCase):
def test_libvirt_sheepdog_driver(self):
vol_driver = volume_driver.SheepdogDriver()
- libvirt_driver = volume.LibvirtNetVolumeDriver('fake')
+ libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
name = 'volume-00000001'
vol = {'id': 1, 'name': name}
address = '127.0.0.1'
@@ -148,7 +156,7 @@ class LibvirtVolumeTestCase(test.TestCase):
def test_libvirt_rbd_driver(self):
vol_driver = volume_driver.RBDDriver()
- libvirt_driver = volume.LibvirtNetVolumeDriver('fake')
+ libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
name = 'volume-00000001'
vol = {'id': 1, 'name': name}
address = '127.0.0.1'