Browse Source

Append sort_by=id in search url

Manager uses elastic-search scoring and display_name as default
primary and secondary sort order respectively. In a Manager cluster,
each Manager has its own elastic-search instance, Thus the relevance
of scoring might differ due to different parameters, so pagination
result may differ too.

When NCP does a multi-page search, like retrieving all existing
logical ports in a scale setup, Manager VIP could be served by
different Managers during the search. Due to the above reason,
some entries could be missing or duplicated in the query result.

This patch appends "sort_by=id" in search url, therefore all
Managers could return the same pagination results.

Change-Id: Id26cf0cbcdaebb965890d5ee7934c11da056b128
(cherry picked from commit 6c7d58559f)
tags/16.0.4
Shih-Hao Li 3 weeks ago
committed by Salvatore Orlando
parent
commit
1d2ea12778
4 changed files with 12 additions and 20 deletions
  1. +1
    -1
      vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py
  2. +1
    -1
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  3. +4
    -4
      vmware_nsxlib/tests/unit/v3/test_resources.py
  4. +6
    -14
      vmware_nsxlib/v3/lib.py

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

@@ -1438,7 +1438,7 @@ class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase):
vs_name = 'test-name'
with self.mock_get(
vs_id, vs_name, lb_persistence_profile_path='test-profile'), \
self.mock_create_update() as update_call:
self.mock_create_update() as update_call:
self.resourceApi.remove_dlb_virtual_server_persistence_profile(
vs_id)
expected_def = lb_defs.LBVirtualServerDef(


+ 1
- 1
vmware_nsxlib/tests/unit/v3/policy/test_resources.py View File

@@ -6348,7 +6348,7 @@ class TestNsxSearch(NsxPolicyLibTestCase):

def setUp(self):
super(TestNsxSearch, self).setUp()
self.search_path = 'search/query?query=%s'
self.search_path = 'search/query?query=%s&sort_by=id'

def test_nsx_search_by_realization(self):
"""Test search of resources with the specified tag."""


+ 4
- 4
vmware_nsxlib/tests/unit/v3/test_resources.py View File

@@ -1764,7 +1764,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):

def setUp(self):
super(TestNsxSearch, self).setUp()
self.search_path = 'search?query=%s'
self.search_path = 'search?query=%s&sort_by=id'
self.mock = mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value=self.get_nsxlib_version())
self.mock.start()
@@ -1978,7 +1978,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
body = {"query_pipeline": [{"query": query}]}
self.nsxlib.search_resource_by_attribute_values(
resource_type, attr_name, attr_values)
search.assert_called_with("search/querypipeline", body)
search.assert_called_with("search/querypipeline?sort_by=id", body)

def test_nsx_search_resource_by_filters(self):
"""Test search resources with the specified filters."""
@@ -1992,7 +1992,7 @@ class TestNsxSearch(nsxlib_testcase.NsxClientTestCase):
"related": related}
self.nsxlib.search_resource_by_filters(
parent_type, filters, related=related)
search.assert_called_with("search/aggregate", body)
search.assert_called_with("search/aggregate?sort_by=id", body)

def test_get_id_by_resource_and_tag(self):
id = 'test'
@@ -2034,7 +2034,7 @@ class TestNsxSearchNew(TestNsxSearch):
def setUp(self):

super(TestNsxSearchNew, self).setUp()
self.search_path = 'search/query?query=%s'
self.search_path = 'search/query?query=%s&sort_by=id'

@staticmethod
def get_nsxlib_version():


+ 6
- 14
vmware_nsxlib/v3/lib.py View File

@@ -121,8 +121,8 @@ class NsxLibBase(object):
def _get_search_url(self):
if (version.LooseVersion(self.get_version()) >=
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
return "search/query?query=%s"
return "search?query=%s"
return "search/query?query=%s&sort_by=id"
return "search?query=%s&sort_by=id"

# TODO(abhiraut): Revisit this method to generate complex boolean
# queries to search resources.
@@ -223,12 +223,8 @@ class NsxLibBase(object):
" AND %s:(%s)" % (name, attribute_query)
if attribute_query else "")
body = {"query_pipeline": [{"query": query}]}
args = []
if cursor:
args.append("cursor=%d" % cursor)
if page_size:
args.append("page_size=%d" % page_size)
url = "search/querypipeline" + ("?%s" % "&".join(args) if args else "")
url = self._add_pagination_parameters(
"search/querypipeline?sort_by=id", cursor, page_size)

# Retry the search in case of error
@utils.retry_upon_exception(exceptions.NsxSearchError,
@@ -260,12 +256,8 @@ class NsxLibBase(object):
related = extra_attrs.get("related")
if related:
body["related"] = related
args = []
if cursor:
args.append("cursor=%d" % cursor)
if page_size:
args.append("page_size=%d" % page_size)
url = "search/aggregate" + ("?%s" % "&".join(args) if args else "")
url = self._add_pagination_parameters(
"search/aggregate?sort_by=id", cursor, page_size)

# Retry the search in case of error
@utils.retry_upon_exception(exceptions.NsxSearchError,


Loading…
Cancel
Save