diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py index d34da03f..a51a19ea 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py @@ -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' diff --git a/vmware_nsxlib/v3/policy/lb_resources.py b/vmware_nsxlib/v3/policy/lb_resources.py index 0631aa73..9f04cf71 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -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,