[CP] 升级脚本python3改造
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
@ -37,12 +38,12 @@ class QueryCursor:
|
||||
if True == print_when_succ:
|
||||
logging.info('succeed to execute sql: %s, rowcount = %d', sql, rowcount)
|
||||
return rowcount
|
||||
except mysql.connector.Error, e:
|
||||
except mysql.connector.Error as e:
|
||||
logging.exception('mysql connector error, fail to execute sql: %s', sql)
|
||||
raise e
|
||||
except Exception, e:
|
||||
raise
|
||||
except Exception as e:
|
||||
logging.exception('normal error, fail to execute sql: %s', sql)
|
||||
raise e
|
||||
raise
|
||||
def exec_query(self, sql, print_when_succ = True):
|
||||
try:
|
||||
self.__cursor.execute(sql)
|
||||
@ -51,12 +52,12 @@ class QueryCursor:
|
||||
if True == print_when_succ:
|
||||
logging.info('succeed to execute query: %s, rowcount = %d', sql, rowcount)
|
||||
return (self.__cursor.description, results)
|
||||
except mysql.connector.Error, e:
|
||||
except mysql.connector.Error as e:
|
||||
logging.exception('mysql connector error, fail to execute sql: %s', sql)
|
||||
raise e
|
||||
except Exception, e:
|
||||
raise
|
||||
except Exception as e:
|
||||
logging.exception('normal error, fail to execute sql: %s', sql)
|
||||
raise e
|
||||
raise
|
||||
#### ---------------end----------------------
|
||||
|
||||
#### --------------start : opt.py --------------
|
||||
@ -196,10 +197,10 @@ def parse_options(argv):
|
||||
def deal_with_local_opt(opt):
|
||||
if 'help' == opt.get_long_name():
|
||||
global help_str
|
||||
print help_str
|
||||
print(help_str)
|
||||
elif 'version' == opt.get_long_name():
|
||||
global version_str
|
||||
print version_str
|
||||
print(version_str)
|
||||
|
||||
def deal_with_local_opts():
|
||||
global g_opts
|
||||
@ -300,9 +301,9 @@ def fetch_tenant_ids(query_cur):
|
||||
for r in results:
|
||||
tenant_id_list.append(r[0])
|
||||
return tenant_id_list
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.exception('fail to fetch distinct tenant ids')
|
||||
raise e
|
||||
raise
|
||||
|
||||
def set_default_timeout_by_tenant(query_cur, timeout, timeout_per_tenant, min_timeout):
|
||||
if timeout > 0:
|
||||
@ -386,7 +387,7 @@ def check_until_timeout(query_cur, sql, value, timeout):
|
||||
times -= 1
|
||||
if times == -1:
|
||||
logging.warn("""check {0} job timeout""".format(job_name))
|
||||
raise e
|
||||
raise MyError("""check {0} job timeout""".format(job_name))
|
||||
time.sleep(10)
|
||||
|
||||
# 开始健康检查
|
||||
@ -409,18 +410,18 @@ def do_check(my_host, my_port, my_user, my_passwd, upgrade_params, timeout, need
|
||||
check_server_version_by_zone(query_cur, zone)
|
||||
if True == need_check_major_status:
|
||||
check_major_merge(query_cur, timeout)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.exception('run error')
|
||||
raise e
|
||||
raise
|
||||
finally:
|
||||
cur.close()
|
||||
conn.close()
|
||||
except mysql.connector.Error, e:
|
||||
except mysql.connector.Error as e:
|
||||
logging.exception('connection error')
|
||||
raise e
|
||||
except Exception, e:
|
||||
raise
|
||||
except Exception as e:
|
||||
logging.exception('normal error')
|
||||
raise e
|
||||
raise
|
||||
|
||||
if __name__ == '__main__':
|
||||
upgrade_params = UpgradeParams()
|
||||
@ -444,10 +445,10 @@ if __name__ == '__main__':
|
||||
logging.info('parameters from cmd: host=\"%s\", port=%s, user=\"%s\", password=\"%s\", log-file=\"%s\", timeout=%s, zone=\"%s\"', \
|
||||
host, port, user, password.replace('"', '\\"'), log_filename, timeout, zone)
|
||||
do_check(host, port, user, password, upgrade_params, timeout, False, zone) # need_check_major_status = False
|
||||
except mysql.connector.Error, e:
|
||||
except mysql.connector.Error as e:
|
||||
logging.exception('mysql connctor error')
|
||||
raise e
|
||||
except Exception, e:
|
||||
raise
|
||||
except Exception as e:
|
||||
logging.exception('normal error')
|
||||
raise e
|
||||
raise
|
||||
|
||||
|
||||
Reference in New Issue
Block a user