Add block_device_mapping_get_all_by_instance to virtapi

Add another conductor api method to the virtapi.  This is needed by the
following patch: https://review.openstack.org/#/c/42812

Part of blueprint qemu-assisted-snapshots

Change-Id: I21d0ebe9f83423d504f7626f0d048b31945156d9
This commit is contained in:
Russell Bryant 2013-08-30 10:04:18 -04:00 committed by Eric Harney
parent 04eee47372
commit 1ed00ab0e9
4 changed files with 37 additions and 3 deletions

View File

@ -379,6 +379,12 @@ class ComputeVirtAPI(virtapi.VirtAPI):
return self._compute.conductor_api.instance_type_get(context,
instance_type_id)
def block_device_mapping_get_all_by_instance(self, context, instance,
legacy=True):
capi = self._compute.conductor_api
return capi.block_device_mapping_get_all_by_instance(context, instance,
legacy=legacy)
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""

View File

@ -75,6 +75,10 @@ class VirtAPIBaseTest(test.TestCase, test.APICoverage):
self.assertExpected('instance_type_get',
'fake-instance-type')
def test_block_device_mapping_get_all_by_instance(self):
self.assertExpected('block_device_mapping_get_all_by_instance',
{'uuid': 'fake_uuid'}, legacy=False)
class FakeVirtAPITest(VirtAPIBaseTest):
@ -97,13 +101,19 @@ class FakeVirtAPITest(VirtAPIBaseTest):
# NOTE(danms): FakeVirtAPI will convert the first argument to
# argument['id'], so expect that in the actual db call
e_args = tuple([args[0]['id']] + list(args[1:]))
elif method in ('test_security_group_get_by_instance'):
elif method in ('security_group_get_by_instance',
'block_device_mapping_get_all_by_instance'):
e_args = tuple([args[0]['uuid']] + list(args[1:]))
else:
e_args = args
getattr(db, db_method)(self.context, *e_args, **kwargs).AndReturn(
'it worked')
if method in ('block_device_mapping_get_all_by_instance'):
e_kwargs = {}
else:
e_kwargs = kwargs
getattr(db, db_method)(self.context, *e_args, **e_kwargs).AndReturn(
'it worked')
self.mox.ReplayAll()
result = getattr(self.virtapi, method)(self.context, *args, **kwargs)
self.assertEqual(result, 'it worked')

View File

@ -27,6 +27,7 @@ semantics of real hypervisor connections.
from oslo.config import cfg
from nova import block_device
from nova.compute import power_state
from nova.compute import task_states
from nova import db
@ -490,3 +491,11 @@ class FakeVirtAPI(virtapi.VirtAPI):
def instance_type_get(self, context, instance_type_id):
return db.instance_type_get(context, instance_type_id)
def block_device_mapping_get_all_by_instance(self, context, instance,
legacy=True):
bdms = db.block_device_mapping_get_all_by_instance(context,
instance['uuid'])
if legacy:
bdms = block_device.legacy_mapping(bdms)
return bdms

View File

@ -90,3 +90,12 @@ class VirtAPI(object):
:param instance_type_id: the id of the instance type in question
"""
raise NotImplementedError()
def block_device_mapping_get_all_by_instance(self, context, instance,
legacy=True):
"""Get block device mappings for an instance
:param context: security context
:param instance: the instance we're getting bdms for
:param legacy: get bdm info in legacy format (or not)
"""
raise NotImplementedError()