diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index ab23c78a..e49df1ac 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -545,7 +545,7 @@ class TestPolicyGroup(NsxPolicyLibTestCase): self.assertEqual(constants.STATE_REALIZED, state) path = "/%s/domains/%s/groups/%s" % ( TEST_TENANT, domain_id, group_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) def test_get_realized_multiple_results_get_default(self): domain_id = 'd1' @@ -562,7 +562,7 @@ class TestPolicyGroup(NsxPolicyLibTestCase): self.assertEqual(constants.STATE_UNREALIZED, state) path = "/%s/domains/%s/groups/%s" % ( TEST_TENANT, domain_id, group_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) def test_get_realized_multiple_results_get_specific(self): domain_id = 'd1' @@ -580,7 +580,7 @@ class TestPolicyGroup(NsxPolicyLibTestCase): self.assertEqual(constants.STATE_REALIZED, state) path = "/%s/domains/%s/groups/%s" % ( TEST_TENANT, domain_id, group_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) def test_get_realized_id(self): domain_id = 'd1' @@ -597,7 +597,7 @@ class TestPolicyGroup(NsxPolicyLibTestCase): self.assertEqual(realized_id, result_id) path = "/%s/domains/%s/groups/%s" % ( TEST_TENANT, domain_id, group_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) def test_get_path(self): domain_id = 'd1' @@ -1832,7 +1832,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): self.assertEqual(constants.STATE_REALIZED, state) path = "/%s/domains/%s/%s/%s" % ( TEST_TENANT, domain_id, self.path_name, map_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) class TestPolicyGatewayPolicy(TestPolicyCommunicationMap): @@ -1972,7 +1972,7 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase): self.assertEqual(constants.STATE_REALIZED, state) path = "/%s/sites/default/enforcement-points/%s" % ( TEST_TENANT, ep_id) - api_get.assert_called_once_with(path) + api_get.assert_called_once_with(path, silent=False) class TestPolicyDeploymentMap(NsxPolicyLibTestCase): diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index 2c5ea5a5..d088cd1c 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -112,7 +112,8 @@ class RESTClient(object): return self.url_patch(resource, body, headers=headers) def url_list(self, url, headers=None, silent=False): - concatenate_response = self.url_get(url, headers=headers) + concatenate_response = self.url_get(url, headers=headers, + silent=silent) cursor = concatenate_response.get('cursor', NULL_CURSOR_PREFIX) op = '&' if urlparse.urlparse(url).query else '?' url += op + 'cursor=' diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 51d5f86c..5d40e626 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1765,21 +1765,22 @@ class NsxPolicyApi(object): self.cache.update(path, result) return result - def list(self, resource_def): + def list(self, resource_def, silent=False): path = resource_def.get_section_path() - return self.client.list(path) + return self.client.list(path, silent=silent) - def get_realized_entities(self, path): - return self.client.list(REALIZATION_PATH % path)['results'] + def get_realized_entities(self, path, silent=False): + return self.client.list(REALIZATION_PATH % path, + silent=silent)['results'] - def get_realized_entity(self, path): + def get_realized_entity(self, path, silent=False): # Return first realization entity if exists # Useful for resources with single realization entity - entities = self.get_realized_entities(path) + entities = self.get_realized_entities(path, silent=silent) if entities: return entities[0] - def get_realized_state(self, path): - entity = self.get_realized_entity(path) + def get_realized_state(self, path, silent=False): + entity = self.get_realized_entity(path, silent=silent) if entity: return entity['state'] diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 05996b3f..c43ebd12 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -170,10 +170,13 @@ class NsxPolicyResourceBase(object): if obj.get('display_name') == name: return obj - def _get_realization_info(self, resource_def, entity_type=None): + def _get_realization_info(self, resource_def, entity_type=None, + silent=False): + entities = [] try: path = resource_def.get_resource_full_path() - entities = self.policy_api.get_realized_entities(path) + entities = self.policy_api.get_realized_entities( + path, silent=silent) if entities: if entity_type: # look for the entry with the right entity_type @@ -184,12 +187,18 @@ class NsxPolicyResourceBase(object): # return the first realization entry # (Useful for resources with single realization entity) return entities[0] - else: - # resource not deployed yet - LOG.warning("No realized state found for %s", path) except exceptions.ResourceNotFound: - # resource not deployed yet - LOG.warning("No realized state found for %s", path) + pass + + # If we got here the resource was not deployed yet + if silent: + LOG.debug("No realization info found for %(path)s type %(type)s: " + "%(entities)s", + {"path": path, "type": entity_type, + "entities": entities}) + else: + LOG.warning("No realization info found for %(path)s type %(type)s", + {"path": path, "type": entity_type}) def _get_realized_state(self, resource_def, entity_type=None, realization_info=None): @@ -222,7 +231,7 @@ class NsxPolicyResourceBase(object): @utils.retry_upon_none_result(max_attempts, delay=sleep, random=True) def get_info(): info = self._get_realization_info( - resource_def, entity_type=entity_type) + resource_def, entity_type=entity_type, silent=True) if info and info['state'] == constants.STATE_REALIZED: return info @@ -1014,7 +1023,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase): # get all the realized resources of the tier1 entities = self.policy_api.get_realized_entities(path) for e in entities: - # Look fir router ports + # Look for router ports if (e['entity_type'] == 'RealizedLogicalRouterPort' and e['state'] == constants.STATE_REALIZED): # Get the NSX port to check if its the downlink port