Merge "Big Switch: fix capabilities retrieval code"
This commit is contained in:
commit
4dc760f693
@ -110,11 +110,11 @@ class ServerProxy(object):
|
|||||||
|
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
try:
|
try:
|
||||||
body = self.rest_call('GET', CAPABILITIES_PATH)[3]
|
body = self.rest_call('GET', CAPABILITIES_PATH)[2]
|
||||||
self.capabilities = json.loads(body)
|
self.capabilities = json.loads(body)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.error(_("Couldn't retrieve capabilities. "
|
LOG.exception(_("Couldn't retrieve capabilities. "
|
||||||
"Newer API calls won't be supported."))
|
"Newer API calls won't be supported."))
|
||||||
LOG.info(_("The following capabilities were received "
|
LOG.info(_("The following capabilities were received "
|
||||||
"for %(server)s: %(cap)s"), {'server': self.server,
|
"for %(server)s: %(cap)s"), {'server': self.server,
|
||||||
'cap': self.capabilities})
|
'cap': self.capabilities})
|
||||||
|
@ -34,7 +34,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
|
|||||||
def test_floating_ip_capability(self):
|
def test_floating_ip_capability(self):
|
||||||
with contextlib.nested(
|
with contextlib.nested(
|
||||||
mock.patch(SERVERRESTCALL,
|
mock.patch(SERVERRESTCALL,
|
||||||
return_value=(200, None, None, '["floatingip"]')),
|
return_value=(200, None, '["floatingip"]', None)),
|
||||||
mock.patch(SERVERPOOL + '.rest_create_floatingip',
|
mock.patch(SERVERPOOL + '.rest_create_floatingip',
|
||||||
return_value=(200, None, None, None)),
|
return_value=(200, None, None, None)),
|
||||||
mock.patch(SERVERPOOL + '.rest_delete_floatingip',
|
mock.patch(SERVERPOOL + '.rest_delete_floatingip',
|
||||||
@ -53,7 +53,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
|
|||||||
def test_floating_ip_capability_neg(self):
|
def test_floating_ip_capability_neg(self):
|
||||||
with contextlib.nested(
|
with contextlib.nested(
|
||||||
mock.patch(SERVERRESTCALL,
|
mock.patch(SERVERRESTCALL,
|
||||||
return_value=(200, None, None, '[""]')),
|
return_value=(200, None, '[""]', None)),
|
||||||
mock.patch(SERVERPOOL + '.rest_update_network',
|
mock.patch(SERVERPOOL + '.rest_update_network',
|
||||||
return_value=(200, None, None, None))
|
return_value=(200, None, None, None))
|
||||||
) as (mock_rest, mock_netupdate):
|
) as (mock_rest, mock_netupdate):
|
||||||
@ -67,7 +67,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
|
|||||||
|
|
||||||
def test_keep_alive_capability(self):
|
def test_keep_alive_capability(self):
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
SERVERRESTCALL, return_value=(200, None, None, '["keep-alive"]')
|
SERVERRESTCALL, return_value=(200, None, '["keep-alive"]', None)
|
||||||
):
|
):
|
||||||
# perform a task to cause capabilities to be retrieved
|
# perform a task to cause capabilities to be retrieved
|
||||||
with self.floatingip_with_assoc():
|
with self.floatingip_with_assoc():
|
||||||
|
@ -174,6 +174,37 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
|
|||||||
self.assertIn('EXTRA-HEADER', callheaders)
|
self.assertIn('EXTRA-HEADER', callheaders)
|
||||||
self.assertEqual(callheaders['EXTRA-HEADER'], 'HI')
|
self.assertEqual(callheaders['EXTRA-HEADER'], 'HI')
|
||||||
|
|
||||||
|
def test_capabilities_retrieval(self):
|
||||||
|
sp = servermanager.ServerPool()
|
||||||
|
with mock.patch(HTTPCON) as conmock:
|
||||||
|
rv = conmock.return_value.getresponse.return_value
|
||||||
|
rv.getheader.return_value = 'HASHHEADER'
|
||||||
|
|
||||||
|
# each server will get different capabilities
|
||||||
|
rv.read.side_effect = ['["a","b","c"]', '["b","c","d"]']
|
||||||
|
# pool capabilities is intersection between both
|
||||||
|
self.assertEqual(set(['b', 'c']), sp.get_capabilities())
|
||||||
|
self.assertEqual(2, rv.read.call_count)
|
||||||
|
|
||||||
|
# the pool should cache after the first call so no more
|
||||||
|
# HTTP calls should be made
|
||||||
|
rv.read.side_effect = ['["w","x","y"]', '["x","y","z"]']
|
||||||
|
self.assertEqual(set(['b', 'c']), sp.get_capabilities())
|
||||||
|
self.assertEqual(2, rv.read.call_count)
|
||||||
|
|
||||||
|
def test_capabilities_retrieval_failure(self):
|
||||||
|
sp = servermanager.ServerPool()
|
||||||
|
with mock.patch(HTTPCON) as conmock:
|
||||||
|
rv = conmock.return_value.getresponse.return_value
|
||||||
|
rv.getheader.return_value = 'HASHHEADER'
|
||||||
|
# a failure to parse should result in an empty capability set
|
||||||
|
rv.read.return_value = 'XXXXX'
|
||||||
|
self.assertEqual([], sp.servers[0].get_capabilities())
|
||||||
|
|
||||||
|
# One broken server should affect all capabilities
|
||||||
|
rv.read.side_effect = ['{"a": "b"}', '["b","c","d"]']
|
||||||
|
self.assertEqual(set(), sp.get_capabilities())
|
||||||
|
|
||||||
def test_reconnect_on_timeout_change(self):
|
def test_reconnect_on_timeout_change(self):
|
||||||
sp = servermanager.ServerPool()
|
sp = servermanager.ServerPool()
|
||||||
with mock.patch(HTTPCON) as conmock:
|
with mock.patch(HTTPCON) as conmock:
|
||||||
|
Loading…
Reference in New Issue
Block a user