Browse Source

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
(cherry picked from commit 9812774970)
changes/03/752203/1
asarfaty 7 months ago
committed by Adit Sarfaty
parent
commit
c35d7d3fef
2 changed files with 26 additions and 11 deletions
  1. +15
    -4
      vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py
  2. +11
    -7
      vmware_nsxlib/v3/policy/lb_resources.py

+ 15
- 4
vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py View File

@@ -717,14 +717,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'


+ 11
- 7
vmware_nsxlib/v3/policy/lb_resources.py View File

@@ -31,11 +31,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"""
@@ -616,9 +611,18 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
lb_service_id=lb_service_id, tenant=tenant)
return self.policy_api.get(lb_service_def, silent=silent)

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…
Cancel
Save