Skip to content

Commit 32973c1

Browse files
CE-59 Couchbase Plugin : Conversion of python2 to python3 (#38)
1 parent c7b0bc3 commit 32973c1

File tree

17 files changed

+131
-132
lines changed

17 files changed

+131
-132
lines changed

plugin_config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
id: 18f4ff11-b758-4bf2-9a37-719a22f5a4b8
22
name: sc:couchbase
3-
externalVersion: "1.1.4"
4-
buildNumber: 1.1.4.0
5-
language: PYTHON27
3+
externalVersion: "1.2.0"
4+
buildNumber: 1.2.0.0
5+
language: PYTHON38
66
hostTypes:
77
- UNIX
88
pluginType: STAGED

src/controller/couchbase_lib/_bucket.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def bucket_list(self, return_type=list):
139139
logger.debug("parse json")
140140
bucket_list_dict = json.loads(bucket_list)
141141
logger.debug("remap json")
142-
bucket_list_dict = map(helper_lib.remap_bucket_json, bucket_list_dict)
142+
bucket_list_dict = list(map(helper_lib.remap_bucket_json, bucket_list_dict))
143143
logger.debug("Bucket details in staged environment: {}".format(bucket_list))
144144
return bucket_list_dict
145145

@@ -179,13 +179,13 @@ def monitor_bucket(self, bucket_name, staging_UUID):
179179
stdout, stderr, exit_code = utilities.execute_bash(self.connection, command, **kwargs)
180180
logger.debug("stdout: {}".format(stdout))
181181
content = json.loads(stdout)
182-
pending_docs = self._get_last_value_of_node_stats(content["nodeStats"].values()[0])
182+
pending_docs = self._get_last_value_of_node_stats(list(content["nodeStats"].values())[0])
183183
while pending_docs != 0:
184184
logger.debug("Documents pending for replication: {}".format(pending_docs))
185185
helper_lib.sleepForSecond(30)
186186
stdout, stderr, exit_code = utilities.execute_bash(self.connection, command, **kwargs)
187187
content = json.loads(stdout)
188-
pending_docs = self._get_last_value_of_node_stats(content["nodeStats"].values()[0])
188+
pending_docs = self._get_last_value_of_node_stats(list(content["nodeStats"].values())[0])
189189
else:
190190
logger.debug("Replication for bucket {} completed".format(bucket_name))
191191

src/controller/couchbase_lib/_mixin_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def inner(*args, **kwargs):
3636
try:
3737
return function(*args, **kwargs)
3838
except AttributeError as AE:
39-
logger.debug("Failed to read value from schema objects. Error: {}".format(AE.message))
39+
logger.debug("Failed to read value from schema objects. Error: {}".format(str(AE)))
4040
raise
4141
return inner

src/controller/couchbase_lib/_xdcr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def xdcr_replicate(self, src, tgt):
7979
logger.debug("{} : XDCR replication create succeeded".format(tgt))
8080
helper_lib.sleepForSecond(2)
8181
except Exception as e:
82-
logger.debug("XDCR error {}".format(e.message))
82+
logger.debug("XDCR error {}".format(str(e)))
8383

8484

8585
def get_replication_uuid(self):
@@ -165,7 +165,7 @@ def get_replication_uuid(self):
165165
except UserError:
166166
raise
167167
except Exception as err:
168-
logger.warn("Error identified: {} ".format(err.message))
168+
logger.warn("Error identified: {} ".format(str(err)))
169169
logger.warn("UUID is None. Not able to find any cluster")
170170
return None
171171

src/controller/couchbase_operation.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def run_couchbase_command(self, couchbase_command, **kwargs):
117117

118118
logger.debug("couchbase command to run: {}".format(command))
119119
stdout, stderr, exit_code = utilities.execute_bash(self.connection, command, environment_vars=env)
120-
return [stdout.encode('utf-8'), stderr.encode('utf-8'), exit_code]
120+
return [stdout, stderr, exit_code]
121121

122122

123123
def run_os_command(self, os_command, **kwargs):
@@ -131,7 +131,7 @@ def run_os_command(self, os_command, **kwargs):
131131

132132
logger.debug("os command to run: {}".format(command))
133133
stdout, stderr, exit_code = utilities.execute_bash(self.connection, command)
134-
return [stdout.encode('utf-8'), stderr.encode('utf-8'), exit_code]
134+
return [stdout, stderr, exit_code]
135135

136136

137137
def restart_couchbase(self, provision=False):
@@ -190,9 +190,9 @@ def stop_couchbase(self):
190190
except Exception as err:
191191
logger.debug("Exception Error: {}".format(err))
192192
if self.status() == Status.INACTIVE:
193-
logger.debug("Seems like couchbase service is not running. {}".format(err.message))
193+
logger.debug("Seems like couchbase service is not running. {}".format(str(err)))
194194
else:
195-
raise CouchbaseServicesError(err.message)
195+
raise CouchbaseServicesError(str(err))
196196

197197

198198
def ip_file_name(self):
@@ -253,7 +253,7 @@ def staging_bootstrap_status(self):
253253
# TODO
254254
# rewrite it
255255
logger.debug("Exception: {}".format(str(error)))
256-
if re.search("Unable to connect to host at", error.message):
256+
if re.search("Unable to connect to host at", str(error)):
257257
logger.debug("Couchbase service is not running")
258258
return Status.INACTIVE
259259

@@ -339,7 +339,7 @@ def status(self, provision=False):
339339
# TODO
340340
# rewrite it
341341
logger.debug("Exception: {}".format(str(error)))
342-
if re.search("Unable to connect to host at", error.message):
342+
if re.search("Unable to connect to host at", str(error)):
343343
logger.debug("Couchbase service is not running")
344344
return Status.INACTIVE
345345

@@ -399,6 +399,8 @@ def create_config_dir(self):
399399
while loop_var:
400400
bin_directory = os.path.dirname(bin_directory)
401401
loop_var = loop_var - 1
402+
logger.debug(f"bin_directory={bin_directory}")
403+
logger.debug(f"DELPHIX_HIDDEN_FOLDER={DELPHIX_HIDDEN_FOLDER}")
402404
dir_name = bin_directory + "/" + DELPHIX_HIDDEN_FOLDER
403405
if not helper_lib.check_dir_present(self.connection, dir_name):
404406
self.make_directory(dir_name, force_env_user=True)
@@ -440,7 +442,7 @@ def source_bucket_list(self):
440442
bucket_list = bucket_list.replace("False", "\"False\"")
441443
logger.debug("parse json")
442444
bucket_list_dict = json.loads(bucket_list)
443-
bucket_list_dict = map(helper_lib.remap_bucket_json, bucket_list_dict)
445+
bucket_list_dict = list(map(helper_lib.remap_bucket_json, bucket_list_dict))
444446

445447
logger.debug("Source Bucket Information {}".format(bucket_list_dict))
446448
return bucket_list_dict
@@ -488,7 +490,7 @@ def source_bucket_list_offline(self):
488490

489491
backup_list = bucket_list.split('\n')
490492
logger.debug("Bucket search output: {}".format(backup_list))
491-
date_list = map(self.get_backup_date, backup_list)
493+
date_list = list(map(self.get_backup_date, backup_list))
492494
date_list.sort()
493495
logger.debug("date list: {}".format(date_list))
494496
files_to_process = [ x for x in backup_list if date_list[-1] in x ]
@@ -647,7 +649,7 @@ def check_index_build(self):
647649
tobuild = 1
648650

649651
#break the loop either end_time is exceeding from 1 minute or server is successfully started
650-
while time.time() < end_time and tobuild <> 0:
652+
while time.time() < end_time and tobuild != 0:
651653

652654
command_output, std_err, exit_code = self.run_couchbase_command(
653655
couchbase_command='check_index_build',
@@ -976,18 +978,14 @@ def rename_cluster(self):
976978

977979
logger.debug("rename cluster - exit_code: {} stdout: {} std_err: {}".format(exit_code, command_output, std_err))
978980

979-
980-
981-
982-
983981
def start_node_bootstrap(self):
984982
logger.debug("start start_node_bootstrap")
985983
self.start_couchbase(no_wait=True)
986984
end_time = time.time() + 3660
987985
server_status = Status.INACTIVE
988986

989987
#break the loop either end_time is exceeding from 1 minute or server is successfully started
990-
while time.time() < end_time and server_status<>Status.ACTIVE:
988+
while time.time() < end_time and server_status != Status.ACTIVE:
991989
helper_lib.sleepForSecond(1) # waiting for 1 second
992990
server_status = self.staging_bootstrap_status() # fetching status
993991
logger.debug("server status {}".format(server_status))
@@ -1068,6 +1066,6 @@ def addnode(self, nodeno, node_def):
10681066

10691067

10701068
if __name__ == "__main__":
1071-
print "Checking Couchbase Class"
1069+
# print "Checking Couchbase Class"
10721070
test_object = CouchbaseOperation(Resource.ObjectBuilder.set_dsource(True).build())
10731071
print (test_object.get_config_file_path.__doc__)

src/controller/db_exception_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __new__(mcs, caller_name, caller_base_name, attributes_in_caller):
4747
return super(DatabaseExceptionHandlerMeta, mcs).__new__(mcs, caller_name, caller_base_name,
4848
attributes_in_caller)
4949
except Exception as err:
50-
logger.debug("Exception occurred in metaclass: {}".format(err.message))
50+
logger.debug("Exception occurred in metaclass: {}".format(str(err)))
5151
raise
5252

5353
@classmethod
@@ -94,13 +94,13 @@ def wrapper_function(*args, **kwargs):
9494
raise
9595

9696
except Exception as error:
97-
logger.debug("Caught Exception : {}".format(error.message))
97+
logger.debug("Caught Exception : {}".format(str(error)))
9898
logger.debug("pioro")
9999
ttype, value, traceb = sys.exc_info()
100100
logger.debug("type: {}, value: {}".format(ttype, value))
101101
logger.debug("trackback")
102102
logger.debug(traceback.format_exc())
103-
mcs._exception_generator_factory(error.message)
103+
mcs._exception_generator_factory(str(error))
104104

105105
return wrapper_function
106106

src/controller/helper_lib.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import time
2222
from datetime import datetime
2323

24-
import db_commands.constants
24+
import db_commands
2525
from db_commands.commands import CommandFactory
2626
from db_commands.constants import DEFAULT_CB_BIN_PATH
2727
from dlpx.virtualization.platform.exceptions import UserError
@@ -240,7 +240,7 @@ def filter_bucket_name_from_output(bucket_output):
240240
logger.debug("filter input: {}".format(bucket_output))
241241
logger.debug("filter input: {}".format(len(bucket_output)))
242242
if bucket_output != []:
243-
output = map(lambda x: x["name"], bucket_output)
243+
output = list(map(lambda x: x["name"], bucket_output))
244244
logger.debug("Bucket list: {}".format(output))
245245
return output
246246

@@ -337,7 +337,7 @@ def check_dir_present(connection, dir):
337337
logger.debug("dir path found {} ".format(dir))
338338
return True
339339
except Exception as err:
340-
logger.debug("directory path is absent: {}".format(err.message))
340+
logger.debug("directory path is absent: {}".format(str(err)))
341341
return False
342342

343343

@@ -367,8 +367,8 @@ def unmount_file_system(rx_connection, path):
367367
try:
368368
utilities.execute_bash(rx_connection, CommandFactory.unmount_file_system(path))
369369
except Exception as err:
370-
logger.debug("error here {}".format(err.message))
371-
raise UnmountFileSystemError(err.message)
370+
logger.debug("error here {}".format(str(err)))
371+
raise UnmountFileSystemError(str(err))
372372

373373

374374
def get_bucket_size_in_MB(bucket_size, bkt_name_size):
@@ -402,7 +402,7 @@ def check_stale_mountpoint(connection, path):
402402
return False
403403
else:
404404
logger.error("df retured error - stale mount point or other error")
405-
logger.error("stdout: {} stderr: {} exit_code: {}".format(output.encode('utf-8'), stderr.encode('utf-8'), exit_code))
405+
logger.error("stdout: {} stderr: {} exit_code: {}".format(output, stderr, exit_code))
406406
return True
407407
else:
408408
return False
@@ -415,7 +415,7 @@ def check_server_is_used(connection, path):
415415
output, stderr, exit_code = utilities.execute_bash(connection, CommandFactory.mount())
416416
if exit_code != 0:
417417
logger.error("mount retured error")
418-
logger.error("stdout: {} stderr: {} exit_code: {}".format(output.encode('utf-8'), stderr.encode('utf-8'), exit_code))
418+
logger.error("stdout: {} stderr: {} exit_code: {}".format(output, stderr, exit_code))
419419
raise UserError("Problem with reading mounted file systems", "Ask OS admin to check mount", stderr)
420420
else:
421421
# parse a mount output to find another Delphix mount points

src/controller/resource_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#######################################################################################################################
3535

3636
import logging
37-
from db_exception_handler import DatabaseExceptionHandlerMeta
37+
from controller.db_exception_handler import DatabaseExceptionHandlerMeta
3838

3939
logger = logging.getLogger(__name__)
4040

0 commit comments

Comments
 (0)