Browse Source

Handle errors in GETs gracefully

If a call to send_api_request hits an exception,
it will return None. However, our code that expects iterable
types are returned from many of our GETs. This change replaces
None returns with empty dicts in such cases.

Change-Id: I6be1ee4f84fd38519d7c5ae227581a1a72964fa0
changes/82/501482/4
Mitchell Jameson 5 years ago
parent
commit
8bce4452aa
  1. 1
      networking_arista/ml2/rpc/arista_json.py
  2. 27
      networking_arista/tests/unit/ml2/rpc/test_arista_json_rpc_wrapper.py

1
networking_arista/ml2/rpc/arista_json.py

@ -103,6 +103,7 @@ class AristaRPCWrapperJSON(AristaRPCWrapperBase):
# reraise the exception
with excutils.save_and_reraise_exception() as ctxt:
ctxt.reraise = True
return {} if method == 'GET' else None
def _check_if_cvx_leader(self, host):
url = 'agent/'

27
networking_arista/tests/unit/ml2/rpc/test_arista_json_rpc_wrapper.py

@ -15,6 +15,7 @@
import functools
import operator
import requests
import socket
import mock
@ -656,6 +657,32 @@ class TestAristaJSONRPCWrapper(testlib_api.SqlTestCase):
]
self._verify_send_api_request_call(mock_send_api_req, calls)
@patch('requests.get')
@patch(BASE_RPC + '_get_eos_master')
def test_get_value_error(self, mock_get_eos_master, mock_requests_get):
mock_get_eos_master.return_value = 'fake_master'
mock_requests_get.return_value = requests.Response()
self.assertIsNotNone(self.drv.get_vms_for_tenant(''))
self.assertIsNotNone(self.drv.get_dhcps_for_tenant(''))
self.assertIsNotNone(self.drv.get_baremetals_for_tenant(''))
self.assertIsNotNone(self.drv.get_routers_for_tenant(''))
self.assertIsNotNone(self.drv.get_ports_for_tenant('', 'vm'))
self.assertIsNotNone(self.drv.get_tenants())
self.assertIsNotNone(self.drv.get_networks(''))
self.assertIsNotNone(self.drv.get_instance_ports('', 'vm'))
@patch(BASE_RPC + '_get_eos_master')
def test_get_exception(self, mock_get_eos_master):
mock_get_eos_master.return_value = 'fake_master'
self.assertIsNotNone(self.drv.get_vms_for_tenant(''))
self.assertIsNotNone(self.drv.get_dhcps_for_tenant(''))
self.assertIsNotNone(self.drv.get_baremetals_for_tenant(''))
self.assertIsNotNone(self.drv.get_routers_for_tenant(''))
self.assertIsNotNone(self.drv.get_ports_for_tenant('', 'vm'))
self.assertIsNotNone(self.drv.get_tenants())
self.assertIsNotNone(self.drv.get_networks(''))
self.assertIsNotNone(self.drv.get_instance_ports('', 'vm'))
class RPCWrapperJSONValidConfigTrunkTestCase(testlib_api.SqlTestCase):
"""Test cases to test plug trunk port into network. """

Loading…
Cancel
Save