summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-04-10 22:32:02 +0000
committerGerrit Code Review <review@openstack.org>2013-04-10 22:32:02 +0000
commit7abb96db7410f0e46be3e470cb282d385a8964f3 (patch)
tree2fda24cd54832b81330f286743a747968deb01fe
parent32456dc736b834eab1d534eecca5edeef5086d6d (diff)
parentba9cd2a545a0c198990f649b6a2985a22102930f (diff)
downloadnova-7abb96db7410f0e46be3e470cb282d385a8964f3.tar.gz
nova-7abb96db7410f0e46be3e470cb282d385a8964f3.tar.xz
nova-7abb96db7410f0e46be3e470cb282d385a8964f3.zip
Merge "Change DB API instance functions for selective metadata fetching"
-rw-r--r--nova/conductor/api.py25
-rw-r--r--nova/conductor/manager.py15
-rw-r--r--nova/conductor/rpcapi.py16
-rw-r--r--nova/db/api.py4
-rw-r--r--nova/db/sqlalchemy/api.py5
-rw-r--r--nova/tests/conductor/test_conductor.py25
6 files changed, 55 insertions, 35 deletions
diff --git a/nova/conductor/api.py b/nova/conductor/api.py
index cebe6bf1f..1a0d24d66 100644
--- a/nova/conductor/api.py
+++ b/nova/conductor/api.py
@@ -76,19 +76,22 @@ class LocalAPI(object):
def instance_get_all(self, context):
return self._manager.instance_get_all(context)
- def instance_get_all_by_host(self, context, host):
- return self._manager.instance_get_all_by_host(context, host)
+ def instance_get_all_by_host(self, context, host, columns_to_join=None):
+ return self._manager.instance_get_all_by_host(context, host,
+ columns_to_join)
def instance_get_all_by_host_and_node(self, context, host, node):
return self._manager.instance_get_all_by_host(context, host, node)
def instance_get_all_by_filters(self, context, filters,
sort_key='created_at',
- sort_dir='desc'):
+ sort_dir='desc',
+ columns_to_join=None):
return self._manager.instance_get_all_by_filters(context,
filters,
sort_key,
- sort_dir)
+ sort_dir,
+ columns_to_join)
def instance_get_all_hung_in_rebooting(self, context, timeout):
return self._manager.instance_get_all_hung_in_rebooting(context,
@@ -398,8 +401,9 @@ class API(object):
def instance_get_all(self, context):
return self.conductor_rpcapi.instance_get_all(context)
- def instance_get_all_by_host(self, context, host):
- return self.conductor_rpcapi.instance_get_all_by_host(context, host)
+ def instance_get_all_by_host(self, context, host, columns_to_join=None):
+ return self.conductor_rpcapi.instance_get_all_by_host(
+ context, host, columns_to_join=columns_to_join)
def instance_get_all_by_host_and_node(self, context, host, node):
return self.conductor_rpcapi.instance_get_all_by_host(context,
@@ -407,11 +411,10 @@ class API(object):
def instance_get_all_by_filters(self, context, filters,
sort_key='created_at',
- sort_dir='desc'):
- return self.conductor_rpcapi.instance_get_all_by_filters(context,
- filters,
- sort_key,
- sort_dir)
+ sort_dir='desc',
+ columns_to_join=None):
+ return self.conductor_rpcapi.instance_get_all_by_filters(
+ context, filters, sort_key, sort_dir, columns_to_join)
def instance_get_all_hung_in_rebooting(self, context, timeout):
return self.conductor_rpcapi.instance_get_all_hung_in_rebooting(
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index a9f0e9681..f557a0c67 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -49,7 +49,7 @@ datetime_fields = ['launched_at', 'terminated_at', 'updated_at']
class ConductorManager(manager.Manager):
"""Mission: TBD."""
- RPC_API_VERSION = '1.46'
+ RPC_API_VERSION = '1.47'
def __init__(self, *args, **kwargs):
super(ConductorManager, self).__init__(*args, **kwargs)
@@ -109,12 +109,14 @@ class ConductorManager(manager.Manager):
def instance_get_all(self, context):
return jsonutils.to_primitive(self.db.instance_get_all(context))
- def instance_get_all_by_host(self, context, host, node=None):
+ def instance_get_all_by_host(self, context, host, node=None,
+ columns_to_join=None):
if node is not None:
result = self.db.instance_get_all_by_host_and_node(
context.elevated(), host, node)
else:
- result = self.db.instance_get_all_by_host(context.elevated(), host)
+ result = self.db.instance_get_all_by_host(context.elevated(), host,
+ columns_to_join)
return jsonutils.to_primitive(result)
@rpc_common.client_exceptions(exception.MigrationNotFound)
@@ -254,9 +256,10 @@ class ConductorManager(manager.Manager):
" invocation"))
def instance_get_all_by_filters(self, context, filters, sort_key,
- sort_dir):
- result = self.db.instance_get_all_by_filters(context, filters,
- sort_key, sort_dir)
+ sort_dir, columns_to_join=None):
+ result = self.db.instance_get_all_by_filters(
+ context, filters, sort_key, sort_dir,
+ columns_to_join=columns_to_join)
return jsonutils.to_primitive(result)
def instance_get_all_hung_in_rebooting(self, context, timeout):
diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py
index d8daecf9c..2f6dbcc43 100644
--- a/nova/conductor/rpcapi.py
+++ b/nova/conductor/rpcapi.py
@@ -84,6 +84,8 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.44 - Added compute_node_delete
1.45 - Added project_id to quota_commit and quota_rollback
1.46 - Added compute_confirm_resize
+ 1.47 - Added columns_to_join to instance_get_all_by_host and
+ instance_get_all_by_filters
"""
BASE_RPC_API_VERSION = '1.0'
@@ -248,11 +250,11 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
return self.call(context, msg, version='1.14')
def instance_get_all_by_filters(self, context, filters, sort_key,
- sort_dir):
+ sort_dir, columns_to_join=None):
msg = self.make_msg('instance_get_all_by_filters',
filters=filters, sort_key=sort_key,
- sort_dir=sort_dir)
- return self.call(context, msg, version='1.15')
+ sort_dir=sort_dir, columns_to_join=columns_to_join)
+ return self.call(context, msg, version='1.47')
def instance_get_all_hung_in_rebooting(self, context, timeout):
msg = self.make_msg('instance_get_all_hung_in_rebooting',
@@ -306,9 +308,11 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
msg = self.make_msg('instance_get_all')
return self.call(context, msg, version='1.23')
- def instance_get_all_by_host(self, context, host, node=None):
- msg = self.make_msg('instance_get_all_by_host', host=host, node=node)
- return self.call(context, msg, version='1.32')
+ def instance_get_all_by_host(self, context, host, node=None,
+ columns_to_join=None):
+ msg = self.make_msg('instance_get_all_by_host', host=host, node=node,
+ columns_to_join=columns_to_join)
+ return self.call(context, msg, version='1.47')
def instance_fault_create(self, context, values):
msg = self.make_msg('instance_fault_create', values=values)
diff --git a/nova/db/api.py b/nova/db/api.py
index 19a5e1f5f..c1d28e33a 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -624,9 +624,9 @@ def instance_get_active_by_window_joined(context, begin, end=None,
project_id, host)
-def instance_get_all_by_host(context, host):
+def instance_get_all_by_host(context, host, columns_to_join=None):
"""Get all instances belonging to a host."""
- return IMPL.instance_get_all_by_host(context, host)
+ return IMPL.instance_get_all_by_host(context, host, columns_to_join)
def instance_get_all_by_host_and_node(context, host, node):
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 035779e41..ab7646c41 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1842,9 +1842,10 @@ def _instance_get_all_query(context, project_only=False, joins=None):
@require_admin_context
-def instance_get_all_by_host(context, host):
+def instance_get_all_by_host(context, host, columns_to_join=None):
return _instances_fill_metadata(context,
- _instance_get_all_query(context).filter_by(host=host).all())
+ _instance_get_all_query(context).filter_by(host=host).all(),
+ manual_joins=columns_to_join)
@require_admin_context
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index f4c6dde61..e339ecf44 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -670,7 +670,8 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
filters = {'foo': 'bar'}
self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
db.instance_get_all_by_filters(self.context, filters,
- 'fake-key', 'fake-sort')
+ 'fake-key', 'fake-sort',
+ columns_to_join=None)
self.mox.ReplayAll()
self.conductor.instance_get_all_by_filters(self.context, filters,
'fake-key', 'fake-sort')
@@ -679,7 +680,7 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node')
db.instance_get_all_by_host(self.context.elevated(),
- 'host').AndReturn('result')
+ 'host', None).AndReturn('result')
db.instance_get_all_by_host_and_node(self.context.elevated(), 'host',
'node').AndReturn('result')
self.mox.ReplayAll()
@@ -826,7 +827,8 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
filters = {'foo': 'bar'}
self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
db.instance_get_all_by_filters(self.context, filters,
- 'fake-key', 'fake-sort')
+ 'fake-key', 'fake-sort',
+ columns_to_join=None)
self.mox.ReplayAll()
self.conductor.instance_get_all_by_filters(self.context, filters,
'fake-key', 'fake-sort')
@@ -973,7 +975,8 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase):
self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
db.instance_get_all(self.context)
db.instance_get_all_by_filters(self.context, {'name': 'fake-inst'},
- 'updated_at', 'asc')
+ 'updated_at', 'asc',
+ columns_to_join=None)
self.mox.ReplayAll()
self.conductor.instance_get_all(self.context)
self.conductor.instance_get_all_by_filters(self.context,
@@ -1049,14 +1052,20 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase):
result = self.conductor.service_update(self.context, {'id': ''}, {})
self.assertEqual(result, 'fake-result')
- def test_instance_get_all_by_host(self):
- self._test_stubbed('instance_get_all_by_host',
- self.context.elevated(), 'host')
-
def test_instance_get_all_by_host_and_node(self):
self._test_stubbed('instance_get_all_by_host_and_node',
self.context.elevated(), 'host', 'node')
+ def test_instance_get_all_by_host(self):
+ self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
+ self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node')
+ db.instance_get_all_by_host(self.context.elevated(), 'host',
+ None).AndReturn('fake-result')
+ self.mox.ReplayAll()
+ result = self.conductor.instance_get_all_by_host(self.context,
+ 'host')
+ self.assertEqual(result, 'fake-result')
+
def test_ping(self):
timeouts = []
calls = dict(count=0)