Merge "Use reasonable timeout for rpc service_update()" into stable/juno
This commit is contained in:
commit
a19a1e52f1
|
@ -281,7 +281,20 @@ class ConductorAPI(object):
|
|||
|
||||
def service_update(self, context, service, values):
|
||||
service_p = jsonutils.to_primitive(service)
|
||||
cctxt = self.client.prepare()
|
||||
|
||||
# (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)
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ class Service(service.Service):
|
|||
'host': self.host,
|
||||
'binary': self.binary,
|
||||
'topic': self.topic,
|
||||
'report_count': 0
|
||||
'report_count': 0,
|
||||
}
|
||||
service = self.conductor_api.service_create(context, svc_values)
|
||||
self.service_id = service['id']
|
||||
|
|
|
@ -19,6 +19,7 @@ import contextlib
|
|||
|
||||
import mock
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
from oslo import messaging
|
||||
|
||||
from nova.api.ec2 import ec2utils
|
||||
|
@ -59,6 +60,10 @@ from nova.tests import fake_utils
|
|||
from nova import utils
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('report_interval', 'nova.service')
|
||||
|
||||
|
||||
FAKE_IMAGE_REF = 'fake-image-ref'
|
||||
|
||||
|
||||
|
@ -863,6 +868,30 @@ 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."""
|
||||
|
|
Loading…
Reference in New Issue