Remove and deprecate unused conductor service calls

A previous change converted service and servicegroup to objects.
This change removes the now unused service methods from conductor.

Change-Id: I3e35598ec89b18d1121547caa37ec5dbc506cb06
This commit is contained in:
Hans Lindgren 2014-11-07 14:52:23 +01:00
parent 19455514d1
commit 6285d6a511
4 changed files with 16 additions and 250 deletions

View File

@ -117,39 +117,6 @@ class LocalAPI(object):
instance, last_refreshed,
update_totals)
def service_get_all(self, context):
return self._manager.service_get_all_by(context, host=None, topic=None,
binary=None)
def service_get_all_by_topic(self, context, topic):
return self._manager.service_get_all_by(context, topic=topic,
host=None, binary=None)
def service_get_all_by_host(self, context, host):
return self._manager.service_get_all_by(context, host=host, topic=None,
binary=None)
def service_get_by_host_and_topic(self, context, host, topic):
return self._manager.service_get_all_by(context, topic, host,
binary=None)
def service_get_by_compute_host(self, context, host):
result = self._manager.service_get_all_by(context, 'compute', host,
binary=None)
# FIXME(comstud): A major revision bump to 2.0 should return a
# single entry, so we should just return 'result' at that point.
return result[0]
def service_get_by_host_and_binary(self, context, host, binary):
return self._manager.service_get_all_by(context, host=host,
binary=binary, topic=None)
def service_create(self, context, values):
return self._manager.service_create(context, values)
def service_destroy(self, context, service_id):
return self._manager.service_destroy(context, service_id)
def compute_node_create(self, context, values):
return self._manager.compute_node_create(context, values)
@ -160,9 +127,6 @@ class LocalAPI(object):
def compute_node_delete(self, context, node):
return self._manager.compute_node_delete(context, node)
def service_update(self, context, service, values):
return self._manager.service_update(context, service, values)
def task_log_get(self, context, task_name, begin, end, host, state=None):
return self._manager.task_log_get(context, task_name, begin, end,
host, state)

View File

@ -270,6 +270,7 @@ class ConductorManager(manager.Manager):
self.notifier.info(context, 'volume.usage',
compute_utils.usage_volume_info(vol_usage))
# NOTE(hanlind): This method can be removed in version 3.0 of the RPC API
@messaging.expected_exceptions(exception.ComputeHostNotFound,
exception.HostBinaryNotFound)
def service_get_all_by(self, context, topic, host, binary):
@ -310,10 +311,12 @@ class ConductorManager(manager.Manager):
evt = self.db.action_event_finish(context, values)
return jsonutils.to_primitive(evt)
# NOTE(hanlind): This method can be removed in version 3.0 of the RPC API
def service_create(self, context, values):
svc = self.db.service_create(context, values)
return jsonutils.to_primitive(svc)
# NOTE(hanlind): This method can be removed in version 3.0 of the RPC API
@messaging.expected_exceptions(exception.ServiceNotFound)
def service_destroy(self, context, service_id):
self.db.service_destroy(context, service_id)
@ -330,6 +333,7 @@ class ConductorManager(manager.Manager):
result = self.db.compute_node_delete(context, node['id'])
return jsonutils.to_primitive(result)
# NOTE(hanlind): This method can be removed in version 3.0 of the RPC API
@messaging.expected_exceptions(exception.ServiceNotFound)
def service_update(self, context, service, values):
svc = self.db.service_update(context, service['id'], values)

View File

@ -160,6 +160,10 @@ class ConductorAPI(object):
* Remove bw_usage_update()
* Remove notify_usage_exists()
* Remove get_ec2_ids()
* Remove service_get_all_by()
* Remove service_create()
* Remove service_destroy()
* Remove service_update()
"""
@ -231,11 +235,6 @@ class ConductorAPI(object):
instance=instance_p, last_refreshed=last_refreshed,
update_totals=update_totals)
def service_get_all_by(self, context, topic=None, host=None, binary=None):
cctxt = self.client.prepare()
return cctxt.call(context, 'service_get_all_by',
topic=topic, host=host, binary=binary)
def instance_get_all_by_host(self, context, host, node=None,
columns_to_join=None):
cctxt = self.client.prepare()
@ -243,14 +242,6 @@ class ConductorAPI(object):
host=host, node=node,
columns_to_join=columns_to_join)
def service_create(self, context, values):
cctxt = self.client.prepare()
return cctxt.call(context, 'service_create', values=values)
def service_destroy(self, context, service_id):
cctxt = self.client.prepare()
return cctxt.call(context, 'service_destroy', service_id=service_id)
def compute_node_create(self, context, values):
cctxt = self.client.prepare()
return cctxt.call(context, 'compute_node_create', values=values)
@ -266,25 +257,6 @@ class ConductorAPI(object):
cctxt = self.client.prepare()
return cctxt.call(context, 'compute_node_delete', node=node_p)
def service_update(self, context, service, values):
service_p = jsonutils.to_primitive(service)
# (NOTE:jichenjc)If we're calling this periodically, it makes no
# sense for the RPC timeout to be more than the service
# report interval. Select 5 here is only find a reaonable long
# interval as threshold.
timeout = CONF.report_interval
if timeout and timeout > 5:
timeout -= 1
if timeout:
cctxt = self.client.prepare(timeout=timeout)
else:
cctxt = self.client.prepare()
return cctxt.call(context, 'service_update',
service=service_p, values=values)
def task_log_get(self, context, task_name, begin, end, host, state=None):
cctxt = self.client.prepare()
return cctxt.call(context, 'task_log_get',

View File

@ -20,7 +20,6 @@ import uuid
import mock
from mox3 import mox
from oslo_config import cfg
import oslo_messaging as messaging
from oslo_utils import timeutils
import six
@ -62,10 +61,6 @@ from nova.tests.unit import fake_utils
from nova import utils
CONF = cfg.CONF
CONF.import_opt('report_interval', 'nova.service')
FAKE_IMAGE_REF = 'fake-image-ref'
@ -808,77 +803,6 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
self.conductor.block_device_mapping_update_or_create(self.context,
fake_bdm)
def _test_stubbed(self, name, dbargs, condargs,
db_result_listified=False, db_exception=None):
self.mox.StubOutWithMock(db, name)
if db_exception:
getattr(db, name)(self.context, *dbargs).AndRaise(db_exception)
else:
getattr(db, name)(self.context, *dbargs).AndReturn(condargs)
if name == 'service_get_by_compute_host':
self.mox.StubOutWithMock(
objects.ComputeNodeList, 'get_all_by_host')
objects.ComputeNodeList.get_all_by_host(
self.context, mox.IgnoreArg()
).AndReturn(['fake-compute'])
self.mox.ReplayAll()
if db_exception:
self.assertRaises(db_exception.__class__,
self.conductor.service_get_all_by,
self.context, **condargs)
else:
result = self.conductor.service_get_all_by(self.context,
**condargs)
if db_result_listified:
if name == 'service_get_by_compute_host':
condargs['compute_node'] = ['fake-compute']
self.assertEqual([condargs], result)
else:
self.assertEqual(condargs, result)
def test_service_get_all(self):
self._test_stubbed('service_get_all', (),
dict(topic=None, host=None, binary=None))
def test_service_get_by_host_and_topic(self):
self._test_stubbed('service_get_by_host_and_topic',
('host', 'topic'),
dict(topic='topic', host='host', binary=None))
def test_service_get_all_by_topic(self):
self._test_stubbed('service_get_all_by_topic',
('topic',),
dict(topic='topic', host=None, binary=None))
def test_service_get_all_by_host(self):
self._test_stubbed('service_get_all_by_host',
('host',),
dict(host='host', topic=None, binary=None))
def test_service_get_by_compute_host(self):
self._test_stubbed('service_get_by_compute_host',
('host',),
dict(topic='compute', host='host', binary=None),
db_result_listified=True)
def test_service_get_by_args(self):
self._test_stubbed('service_get_by_host_and_binary',
('host', 'binary'),
dict(host='host', binary='binary', topic=None))
def test_service_get_by_compute_host_not_found(self):
self._test_stubbed('service_get_by_compute_host',
('host',),
dict(topic='compute', host='host', binary=None),
db_exception=exc.ComputeHostNotFound(host='host'))
def test_service_get_by_args_not_found(self):
self._test_stubbed('service_get_by_host_and_binary',
('host', 'binary'),
dict(host='host', binary='binary', topic=None),
db_exception=exc.HostBinaryNotFound(binary='binary',
host='host'))
def test_security_groups_trigger_handler(self):
self.mox.StubOutWithMock(self.conductor_manager.security_group_api,
'trigger_handler')
@ -889,30 +813,6 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
self.conductor.security_groups_trigger_handler(self.context,
'event', ['arg'])
@mock.patch.object(db, 'service_update')
@mock.patch('oslo_messaging.RPCClient.prepare')
def test_service_update_time_big(self, mock_prepare, mock_update):
CONF.set_override('report_interval', 10)
services = {'id': 1}
self.conductor.service_update(self.context, services, {})
mock_prepare.assert_called_once_with(timeout=9)
@mock.patch.object(db, 'service_update')
@mock.patch('oslo_messaging.RPCClient.prepare')
def test_service_update_time_small(self, mock_prepare, mock_update):
CONF.set_override('report_interval', 3)
services = {'id': 1}
self.conductor.service_update(self.context, services, {})
mock_prepare.assert_called_once_with(timeout=3)
@mock.patch.object(db, 'service_update')
@mock.patch('oslo_messaging.RPCClient.prepare')
def test_service_update_no_time(self, mock_prepare, mock_update):
CONF.set_override('report_interval', None)
services = {'id': 1}
self.conductor.service_update(self.context, services, {})
mock_prepare.assert_called_once_with()
class ConductorAPITestCase(_BaseTestCase, test.TestCase):
"""Conductor API Tests."""
@ -953,89 +853,15 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase):
self.conductor.block_device_mapping_update_or_create(self.context,
'fake-bdm')
def _test_stubbed(self, name, *args, **kwargs):
if args and isinstance(args[0], FakeContext):
ctxt = args[0]
args = args[1:]
else:
ctxt = self.context
db_exception = kwargs.get('db_exception')
self.mox.StubOutWithMock(db, name)
if db_exception:
getattr(db, name)(ctxt, *args).AndRaise(db_exception)
else:
getattr(db, name)(ctxt, *args).AndReturn(dict(host='fake'))
if name == 'service_get_by_compute_host':
self.mox.StubOutWithMock(
objects.ComputeNodeList, 'get_all_by_host')
objects.ComputeNodeList.get_all_by_host(
self.context, mox.IgnoreArg()
).AndReturn(['fake-compute'])
if name == 'service_destroy':
# TODO(russellb) This is a hack ... SetUp() starts the conductor()
# service. There is a cleanup step that runs after this test which
# also deletes the associated service record. This involves a call
# to db.service_destroy(), which we have stubbed out.
db.service_destroy(mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
if db_exception:
self.assertRaises(db_exception.__class__,
getattr(self.conductor, name),
self.context, *args)
else:
result = getattr(self.conductor, name)(self.context, *args)
expected = dict(host='fake')
if name == 'service_get_by_compute_host':
expected = dict(host='fake', compute_node=['fake-compute'])
self.assertEqual(
result, expected
if kwargs.get('returns', True) else None)
def test_service_get_all(self):
self._test_stubbed('service_get_all')
def test_service_get_by_host_and_topic(self):
self._test_stubbed('service_get_by_host_and_topic', 'host', 'topic')
def test_service_get_all_by_topic(self):
self._test_stubbed('service_get_all_by_topic', 'topic')
def test_service_get_all_by_host(self):
self._test_stubbed('service_get_all_by_host', 'host')
def test_service_get_by_compute_host(self):
self._test_stubbed('service_get_by_compute_host', 'host')
def test_service_get_by_args(self):
self._test_stubbed('service_get_by_host_and_binary', 'host', 'binary')
def test_service_get_by_compute_host_not_found(self):
self._test_stubbed('service_get_by_compute_host', 'host',
db_exception=exc.ComputeHostNotFound(host='host'))
def test_service_get_by_args_not_found(self):
self._test_stubbed('service_get_by_host_and_binary', 'host', 'binary',
db_exception=exc.HostBinaryNotFound(binary='binary',
host='host'))
def test_service_create(self):
self._test_stubbed('service_create', {})
def test_service_destroy(self):
self._test_stubbed('service_destroy', '', returns=False)
def test_service_update(self):
ctxt = self.context
self.mox.StubOutWithMock(db, 'service_update')
db.service_update(ctxt, '', {}).AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.service_update(self.context, {'id': ''}, {})
self.assertEqual(result, 'fake-result')
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')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node')
db.instance_get_all_by_host_and_node(self.context.elevated(), 'host',
'node').AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.instance_get_all_by_host_and_node(
self.context, 'host', 'node')
self.assertEqual('fake-result', result)
def test_instance_get_all_by_host(self):
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')