Suppress logging of lb services list results if empty
Since lb services list is called often by the vmware_nsx neutron plugin, adding an option to suppress empty results logging to make logs cleaner Change-Id: I95e7c20569e87bc2c184965a14a3ceec56e8f8ad
This commit is contained in:
parent
889037c399
commit
9812774970
|
@ -847,14 +847,25 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
|
|||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_list(self):
|
||||
def _test_list(self, silent=False, silent_if_empty=False):
|
||||
s1 = {'id': 'xxx', 'display_name': 'yyy'}
|
||||
with mock.patch.object(self.policy_api, "list",
|
||||
return_value={'results': []}) as api_call:
|
||||
result = self.resourceApi.list(tenant=TEST_TENANT)
|
||||
return_value={'results': [s1]}) as api_call:
|
||||
result = self.resourceApi.list(tenant=TEST_TENANT, silent=silent,
|
||||
silent_if_empty=silent_if_empty)
|
||||
expected_def = lb_defs.LBServiceDef(
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual([], result)
|
||||
self.assertEqual([s1], result)
|
||||
|
||||
def test_list(self):
|
||||
self._test_list()
|
||||
|
||||
def test_list_total_silence(self):
|
||||
self._test_list(silent=True)
|
||||
|
||||
def test_list_silent_if_empty(self):
|
||||
self._test_list(silent_if_empty=True)
|
||||
|
||||
def test_update(self):
|
||||
obj_id = '111'
|
||||
|
|
|
@ -30,11 +30,6 @@ from vmware_nsxlib.v3 import utils
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# Sentitel object to indicate unspecified attribute value
|
||||
# None value in attribute would indicate "unset" functionality,
|
||||
# while "ignore" means that the value not be present in request
|
||||
# body
|
||||
|
||||
|
||||
class NsxPolicyLBAppProfileBase(NsxPolicyResourceBase):
|
||||
"""NSX Policy LB app profile"""
|
||||
|
@ -669,9 +664,18 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
|
|||
lb_service_id=lb_service_id, tenant=tenant)
|
||||
return self.policy_api.get(lb_service_def)
|
||||
|
||||
def list(self, tenant=constants.POLICY_INFRA_TENANT):
|
||||
def list(self, tenant=constants.POLICY_INFRA_TENANT, silent=False,
|
||||
silent_if_empty=False):
|
||||
if not silent and silent_if_empty:
|
||||
# Log only non-empty results
|
||||
silent = True
|
||||
lb_service_def = lb_defs.LBServiceDef(tenant=tenant)
|
||||
return self.policy_api.list(lb_service_def)['results']
|
||||
list_results = self.policy_api.list(lb_service_def, silent=silent)
|
||||
if silent_if_empty and list_results.get('results'):
|
||||
LOG.debug("REST call: GET %s. Response: %s",
|
||||
lb_service_def.get_section_path(), list_results)
|
||||
|
||||
return list_results['results']
|
||||
|
||||
def update(self, lb_service_id, name=IGNORE,
|
||||
description=IGNORE, tags=IGNORE,
|
||||
|
|
Loading…
Reference in New Issue