summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-01-13 11:22:50 -0800
committerBrian Waldon <bcwaldon@gmail.com>2012-01-13 16:59:50 -0800
commitbb10721ffc14abb86ab4d58b2b30fc676e88d394 (patch)
tree22da01aef372d76efd580a6d6afe495bed23dd5c /nova/tests
parenta51c93ab3c646642330c4eeba3ede0772a8ab734 (diff)
Convert nova.volume.api.API to use volume objects
Change-Id: If6b78f7de814116bc93b273ec300dba02e63593d
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/ec2/test_cloud.py1
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_vsa.py13
-rw-r--r--nova/tests/test_compute.py40
-rw-r--r--nova/tests/test_quota.py12
-rw-r--r--nova/tests/test_volume.py81
-rw-r--r--nova/tests/test_vsa.py2
-rw-r--r--nova/tests/test_vsa_volumes.py13
7 files changed, 65 insertions, 97 deletions
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index 9af1c14c8..d4e4d7d1a 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -1735,6 +1735,7 @@ class CloudTestCase(test.TestCase):
for snapshot_id in (ec2_snapshot1_id, ec2_snapshot2_id):
self.cloud.delete_snapshot(self.context, snapshot_id)
+
db.volume_destroy(self.context, vol['id'])
def test_create_image(self):
diff --git a/nova/tests/api/openstack/compute/contrib/test_vsa.py b/nova/tests/api/openstack/compute/contrib/test_vsa.py
index e19aeedba..ce5ada2a6 100644
--- a/nova/tests/api/openstack/compute/contrib/test_vsa.py
+++ b/nova/tests/api/openstack/compute/contrib/test_vsa.py
@@ -251,24 +251,25 @@ def stub_get_vsa_volume_type(self, context):
'extra_specs': {'type': 'vsa_volume'}}
-def stub_volume_create(self, context, size, snapshot_id, name, description,
+def stub_volume_create(self, context, size, name, description, snapshot,
**param):
LOG.debug(_("_create: param=%s"), size)
vol = _get_default_volume_param()
vol['size'] = size
vol['display_name'] = name
vol['display_description'] = description
- vol['snapshot_id'] = snapshot_id
+ try:
+ vol['snapshot_id'] = snapshot['id']
+ except (KeyError, TypeError):
+ vol['snapshot_id'] = None
return vol
-def stub_volume_update(self, context, **param):
- LOG.debug(_("_volume_update: param=%s"), param)
+def stub_volume_update(self, context, *args, **param):
pass
-def stub_volume_delete(self, context, **param):
- LOG.debug(_("_volume_delete: param=%s"), param)
+def stub_volume_delete(self, context, *args, **param):
pass
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index bf36e7431..06eaf8ef5 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -2828,42 +2828,6 @@ class ComputeAPITestCase(BaseTestCase):
None,
'/dev/invalid')
- def test_attach_volume(self):
- instance_id = 1
- instance_uuid = utils.gen_uuid()
- 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_uuid': instance_uuid,
- '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,
- 'uuid': instance_uuid,
- '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):
@@ -2896,6 +2860,10 @@ class ComputeAPITestCase(BaseTestCase):
def fake_check_attach(*args, **kwargs):
pass
+ def fake_volume_get(self, context, volume_id):
+ return {'id': volume_id}
+
+ self.stubs.Set(nova.volume.api.API, 'get', fake_volume_get)
self.stubs.Set(nova.volume.api.API, 'check_attach', fake_check_attach)
instance = self._create_fake_instance()
diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py
index 83c9e36df..6f2f1161b 100644
--- a/nova/tests/test_quota.py
+++ b/nova/tests/test_quota.py
@@ -251,11 +251,7 @@ class QuotaTestCase(test.TestCase):
volume_ids.append(volume_id)
self.assertRaises(exception.QuotaError,
volume.API().create,
- self.context,
- size=10,
- snapshot_id=None,
- name='',
- description='')
+ self.context, 10, '', '', None)
for volume_id in volume_ids:
db.volume_destroy(self.context, volume_id)
@@ -265,11 +261,7 @@ class QuotaTestCase(test.TestCase):
volume_ids.append(volume_id)
self.assertRaises(exception.QuotaError,
volume.API().create,
- self.context,
- size=10,
- snapshot_id=None,
- name='',
- description='')
+ self.context, 10, '', '', None)
for volume_id in volume_ids:
db.volume_destroy(self.context, volume_id)
diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py
index 6c81facf8..aeefcd020 100644
--- a/nova/tests/test_volume.py
+++ b/nova/tests/test_volume.py
@@ -30,7 +30,7 @@ from nova import log as logging
from nova import rpc
from nova import test
from nova import utils
-from nova import volume
+import nova.volume.api
FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.tests.volume')
@@ -62,11 +62,12 @@ class VolumeTestCase(test.TestCase):
vol['availability_zone'] = FLAGS.storage_availability_zone
vol['status'] = "creating"
vol['attach_status'] = "detached"
- return db.volume_create(context.get_admin_context(), vol)['id']
+ return db.volume_create(context.get_admin_context(), vol)
def test_create_delete_volume(self):
"""Test volume can be created and deleted."""
- volume_id = self._create_volume()
+ volume = self._create_volume()
+ volume_id = volume['id']
self.volume.create_volume(self.context, volume_id)
self.assertEqual(volume_id, db.volume_get(context.get_admin_context(),
volume_id).id)
@@ -79,22 +80,24 @@ class VolumeTestCase(test.TestCase):
def test_create_volume_from_snapshot(self):
"""Test volume can be created from a snapshot."""
- volume_src_id = self._create_volume()
- self.volume.create_volume(self.context, volume_src_id)
- snapshot_id = self._create_snapshot(volume_src_id)
- self.volume.create_snapshot(self.context, volume_src_id, snapshot_id)
- volume_dst_id = self._create_volume(0, snapshot_id)
- self.volume.create_volume(self.context, volume_dst_id, snapshot_id)
- self.assertEqual(volume_dst_id, db.volume_get(
- context.get_admin_context(),
- volume_dst_id).id)
+ volume_src = self._create_volume()
+ self.volume.create_volume(self.context, volume_src['id'])
+ snapshot_id = self._create_snapshot(volume_src['id'])
+ self.volume.create_snapshot(self.context, volume_src['id'],
+ snapshot_id)
+ volume_dst = self._create_volume(0, snapshot_id)
+ self.volume.create_volume(self.context, volume_dst['id'], snapshot_id)
+ self.assertEqual(volume_dst['id'],
+ db.volume_get(
+ context.get_admin_context(),
+ volume_dst['id']).id)
self.assertEqual(snapshot_id, db.volume_get(
context.get_admin_context(),
- volume_dst_id).snapshot_id)
+ volume_dst['id']).snapshot_id)
- self.volume.delete_volume(self.context, volume_dst_id)
+ self.volume.delete_volume(self.context, volume_dst['id'])
self.volume.delete_snapshot(self.context, snapshot_id)
- self.volume.delete_volume(self.context, volume_src_id)
+ self.volume.delete_volume(self.context, volume_src['id'])
def test_too_big_volume(self):
"""Ensure failure if a too large of a volume is requested."""
@@ -102,8 +105,8 @@ class VolumeTestCase(test.TestCase):
# volume_create
return True
try:
- volume_id = self._create_volume('1001')
- self.volume.create_volume(self.context, volume_id)
+ volume = self._create_volume('1001')
+ self.volume.create_volume(self.context, volume)
self.fail("Should have thrown TypeError")
except TypeError:
pass
@@ -113,15 +116,15 @@ class VolumeTestCase(test.TestCase):
vols = []
total_slots = FLAGS.iscsi_num_targets
for _index in xrange(total_slots):
- volume_id = self._create_volume()
- self.volume.create_volume(self.context, volume_id)
- vols.append(volume_id)
- volume_id = self._create_volume()
+ volume = self._create_volume()
+ self.volume.create_volume(self.context, volume['id'])
+ vols.append(volume['id'])
+ volume = self._create_volume()
self.assertRaises(db.NoMoreTargets,
self.volume.create_volume,
self.context,
- volume_id)
- db.volume_destroy(context.get_admin_context(), volume_id)
+ volume['id'])
+ db.volume_destroy(context.get_admin_context(), volume['id'])
for volume_id in vols:
self.volume.delete_volume(self.context, volume_id)
@@ -137,7 +140,8 @@ class VolumeTestCase(test.TestCase):
inst['ami_launch_index'] = 0
instance_id = db.instance_create(self.context, inst)['id']
mountpoint = "/dev/sdf"
- volume_id = self._create_volume()
+ volume = self._create_volume()
+ volume_id = volume['id']
self.volume.create_volume(self.context, volume_id)
if FLAGS.fake_tests:
db.volume_attached(self.context, volume_id, instance_id,
@@ -190,8 +194,8 @@ class VolumeTestCase(test.TestCase):
LOG.debug(_("Target %s allocated"), iscsi_target)
total_slots = FLAGS.iscsi_num_targets
for _index in xrange(total_slots):
- volume_id = self._create_volume()
- d = self.volume.create_volume(self.context, volume_id)
+ volume = self._create_volume()
+ d = self.volume.create_volume(self.context, volume['id'])
_check(d)
for volume_id in volume_ids:
self.volume.delete_volume(self.context, volume_id)
@@ -215,10 +219,10 @@ class VolumeTestCase(test.TestCase):
def test_create_delete_snapshot(self):
"""Test snapshot can be created and deleted."""
- volume_id = self._create_volume()
- self.volume.create_volume(self.context, volume_id)
- snapshot_id = self._create_snapshot(volume_id)
- self.volume.create_snapshot(self.context, volume_id, snapshot_id)
+ volume = self._create_volume()
+ self.volume.create_volume(self.context, volume['id'])
+ snapshot_id = self._create_snapshot(volume['id'])
+ self.volume.create_snapshot(self.context, volume['id'], snapshot_id)
self.assertEqual(snapshot_id,
db.snapshot_get(context.get_admin_context(),
snapshot_id).id)
@@ -228,7 +232,7 @@ class VolumeTestCase(test.TestCase):
db.snapshot_get,
self.context,
snapshot_id)
- self.volume.delete_volume(self.context, volume_id)
+ self.volume.delete_volume(self.context, volume['id'])
def test_create_snapshot_force(self):
"""Test snapshot in use can be created forcibly."""
@@ -237,22 +241,23 @@ class VolumeTestCase(test.TestCase):
pass
self.stubs.Set(rpc, 'cast', fake_cast)
- volume_id = self._create_volume()
- self.volume.create_volume(self.context, volume_id)
- db.volume_attached(self.context, volume_id, self.instance_id,
+ volume = self._create_volume()
+ self.volume.create_volume(self.context, volume['id'])
+ db.volume_attached(self.context, volume['id'], self.instance_id,
'/dev/sda1')
- volume_api = volume.api.API()
+ volume_api = nova.volume.api.API()
+ volume = volume_api.get(self.context, volume['id'])
self.assertRaises(exception.ApiError,
volume_api.create_snapshot,
- self.context, volume_id,
+ self.context, volume,
'fake_name', 'fake_description')
snapshot_ref = volume_api.create_snapshot_force(self.context,
- volume_id,
+ volume,
'fake_name',
'fake_description')
db.snapshot_destroy(self.context, snapshot_ref['id'])
- db.volume_destroy(self.context, volume_id)
+ db.volume_destroy(self.context, volume['id'])
class DriverTestCase(test.TestCase):
diff --git a/nova/tests/test_vsa.py b/nova/tests/test_vsa.py
index d7c8f09f5..132874616 100644
--- a/nova/tests/test_vsa.py
+++ b/nova/tests/test_vsa.py
@@ -24,7 +24,6 @@ from nova import flags
from nova import log as logging
from nova import test
from nova import vsa
-from nova import volume
from nova.volume import volume_types
from nova.vsa import utils as vsa_utils
@@ -40,7 +39,6 @@ class VsaTestCase(test.TestCase):
super(VsaTestCase, self).setUp()
self.stubs = stubout.StubOutForTesting()
self.vsa_api = vsa.API()
- self.volume_api = volume.API()
FLAGS.quota_volumes = 100
FLAGS.quota_gigabytes = 10000
diff --git a/nova/tests/test_vsa_volumes.py b/nova/tests/test_vsa_volumes.py
index ef6396ff4..7840dd481 100644
--- a/nova/tests/test_vsa_volumes.py
+++ b/nova/tests/test_vsa_volumes.py
@@ -56,7 +56,7 @@ class VsaVolumesTestCase(test.TestCase):
def _default_volume_param(self):
return {
'size': 1,
- 'snapshot_id': None,
+ 'snapshot': None,
'name': 'Test volume name',
'description': 'Test volume desc name',
'volume_type': self.default_vol_type,
@@ -95,8 +95,10 @@ class VsaVolumesTestCase(test.TestCase):
'creating')
self.volume_api.update(self.context,
- volume_ref['id'], {'status': 'available'})
- self.volume_api.delete(self.context, volume_ref['id'])
+ volume_ref,
+ {'status': 'available'})
+ volume_ref = self.volume_api.get(self.context, volume_ref['id'])
+ self.volume_api.delete(self.context, volume_ref)
vols3 = self._get_all_volumes_by_vsa()
self.assertEqual(1, len(vols2))
@@ -110,10 +112,11 @@ class VsaVolumesTestCase(test.TestCase):
volume_ref = self.volume_api.create(self.context, **volume_param)
self.volume_api.update(self.context,
- volume_ref['id'], {'status': 'in-use'})
+ volume_ref,
+ {'status': 'in-use'})
self.assertRaises(exception.ApiError,
self.volume_api.delete,
- self.context, volume_ref['id'])
+ self.context, volume_ref)
def test_vsa_volume_delete_vsa_with_volumes(self):
""" Check volume deleton in different states. """