Make nova/virt use aggregate['metadetails']

This patch makes nova/virt use the metadata attached to the
aggregate object instead of querying it separately. This allows
us to remove a method from VirtAPI and avoid adding another one to
conductor to support it.

Change-Id: I4b9ff59147d30ff6f71fa66e838f060b8853dc95
This commit is contained in:
Dan Smith 2012-12-10 12:55:27 -08:00
parent 07848e761a
commit 3f6a2d1621
5 changed files with 23 additions and 44 deletions

View File

@ -268,9 +268,6 @@ class ComputeVirtAPI(virtapi.VirtAPI):
def aggregate_get_by_host(self, context, host, key=None):
return self._compute.db.aggregate_get_by_host(context, host, key=key)
def aggregate_metadata_get(self, context, aggregate_id):
return self._compute.db.aggregate_metadata_get(context, aggregate_id)
def aggregate_metadata_add(self, context, aggregate_id, metadata,
set_delete=False):
return self._compute.db.aggregate_metadata_add(context, aggregate_id,

View File

@ -2399,23 +2399,31 @@ class ResourcePoolWithStubs(StubDependencies, pool.ResourcePool):
class HypervisorPoolTestCase(test.TestCase):
fake_aggregate = {
'id': 98,
'hosts': [],
'metadetails': {
'master_compute': 'master',
pool_states.POOL_FLAG: {},
pool_states.KEY: {}
}
}
def test_slave_asks_master_to_add_slave_to_pool(self):
slave = ResourcePoolWithStubs()
aggregate = {'id': 98, 'hosts': []}
slave.add_to_aggregate("CONTEXT", aggregate, "slave")
slave.add_to_aggregate("CONTEXT", self.fake_aggregate, "slave")
self.assertIn(
(slave.compute_rpcapi.add_aggregate_host,
"CONTEXT", jsonutils.to_primitive(aggregate),
"CONTEXT", jsonutils.to_primitive(self.fake_aggregate),
"slave", "master", "SLAVE_INFO"),
slave.compute_rpcapi._mock_calls)
def test_slave_asks_master_to_remove_slave_from_pool(self):
slave = ResourcePoolWithStubs()
aggregate = {'id': 98, 'hosts': []}
slave.remove_from_aggregate("CONTEXT", aggregate, "slave")
slave.remove_from_aggregate("CONTEXT", self.fake_aggregate, "slave")
self.assertIn(
(slave.compute_rpcapi.remove_aggregate_host,

View File

@ -412,9 +412,6 @@ class FakeVirtAPI(virtapi.VirtAPI):
def aggregate_get_by_host(self, context, host, key=None):
return db.aggregate_get_by_host(context, host, key)
def aggregate_metadata_get(self, context, aggregate_id):
return db.aggregate_metadata_get(context, aggregate_id)
def aggregate_metadata_add(self, context, aggregate_id, metadata,
set_delete=False):
return db.aggregate_metadata_add(context, aggregate_id, metadata,

View File

@ -48,14 +48,6 @@ class VirtAPI(object):
"""
raise NotImplementedError()
def aggregate_metadata_get(self, context, aggregate_id):
"""Get metadata for the specified aggregate
:param context: security context
:param aggregate_id: id of aggregate for which metadata is to
be returned
"""
raise NotImplementedError()
def aggregate_metadata_add(self, context, aggregate_id, metadata,
set_delete=False):
"""Add/update metadata for specified aggregate

View File

@ -57,13 +57,6 @@ class ResourcePool(object):
self._virtapi = virtapi
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
def _is_hv_pool(self, context, aggregate_id):
return pool_states.is_hv_pool(
self._virtapi.aggregate_metadata_get(context, aggregate_id))
def _get_metadata(self, context, aggregate_id):
return self._virtapi.aggregate_metadata_get(context, aggregate_id)
def undo_aggregate_operation(self, context, op, aggregate,
host, set_error):
"""Undo aggregate operation when pool error raised"""
@ -80,24 +73,20 @@ class ResourcePool(object):
def add_to_aggregate(self, context, aggregate, host, slave_info=None):
"""Add a compute host to an aggregate."""
if not self._is_hv_pool(context, aggregate['id']):
if not pool_states.is_hv_pool(aggregate['metadetails']):
return
invalid = {pool_states.CHANGING: 'setup in progress',
pool_states.DISMISSED: 'aggregate deleted',
pool_states.ERROR: 'aggregate in error'}
if (self._get_metadata(context, aggregate['id'])[pool_states.KEY]
in invalid.keys()):
if (aggregate['metadetails'][pool_states.KEY] in invalid.keys()):
raise exception.InvalidAggregateAction(
action='add host',
aggregate_id=aggregate['id'],
reason=invalid[self._get_metadata(context,
aggregate['id'])
[pool_states.KEY]])
reason=aggregate['metadetails'][pool_states.KEY])
if (self._get_metadata(context, aggregate['id'])[pool_states.KEY]
== pool_states.CREATED):
if (aggregate['metadetails'][pool_states.KEY] == pool_states.CREATED):
self._virtapi.aggregate_metadata_add(context, aggregate['id'],
{pool_states.KEY:
pool_states.CHANGING})
@ -113,8 +102,7 @@ class ResourcePool(object):
else:
# the pool is already up and running, we need to figure out
# whether we can serve the request from this host or not.
master_compute = self._get_metadata(context,
aggregate['id'])['master_compute']
master_compute = aggregate['metadetails']['master_compute']
if master_compute == CONF.host and master_compute != host:
# this is the master -> do a pool-join
# To this aim, nova compute on the slave has to go down.
@ -137,25 +125,22 @@ class ResourcePool(object):
def remove_from_aggregate(self, context, aggregate, host, slave_info=None):
"""Remove a compute host from an aggregate."""
slave_info = slave_info or dict()
if not self._is_hv_pool(context, aggregate['id']):
if not pool_states.is_hv_pool(aggregate['metadetails']):
return
invalid = {pool_states.CREATED: 'no hosts to remove',
pool_states.CHANGING: 'setup in progress',
pool_states.DISMISSED: 'aggregate deleted', }
if (self._get_metadata(context, aggregate['id'])[pool_states.KEY]
in invalid.keys()):
if aggregate['metadetails'][pool_states.KEY] in invalid.keys():
raise exception.InvalidAggregateAction(
action='remove host',
aggregate_id=aggregate['id'],
reason=invalid[self._get_metadata(context,
aggregate['id'])[pool_states.KEY]])
reason=invalid[aggregate['metadetails'][pool_states.KEY]])
master_compute = self._get_metadata(context,
aggregate['id'])['master_compute']
master_compute = aggregate['metadetails']['master_compute']
if master_compute == CONF.host and master_compute != host:
# this is the master -> instruct it to eject a host from the pool
host_uuid = self._get_metadata(context, aggregate['id'])[host]
host_uuid = aggregate['metadetails'][host]
self._eject_slave(aggregate['id'],
slave_info.get('compute_uuid'), host_uuid)
self._virtapi.aggregate_metadata_delete(context, aggregate['id'],