Add logging for failed realization
Change-Id: Ia721d46272d3dca67bb2ba09bce6977dec886495
This commit is contained in:
parent
54818b0f51
commit
253a76c527
|
@ -1790,7 +1790,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
user_tags = [{'scope': 'user', 'tag': 'k8s'}]
|
user_tags = [{'scope': 'user', 'tag': 'k8s'}]
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags)
|
self.nsxlib.search_by_tags(tags=user_tags)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_scope_only(self):
|
def test_nsx_search_tags_scope_only(self):
|
||||||
"""Test search of resources with the specified tag."""
|
"""Test search of resources with the specified tag."""
|
||||||
|
@ -1798,7 +1798,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
user_tags = [{'scope': 'user'}]
|
user_tags = [{'scope': 'user'}]
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags)
|
self.nsxlib.search_by_tags(tags=user_tags)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_tag_only(self):
|
def test_nsx_search_tags_tag_only(self):
|
||||||
"""Test search of resources with the specified tag."""
|
"""Test search of resources with the specified tag."""
|
||||||
|
@ -1806,7 +1806,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
user_tags = [{'tag': 'k8s'}]
|
user_tags = [{'tag': 'k8s'}]
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags)
|
self.nsxlib.search_by_tags(tags=user_tags)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_with_extra_attribute(self):
|
def test_nsx_search_tags_with_extra_attribute(self):
|
||||||
"""Test search of resource with specified tags and one attribute."""
|
"""Test search of resource with specified tags and one attribute."""
|
||||||
|
@ -1815,7 +1815,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
query = "%s AND %s" % (self.nsxlib._build_query(tags=user_tags),
|
query = "%s AND %s" % (self.nsxlib._build_query(tags=user_tags),
|
||||||
'marked_for_delete:False')
|
'marked_for_delete:False')
|
||||||
self.nsxlib.search_by_tags(tags=user_tags, marked_for_delete=False)
|
self.nsxlib.search_by_tags(tags=user_tags, marked_for_delete=False)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_with_multi_attributes(self):
|
def test_nsx_search_tags_with_multi_attributes(self):
|
||||||
"""Test search of resource with tags and multiple attributes."""
|
"""Test search of resource with tags and multiple attributes."""
|
||||||
|
@ -1825,7 +1825,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
'tea:boo AND coffee:False')
|
'tea:boo AND coffee:False')
|
||||||
self.nsxlib.search_by_tags(
|
self.nsxlib.search_by_tags(
|
||||||
tags=user_tags, tea='boo', coffee=False)
|
tags=user_tags, tea='boo', coffee=False)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_by_resouce_type_and_attributes(self):
|
def test_nsx_search_by_resouce_type_and_attributes(self):
|
||||||
with mock.patch.object(self.nsxlib.client, 'url_get') as search:
|
with mock.patch.object(self.nsxlib.client, 'url_get') as search:
|
||||||
|
@ -1868,7 +1868,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
user_tags = [{'tag': 'k8s'}, {'scope': 'user'}]
|
user_tags = [{'tag': 'k8s'}, {'scope': 'user'}]
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags)
|
self.nsxlib.search_by_tags(tags=user_tags)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_and_resource_type(self):
|
def test_nsx_search_tags_and_resource_type(self):
|
||||||
"""Test search of specified resource with the specified tag."""
|
"""Test search of specified resource with the specified tag."""
|
||||||
|
@ -1879,7 +1879,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
# Add resource_type to the query
|
# Add resource_type to the query
|
||||||
query = "resource_type:%s AND %s" % (res_type, query)
|
query = "resource_type:%s AND %s" % (res_type, query)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags, resource_type=res_type)
|
self.nsxlib.search_by_tags(tags=user_tags, resource_type=res_type)
|
||||||
search.assert_called_with(self.search_path % query)
|
search.assert_called_with(self.search_path % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_and_cursor(self):
|
def test_nsx_search_tags_and_cursor(self):
|
||||||
"""Test search of resources with the specified tag and cursor."""
|
"""Test search of resources with the specified tag and cursor."""
|
||||||
|
@ -1888,7 +1888,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags, cursor=50)
|
self.nsxlib.search_by_tags(tags=user_tags, cursor=50)
|
||||||
search.assert_called_with(
|
search.assert_called_with(
|
||||||
(self.search_path + '&cursor=50') % query)
|
(self.search_path + '&cursor=50') % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_tags_and_page_size(self):
|
def test_nsx_search_tags_and_page_size(self):
|
||||||
"""Test search of resources with the specified tag and page size."""
|
"""Test search of resources with the specified tag and page size."""
|
||||||
|
@ -1897,7 +1897,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
self.nsxlib.search_by_tags(tags=user_tags, page_size=100)
|
self.nsxlib.search_by_tags(tags=user_tags, page_size=100)
|
||||||
search.assert_called_with(
|
search.assert_called_with(
|
||||||
(self.search_path + '&page_size=100') % query)
|
(self.search_path + '&page_size=100') % query, silent=False)
|
||||||
|
|
||||||
def test_nsx_search_invalid_query_fail(self):
|
def test_nsx_search_invalid_query_fail(self):
|
||||||
"""Test search query failure for missing tag argument."""
|
"""Test search query failure for missing tag argument."""
|
||||||
|
@ -1946,8 +1946,9 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
|
||||||
query = self.nsxlib._build_query(tags=user_tags)
|
query = self.nsxlib._build_query(tags=user_tags)
|
||||||
results = self.nsxlib.search_all_by_tags(tags=user_tags)
|
results = self.nsxlib.search_all_by_tags(tags=user_tags)
|
||||||
search.assert_has_calls([
|
search.assert_has_calls([
|
||||||
mock.call(self.search_path % query),
|
mock.call(self.search_path % query, silent=False),
|
||||||
mock.call((self.search_path + '&cursor=2') % query)])
|
mock.call((self.search_path + '&cursor=2') % query,
|
||||||
|
silent=False)])
|
||||||
self.assertEqual(3, len(results))
|
self.assertEqual(3, len(results))
|
||||||
|
|
||||||
@mock.patch("vmware_nsxlib.v3.lib.NsxLibBase._search_all")
|
@mock.patch("vmware_nsxlib.v3.lib.NsxLibBase._search_all")
|
||||||
|
|
|
@ -125,7 +125,7 @@ class NsxLibBase(object, metaclass=abc.ABCMeta):
|
||||||
# TODO(abhiraut): Revisit this method to generate complex boolean
|
# TODO(abhiraut): Revisit this method to generate complex boolean
|
||||||
# queries to search resources.
|
# queries to search resources.
|
||||||
def search_by_tags(self, tags, resource_type=None, cursor=None,
|
def search_by_tags(self, tags, resource_type=None, cursor=None,
|
||||||
page_size=None, **extra_attrs):
|
page_size=None, silent=False, **extra_attrs):
|
||||||
"""Return the list of resources searched based on tags.
|
"""Return the list of resources searched based on tags.
|
||||||
|
|
||||||
Currently the query only supports AND boolean operator.
|
Currently the query only supports AND boolean operator.
|
||||||
|
@ -137,6 +137,7 @@ class NsxLibBase(object, metaclass=abc.ABCMeta):
|
||||||
:param cursor: Opaque cursor to be used for getting next page of
|
:param cursor: Opaque cursor to be used for getting next page of
|
||||||
records (supplied by current result page).
|
records (supplied by current result page).
|
||||||
:param page_size: Maximum number of results to return in this page.
|
:param page_size: Maximum number of results to return in this page.
|
||||||
|
:param silent: Silence the logging if True.
|
||||||
:param extra_attrs: Support querying by user specified attributes.
|
:param extra_attrs: Support querying by user specified attributes.
|
||||||
Multiple attributes will be ANDed.
|
Multiple attributes will be ANDed.
|
||||||
"""
|
"""
|
||||||
|
@ -160,7 +161,7 @@ class NsxLibBase(object, metaclass=abc.ABCMeta):
|
||||||
@utils.retry_upon_exception(exceptions.NsxSearchError,
|
@utils.retry_upon_exception(exceptions.NsxSearchError,
|
||||||
max_attempts=self.client.max_attempts)
|
max_attempts=self.client.max_attempts)
|
||||||
def do_search(url):
|
def do_search(url):
|
||||||
return self.client.url_get(url)
|
return self.client.url_get(url, silent=silent)
|
||||||
|
|
||||||
return do_search(url)
|
return do_search(url)
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,7 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
sleep = self.nsxlib_config.realization_wait_sec
|
sleep = self.nsxlib_config.realization_wait_sec
|
||||||
if max_attempts is None:
|
if max_attempts is None:
|
||||||
max_attempts = self.nsxlib_config.realization_max_attempts
|
max_attempts = self.nsxlib_config.realization_max_attempts
|
||||||
|
info = {}
|
||||||
|
|
||||||
@utils.retry_upon_none_result(max_attempts, delay=sleep, random=True)
|
@utils.retry_upon_none_result(max_attempts, delay=sleep, random=True)
|
||||||
def get_info():
|
def get_info():
|
||||||
|
@ -286,6 +287,10 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
raise e
|
raise e
|
||||||
except Exception:
|
except Exception:
|
||||||
# max retries reached
|
# max retries reached
|
||||||
|
LOG.error("_wait_until_realized maxed-out for "
|
||||||
|
"resource: %s. Last realization info was %s",
|
||||||
|
resource_def.get_resource_full_path(), info)
|
||||||
|
|
||||||
raise exceptions.RealizationTimeoutError(
|
raise exceptions.RealizationTimeoutError(
|
||||||
resource_type=resource_def.resource_type(),
|
resource_type=resource_def.resource_type(),
|
||||||
resource_id=resource_def.get_id(),
|
resource_id=resource_def.get_id(),
|
||||||
|
@ -296,7 +301,7 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
sleep=None, max_attempts=None,
|
sleep=None, max_attempts=None,
|
||||||
with_refresh=False):
|
with_refresh=False):
|
||||||
res_path = res_def.get_resource_full_path()
|
res_path = res_def.get_resource_full_path()
|
||||||
|
state = {}
|
||||||
if sleep is None:
|
if sleep is None:
|
||||||
sleep = self.nsxlib_config.realization_wait_sec
|
sleep = self.nsxlib_config.realization_wait_sec
|
||||||
if max_attempts is None:
|
if max_attempts is None:
|
||||||
|
@ -312,6 +317,9 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
if con_state == 'SUCCESS':
|
if con_state == 'SUCCESS':
|
||||||
return True
|
return True
|
||||||
if con_state == 'ERROR':
|
if con_state == 'ERROR':
|
||||||
|
LOG.error("_wait_until_state_successful errored for "
|
||||||
|
"resource: %s. Last consolidated_status result "
|
||||||
|
"was %s", res_path, state)
|
||||||
raise exceptions.RealizationErrorStateError(
|
raise exceptions.RealizationErrorStateError(
|
||||||
resource_type=res_def.resource_type(),
|
resource_type=res_def.resource_type(),
|
||||||
resource_id=res_def.get_id(),
|
resource_id=res_def.get_id(),
|
||||||
|
@ -328,6 +336,10 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
raise e
|
raise e
|
||||||
except Exception:
|
except Exception:
|
||||||
# max retries reached
|
# max retries reached
|
||||||
|
LOG.error("_wait_until_state_successful maxed-out for "
|
||||||
|
"resource: %s. Last consolidated_status result was %s",
|
||||||
|
res_path, state)
|
||||||
|
|
||||||
raise exceptions.RealizationTimeoutError(
|
raise exceptions.RealizationTimeoutError(
|
||||||
resource_type=res_def.resource_type(),
|
resource_type=res_def.resource_type(),
|
||||||
resource_id=res_def.get_id(),
|
resource_id=res_def.get_id(),
|
||||||
|
@ -337,7 +349,7 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
@check_allowed_passthrough
|
@check_allowed_passthrough
|
||||||
def _get_realized_id_using_search(self, policy_resource_path,
|
def _get_realized_id_using_search(self, policy_resource_path,
|
||||||
mp_resource_type, resource_def=None,
|
mp_resource_type, resource_def=None,
|
||||||
entity_type=None,
|
entity_type=None, silent=False,
|
||||||
sleep=None, max_attempts=None):
|
sleep=None, max_attempts=None):
|
||||||
"""Wait until the policy path will be found using search api
|
"""Wait until the policy path will be found using search api
|
||||||
|
|
||||||
|
@ -351,12 +363,13 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
tag = [{'scope': 'policyPath',
|
tag = [{'scope': 'policyPath',
|
||||||
'tag': utils.escape_tag_data(policy_resource_path)}]
|
'tag': utils.escape_tag_data(policy_resource_path)}]
|
||||||
|
resources = []
|
||||||
test_num = 0
|
test_num = 0
|
||||||
while test_num < max_attempts:
|
while test_num < max_attempts:
|
||||||
# Use the search api to find the realization id of this entity.
|
# Use the search api to find the realization id of this entity.
|
||||||
resources = self.nsx_api.search_by_tags(
|
resources = self.nsx_api.search_by_tags(
|
||||||
tags=tag, resource_type=mp_resource_type)['results']
|
tags=tag, resource_type=mp_resource_type,
|
||||||
|
silent=silent)['results']
|
||||||
if resources:
|
if resources:
|
||||||
# If status exists, make sure the state is successful
|
# If status exists, make sure the state is successful
|
||||||
if (not resources[0].get('status') or
|
if (not resources[0].get('status') or
|
||||||
|
@ -371,6 +384,9 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
if info and info['state'] == constants.STATE_ERROR:
|
if info and info['state'] == constants.STATE_ERROR:
|
||||||
error_msg, error_code, related_error_codes = \
|
error_msg, error_code, related_error_codes = \
|
||||||
self._get_realization_error_message_and_code(info)
|
self._get_realization_error_message_and_code(info)
|
||||||
|
LOG.error("_get_realized_id_using_search Failed for "
|
||||||
|
"resource: %s. Got error in realization info %s",
|
||||||
|
policy_resource_path, info)
|
||||||
raise exceptions.RealizationErrorStateError(
|
raise exceptions.RealizationErrorStateError(
|
||||||
resource_type=resource_def.resource_type(),
|
resource_type=resource_def.resource_type(),
|
||||||
resource_id=resource_def.get_id(),
|
resource_id=resource_def.get_id(),
|
||||||
|
@ -386,6 +402,10 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
test_num += 1
|
test_num += 1
|
||||||
|
|
||||||
# max retries reached
|
# max retries reached
|
||||||
|
LOG.error("_get_realized_id_using_search maxed-out for "
|
||||||
|
"resource: %s. Last search result was %s",
|
||||||
|
policy_resource_path, resources)
|
||||||
|
|
||||||
raise exceptions.RealizationTimeoutError(
|
raise exceptions.RealizationTimeoutError(
|
||||||
resource_type=mp_resource_type,
|
resource_type=mp_resource_type,
|
||||||
resource_id=policy_resource_path,
|
resource_id=policy_resource_path,
|
||||||
|
|
Loading…
Reference in New Issue