Convert nova.volume.api.API to use volume objects
Change-Id: If6b78f7de814116bc93b273ec300dba02e63593d
This commit is contained in:
@@ -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()
|
||||
|
@@ -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):
|
||||
|
@@ -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
|
||||
|
@@ -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. """
|
||||
|
@@ -246,9 +246,9 @@ class API(base.Base):
|
||||
|
||||
vol_ref = self.volume_api.create(context,
|
||||
vol_size,
|
||||
None,
|
||||
vol_name,
|
||||
vol['description'],
|
||||
None,
|
||||
volume_type=vol_type,
|
||||
metadata=dict(to_vsa_id=str(vsa_id)),
|
||||
availability_zone=availability_zone)
|
||||
@@ -349,7 +349,7 @@ class API(base.Base):
|
||||
vol_name = volume['name']
|
||||
LOG.info(_("VSA ID %(vsa_id)s: Deleting %(direction)s "\
|
||||
"volume %(vol_name)s"), locals())
|
||||
self.volume_api.delete(context, volume['id'])
|
||||
self.volume_api.delete(context, volume)
|
||||
except exception.ApiError:
|
||||
LOG.info(_("Unable to delete volume %s"), volume['name'])
|
||||
if force_delete:
|
||||
|
@@ -136,7 +136,7 @@ class VsaManager(manager.SchedulerDependentManager):
|
||||
locals())
|
||||
if status == 'available':
|
||||
try:
|
||||
# self.volume_api.update(context, volume['id'],
|
||||
# self.volume_api.update(context, volume,
|
||||
# dict(attach_status="attached"))
|
||||
pass
|
||||
except Exception as ex:
|
||||
|
Reference in New Issue
Block a user