Merge "Big Switch: fix capabilities retrieval code"

This commit is contained in:
Jenkins 2014-06-08 03:46:00 +00:00 committed by Gerrit Code Review
commit 1325f80706
3 changed files with 37 additions and 6 deletions

View File

@ -110,11 +110,11 @@ class ServerProxy(object):
def get_capabilities(self):
try:
body = self.rest_call('GET', CAPABILITIES_PATH)[3]
body = self.rest_call('GET', CAPABILITIES_PATH)[2]
self.capabilities = json.loads(body)
except Exception:
LOG.error(_("Couldn't retrieve capabilities. "
"Newer API calls won't be supported."))
LOG.exception(_("Couldn't retrieve capabilities. "
"Newer API calls won't be supported."))
LOG.info(_("The following capabilities were received "
"for %(server)s: %(cap)s"), {'server': self.server,
'cap': self.capabilities})

View File

@ -34,7 +34,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
def test_floating_ip_capability(self):
with contextlib.nested(
mock.patch(SERVERRESTCALL,
return_value=(200, None, None, '["floatingip"]')),
return_value=(200, None, '["floatingip"]', None)),
mock.patch(SERVERPOOL + '.rest_create_floatingip',
return_value=(200, None, None, None)),
mock.patch(SERVERPOOL + '.rest_delete_floatingip',
@ -53,7 +53,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
def test_floating_ip_capability_neg(self):
with contextlib.nested(
mock.patch(SERVERRESTCALL,
return_value=(200, None, None, '[""]')),
return_value=(200, None, '[""]', None)),
mock.patch(SERVERPOOL + '.rest_update_network',
return_value=(200, None, None, None))
) as (mock_rest, mock_netupdate):
@ -67,7 +67,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
def test_keep_alive_capability(self):
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
with self.floatingip_with_assoc():

View File

@ -174,6 +174,37 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
self.assertIn('EXTRA-HEADER', callheaders)
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):
sp = servermanager.ServerPool()
with mock.patch(HTTPCON) as conmock: