summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2012-12-10 12:55:27 -0800
committerDan Smith <danms@us.ibm.com>2012-12-10 16:14:23 -0800
commit3f6a2d1621ce4bdca4fb95d561e1dd703c0737bd (patch)
tree422382376db216e875e6543705fc1a2028380aab
parent07848e761a13afaf44c58d99ceb6a133e6999470 (diff)
downloadnova-3f6a2d1621ce4bdca4fb95d561e1dd703c0737bd.tar.gz
nova-3f6a2d1621ce4bdca4fb95d561e1dd703c0737bd.tar.xz
nova-3f6a2d1621ce4bdca4fb95d561e1dd703c0737bd.zip
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
-rw-r--r--nova/compute/manager.py3
-rw-r--r--nova/tests/test_xenapi.py18
-rw-r--r--nova/virt/fake.py3
-rw-r--r--nova/virt/virtapi.py8
-rw-r--r--nova/virt/xenapi/pool.py35
5 files changed, 23 insertions, 44 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index ce2642b13..3b315ef81 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -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,
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index f570e9959..b226b34df 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -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,
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index fb1ed5558..c354b34d8 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -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,
diff --git a/nova/virt/virtapi.py b/nova/virt/virtapi.py
index 85e638add..59a4006a6 100644
--- a/nova/virt/virtapi.py
+++ b/nova/virt/virtapi.py
@@ -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
diff --git a/nova/virt/xenapi/pool.py b/nova/virt/xenapi/pool.py
index 0be6fad12..8d0e0a91c 100644
--- a/nova/virt/xenapi/pool.py
+++ b/nova/virt/xenapi/pool.py
@@ -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'],