Skip to content

Commit 8797daa

Browse files
committed
Update Curl calls to use full index names for FTS
Change-Id: I4b895ade31453b5400e91fb05d275778cb8d1811 Reviewed-on: https://review.couchbase.org/c/testrunner/+/244277 Tested-by: <dananjay.s@couchbase.com> Reviewed-by: Balakumaran G <balakumaran.gopal@couchbase.com>
1 parent 30b8c57 commit 8797daa

7 files changed

Lines changed: 68 additions & 25 deletions

File tree

lib/membase/api/on_prem_rest_client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,7 +4127,7 @@ def load_synonym_source(self,bucket="default",scope="_default",collection="_defa
41274127
return status, json_parsed
41284128

41294129
def create_fts_index(self, index_name, params, bucket="_default", scope="_default",mode =None):
4130-
"""create or edit fts index , returns {"status":"ok"} on success"""
4130+
"""create or edit fts index , returns (status, full_index_name) on success"""
41314131
api = self.fts_baseUrl + "api/index/{0}".format(index_name)
41324132
if self.is_elixir:
41334133
if scope is None:
@@ -4139,10 +4139,18 @@ def create_fts_index(self, index_name, params, bucket="_default", scope="_defaul
41394139
return status, content
41404140

41414141
if status:
4142-
log.info("Index {0} created".format(index_name))
4142+
full_name = index_name
4143+
try:
4144+
response = json.loads(content)
4145+
if 'name' in response:
4146+
full_name = response['name']
4147+
log.info("Index created with full name: {0}".format(full_name))
4148+
except (json.JSONDecodeError, TypeError, ValueError):
4149+
pass
4150+
log.info("Index {0} created".format(full_name))
4151+
return status, full_name
41434152
else:
41444153
raise Exception("Error creating index: {0}".format(content))
4145-
return status
41464154

41474155
def update_fts_index(self, index_name, index_def, bucket="_default", scope="_default",mode=None):
41484156
api = self.fts_baseUrl + "api/index/{0}".format(index_name)

pytests/fts/fts_base.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,18 +1320,40 @@ def get_rank_of_doc_in_search_results(self, content, doc_id):
13201320
self.__log.info("Doc ID %s not found in search results." % doc_id)
13211321
return -1
13221322

1323+
def _build_full_index_name(self):
1324+
"""Construct the fully-prefixed index name (bucket.scope.name) for global endpoint."""
1325+
if self._source_name and self.index_type != "fulltext-alias":
1326+
scope = self.scope if self.scope else "_default"
1327+
return "{0}.{1}.{2}".format(self._source_name, scope, self.name)
1328+
return self.name
1329+
1330+
def _update_index_name(self, full_name):
1331+
"""Update index name to the server-assigned full name if it differs."""
1332+
if full_name and full_name != self.name and not self.is_elixir:
1333+
self.__log.info("Index name updated from '{0}' to '{1}'".format(
1334+
self.name, full_name))
1335+
self.name = full_name
1336+
self.index_definition['name'] = full_name
1337+
13231338
def create(self, rest=None):
13241339
self.__log.info("Checking if index already exists ...")
13251340
if not rest:
13261341
rest = RestConnection(self.__cluster.get_random_fts_node())
13271342
status, _ = rest.get_fts_index_definition(self.name, self._source_name, self.scope)
13281343
if status != 400:
13291344
rest.delete_fts_index(self.name, self._source_name, self.scope)
1345+
else:
1346+
full_name = self._build_full_index_name()
1347+
if full_name != self.name:
1348+
status, _ = rest.get_fts_index_definition(full_name, self._source_name, self.scope)
1349+
if status != 400:
1350+
rest.delete_fts_index(full_name, self._source_name, self.scope)
13301351
self.__log.info("Creating {0} {1} on {2}".format(
13311352
self.index_type,
13321353
self.name,
13331354
rest.ip))
1334-
rest.create_fts_index(self.name, self.index_definition, self._source_name, self.scope)
1355+
_, full_name = rest.create_fts_index(self.name, self.index_definition, self._source_name, self.scope)
1356+
self._update_index_name(full_name)
13351357
self.__cluster.get_indexes().append(self)
13361358
self.uuid = self.get_uuid()
13371359
global_vars.system_event_logs.add_event(SearchServiceEvents.index_created(rest.ip, self.uuid,
@@ -1344,7 +1366,8 @@ def create_no_check(self, rest=None):
13441366
self.index_type,
13451367
self.name,
13461368
rest.ip))
1347-
rest.create_fts_index(self.name, self.index_definition, self._source_name, self.scope)
1369+
_, full_name = rest.create_fts_index(self.name, self.index_definition, self._source_name, self.scope)
1370+
self._update_index_name(full_name)
13481371
self.__cluster.get_indexes().append(self)
13491372

13501373
def update(self, rest=None):
@@ -3238,15 +3261,15 @@ def create_fts_index_wait_for_completion(self, sample_index_name_1, sample_bucke
32383261
return fts_idx
32393262

32403263
def get_fts_index_by_name(self, name):
3241-
""" Returns an FTSIndex object with the given name """
3264+
""" Returns an FTSIndex object with the given name (supports both short and full prefixed names) """
32423265
for index in self.__indexes:
3243-
if index.name == name:
3266+
if index.name == name or index.name.endswith('.' + name):
32443267
return index
32453268

32463269
def delete_fts_index(self, name):
3247-
""" Delete an FTSIndex object with the given name from a given node """
3270+
""" Delete an FTSIndex object with the given name from a given node (supports both short and full prefixed names) """
32483271
for index in self.__indexes.copy():
3249-
if index.name == name:
3272+
if index.name == name or index.name.endswith('.' + name):
32503273
index.delete()
32513274

32523275
def delete_all_fts_indexes(self):

pytests/fts/fts_callable.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ def create_alias(self, target_indexes, name=None, alias_def=None, bucket=None, s
368368
scope=scope)
369369

370370
def delete_fts_index(self, name):
371-
""" Delete an FTSIndex object with the given name from a given node """
371+
""" Delete an FTSIndex object with the given name from a given node (supports both short and full prefixed names) """
372372
for index in self.fts_indexes:
373-
if index.name == name:
373+
if index.name == name or index.name.endswith('.' + name):
374374
index.delete()
375375

376376
def delete_all(self):
@@ -642,9 +642,15 @@ def check_if_index_exists(self, index_name, bucket_name=None, scope_name=None, i
642642
Returns true / false if index exists
643643
Returns index's node and server group distribution if required -> node_def = True
644644
Returns index definition if required -> index_def = True
645+
Tries both the short name and the fully-prefixed name (bucket.scope.name).
645646
"""
646647
rest = RestConnection(self.cb_cluster.get_random_fts_node())
647648
resp = rest.get_fts_index_definition(index_name, bucket_name, scope_name)
649+
if not resp[0] and bucket_name:
650+
scope = scope_name if scope_name else "_default"
651+
full_name = "{0}.{1}.{2}".format(bucket_name, scope, index_name)
652+
if full_name != index_name:
653+
resp = rest.get_fts_index_definition(full_name, bucket_name, scope_name)
648654
if resp[0]:
649655
if node_def:
650656
return resp[1]['planPIndexes'][0]['nodes']

pytests/fts/rbac_fts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def delete_index_with_no_credentials(self):
115115
rest = self.get_rest_handle_for_credentials("Administrator", "password")
116116
index.create(rest)
117117

118-
api = "http://{0}:8094/api/index/travel".format(server.ip)
118+
api = "http://{0}:8094/api/index/{1}".format(server.ip, index.name)
119119
response, content = httplib2.Http(timeout=120).request(api,
120120
"DELETE",
121121
headers=None)
@@ -139,7 +139,7 @@ def get_index_with_no_credentials(self):
139139
rest = self.get_rest_handle_for_credentials("Administrator", "password")
140140
index.create(rest)
141141

142-
api = "http://{0}:8094/api/index/travel".format(server.ip)
142+
api = "http://{0}:8094/api/index/{1}".format(server.ip, index.name)
143143
response, content = httplib2.Http(timeout=120).request(api,
144144
"GET",
145145
headers=None)
@@ -164,7 +164,7 @@ def query_index_with_no_credentials(self):
164164
index.create(rest)
165165
self.wait_for_indexing_complete()
166166

167-
api = "http://{0}:8094/api/index/travel/query?".format(server.ip)
167+
api = "http://{0}:8094/api/index/{1}/query?".format(server.ip, index.name)
168168
query = {"match": "Wick", "field": "city"}
169169
import urllib.request, urllib.parse, urllib.error
170170
api = api + urllib.parse.urlencode(query)

pytests/fts/stable_topology_fts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,12 +2833,14 @@ def test_ssl(self):
28332833

28342834
self.log.info("Running command : {0}".format(cmd))
28352835
output = subprocess.check_output(cmd, shell=True)
2836-
if json.loads(output)["status"] == "ok":
2836+
create_response = json.loads(output)
2837+
if create_response["status"] == "ok":
2838+
full_index_name = create_response.get("name", "default_idx")
28372839
query = "curl -g -k " + \
28382840
"-XPOST -H \"Content-Type: application/json\" " + \
28392841
"-u Administrator:password " + \
2840-
"https://{0}:18094/api/index/default_idx/query -d ". \
2841-
format(fts_node.ip, fts_ssl_port) + \
2842+
"https://{0}:18094/api/index/{1}/query -d ". \
2843+
format(fts_node.ip, full_index_name) + \
28422844
"\'{0}\'".format(json.dumps(qry))
28432845
self.sleep(20, "wait for indexing to complete")
28442846
output = subprocess.check_output(query, shell=True)

pytests/logredaction/log_redaction_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,14 @@ def test_fts_log_redaction(self):
585585
password='password')
586586
rest.create_bucket(bucket="default", ramQuotaMB=256)
587587
self.sleep(15)
588-
status = rest.create_fts_index("index1", index_definition)
588+
status, full_index_name = rest.create_fts_index("index1", index_definition)
589589
if status:
590-
log.info("Index 'index1' created")
590+
log.info("Index '{0}' created".format(full_index_name))
591591
else:
592592
log.info("Error creating index, status = {0}".format(status))
593593
self.sleep(60, "waiting for docs to get indexed")
594594
query_json = {"query": {"field": "type", "match": "emp"}}
595-
hits, _, _, _ = rest.run_fts_query(index_name="index1",
595+
hits, _, _, _ = rest.run_fts_query(index_name=full_index_name,
596596
query_json=query_json)
597597
log.info("Hits from query {0}: {1}".format(query_json, hits))
598598
self.set_redaction_level()

pytests/security/x509tests.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,21 +1006,25 @@ def check_fts_service(self, host):
10061006
else:
10071007
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/default_idx', port=18094, headers=" -XPUT -H \"Content-Type: application/json\" -u Administrator:password ",
10081008
client_cert=False, curl=True, verb='GET', data="'" + json.dumps(idx) + "'")
1009-
self.assertEqual(json.loads(output)['status'], "ok", "Issue with creating FTS index with client Cert")
1009+
create_resp = json.loads(output)
1010+
self.assertEqual(create_resp['status'], "ok", "Issue with creating FTS index with client Cert")
1011+
full_idx_name = create_resp.get('name', 'default_idx')
10101012

10111013
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/default_idx01', port=self.fts_port, headers=" -XPUT -H \"Content-Type: application/json\" -u Administrator:password ",
10121014
client_cert=False, curl=True, verb='GET', data="'" + json.dumps(idx) + "'", plain_curl=True)
1013-
self.assertEqual(json.loads(output)['status'], "ok", "Issue with creating FTS index with client Cert")
1015+
create_resp_01 = json.loads(output)
1016+
self.assertEqual(create_resp_01['status'], "ok", "Issue with creating FTS index with client Cert")
1017+
full_idx01_name = create_resp_01.get('name', 'default_idx01')
10141018

10151019
if self.client_cert_state == 'enable':
1016-
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/default_idx', port=18094, headers=" -H \"Content-Type: application/json\" ",
1020+
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/{0}'.format(full_idx_name), port=18094, headers=" -H \"Content-Type: application/json\" ",
10171021
client_cert=True, curl=True, verb='DELETE')
10181022
else:
1019-
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/default_idx', port=18094, headers=" -H \"Content-Type: application/json\" -u Administrator:password ",
1023+
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/{0}'.format(full_idx_name), port=18094, headers=" -H \"Content-Type: application/json\" -u Administrator:password ",
10201024
client_cert=False, curl=True, verb='DELETE')
10211025
self.assertEqual(json.loads(output)['status'], "ok", "Issue with deleteing FTS index with client Cert")
10221026

1023-
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/default_idx01', port=self.fts_port, headers=" -H \"Content-Type: application/json\" -u Administrator:password ",
1027+
output = x509main()._execute_command_clientcert(host.ip, url='/api/index/{0}'.format(full_idx01_name), port=self.fts_port, headers=" -H \"Content-Type: application/json\" -u Administrator:password ",
10241028
client_cert=False, curl=True, verb='DELETE', plain_curl=True)
10251029
self.assertEqual(json.loads(output)['status'], "ok", "Issue with deleteing FTS index on 8094")
10261030

0 commit comments

Comments
 (0)