"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mysql/utilities/common/replication.py" between
mysql-utilities-1.6.4.tar.gz and mysql-utilities-1.6.5.tar.gz

About: MySQL Utilities is a package of utilities that are used for maintenance and administration of MySQL servers (written in Python).

replication.py  (mysql-utilities-1.6.4):replication.py  (mysql-utilities-1.6.5)
skipping to change at line 146 skipping to change at line 146
# Copy options and add connected server # Copy options and add connected server
new_opts = options.copy() new_opts = options.copy()
new_opts["conn_info"] = server new_opts["conn_info"] = server
uname = None uname = None
master_values = {} master_values = {}
change_master = [] change_master = []
# If server is a master, perform error checking # If server is a master, perform error checking
# pylint: disable=R0101
if is_master: if is_master:
master = Master(new_opts) master = Master(new_opts)
master.connect() master.connect()
# Check master for binlog # Check master for binlog
if not master.binlog_enabled(): if not master.binlog_enabled():
raise UtilError("Master must have binary logging turned on.") raise UtilError("Master must have binary logging turned on.")
else: else:
# Check rpl user # Check rpl user
if rpl_user is None: if rpl_user is None:
# Try to find the replication user # Try to find the replication user
res = master.get_rpl_users() res = master.get_rpl_users()
if len(res) > 1: if len(res) > 1:
uname = "" uname = ""
passwd = "" passwd = ""
# Throw error if strict but not for rpl_mode = both # Throw error if strict but not for rpl_mode = both
if strict and not rpl_mode == 'both': if strict and rpl_mode != 'both':
raise UtilRplError(_NO_RPL_USER) raise UtilRplError(_NO_RPL_USER)
else: else:
change_master.append(_WARNING % _NO_RPL_USER) change_master.append(_WARNING % _NO_RPL_USER)
else: else:
uname = res[0][0] uname = res[0][0]
if res[0][2]: if res[0][2]:
# Throw error if strict but not for rpl_mode = both # Throw error if strict but not for rpl_mode = both
if strict and not rpl_mode == 'both': if strict and rpl_mode != 'both':
raise UtilRplError(_RPL_USER_PASS) raise UtilRplError(_RPL_USER_PASS)
else: else:
change_master.append(_WARNING % _RPL_USER_PASS) change_master.append(_WARNING % _RPL_USER_PASS)
passwd = res[0][1] passwd = res[0][1]
else: else:
# Parse username and password (supports login-paths) # Parse username and password (supports login-paths)
try: try:
uname, passwd = parse_user_password(rpl_user, options=option uname, passwd = parse_user_password(rpl_user,
s) options=options)
except FormatError as fmt_err: except FormatError:
raise UtilError (USER_PASSWORD_FORMAT.format("--rpl-user")) raise UtilError(USER_PASSWORD_FORMAT.format("--rpl-user"))
if not passwd: if not passwd:
passwd = '' passwd = ''
# Check replication user privileges # Check replication user privileges
errors = master.check_rpl_user(uname, master.host) errors = master.check_rpl_user(uname, master.host)
if errors != []: if errors != []:
raise UtilError(errors[0]) raise UtilError(errors[0])
res = master.get_status() res = master.get_status()
if not res: if not res:
skipping to change at line 572 skipping to change at line 574
if self.master is None or self.slave is None: if self.master is None or self.slave is None:
print "ERROR: Must connect to master and slave before " \ print "ERROR: Must connect to master and slave before " \
"calling replicate()" "calling replicate()"
return False return False
result = True result = True
# Parse user and password (support login-paths) # Parse user and password (support login-paths)
try: try:
r_user, r_pass = parse_user_password(rpl_user) r_user, r_pass = parse_user_password(rpl_user)
except FormatError as fmt_err: except FormatError:
raise UtilError (USER_PASSWORD_FORMAT.format("--rpl-user")) raise UtilError(USER_PASSWORD_FORMAT.format("--rpl-user"))
# Check to see if rpl_user is present, else create her # Check to see if rpl_user is present, else create her
if not self.create_rpl_user(r_user, r_pass)[0]: if not self.create_rpl_user(r_user, r_pass)[0]:
return False return False
# Read master log file information # Read master log file information
res = self.master.get_status() res = self.master.get_status()
if not res: if not res:
print "ERROR: Cannot retrieve master status." print "ERROR: Cannot retrieve master status."
return False return False
skipping to change at line 784 skipping to change at line 786
(user, passwd, host, port, socket) (user, passwd, host, port, socket)
role Name or role of server (e.g., server, master) role Name or role of server (e.g., server, master)
verbose print extra data during operations (optional) verbose print extra data during operations (optional)
default value = False default value = False
charset Default character set for the connection. charset Default character set for the connection.
(default latin1) (default latin1)
""" """
if options is None: if options is None:
options = {} options = {}
assert not options.get("conn_info") is None assert options.get("conn_info") is not None
self.options = options self.options = options
Server.__init__(self, options) Server.__init__(self, options)
def get_status(self): def get_status(self):
"""Return the master status """Return the master status
Returns result set Returns result set
""" """
return self.exec_query("SHOW MASTER STATUS") return self.exec_query("SHOW MASTER STATUS")
skipping to change at line 872 skipping to change at line 874
""" """
grants_enabled = self.grant_tables_enabled() grants_enabled = self.grant_tables_enabled()
if not grants_enabled: if not grants_enabled:
return (True, None) return (True, None)
if "]" in host: if "]" in host:
host = clean_IPv6(host) host = clean_IPv6(host)
# Create user class instance # Create user class instance
user = User(self, "%s:%s@%s:%s" % (r_user, r_pass, host, port)) user = User(self, "{0}:{1}@{2}:{3}".format(r_user, r_pass, host, port))
if not user.exists(): if not user.exists():
user.create() user.create()
# Save current user for privilege checking
user.current_user = "'{0}'@'{1}'".format(r_user, host)
if not user.has_privilege("*", "*", "REPLICATION SLAVE"): # Check privileges, but do not user the anonymous host
if not user.has_privilege("*", "*", "REPLICATION SLAVE",
globals_privs=False):
if verbosity > 0: if verbosity > 0:
print "# Granting replication access to replication user..." print "# Granting replication access to replication user..."
query_str = "GRANT REPLICATION SLAVE ON *.* TO '%s'@'%s' " % \ query_str = ("GRANT REPLICATION SLAVE ON *.* TO "
(r_user, host) "'{0}'@'{1}' ".format(r_user, host))
if r_pass: if r_pass:
query_str += "IDENTIFIED BY '%s'" % r_pass query_str += "IDENTIFIED BY '{0}'".format(r_pass)
if ssl: if ssl:
query_str = "{0} {1}".format(query_str, " REQUIRE SSL") query_str = "{0} {1}".format(query_str, " REQUIRE SSL")
try: try:
self.exec_query(query_str) self.exec_query(query_str)
except UtilError: except UtilError:
return (False, "ERROR: Cannot grant replication slave to " return (False, "ERROR: Cannot grant replication slave to "
"replication user.") "replication user.")
return (True, None) return (True, None)
skipping to change at line 985 skipping to change at line 991
else: else:
slave_info = "unknown host" slave_info = "unknown host"
slave_info += ":%s" % port slave_info += ":%s" % port
return slave_info return slave_info
slaves = [] slaves = []
no_host_slaves = [] no_host_slaves = []
connect_error_slaves = [] connect_error_slaves = []
res = self.exec_query("SHOW SLAVE HOSTS") res = self.exec_query("SHOW SLAVE HOSTS")
verbose = self.options.get("verbose", False) verbose = self.options.get("verbose", False)
if not res == []: if res != []:
# Sort for conformity # Sort for conformity
res.sort() # pylint: disable=E1103 res.sort() # pylint: disable=E1103
for row in res: for row in res:
info = _get_slave_info(row[1], row[2]) info = _get_slave_info(row[1], row[2])
conn_dict = { conn_dict = {
'conn_info': {'user': user, 'passwd': password, 'conn_info': {'user': user, 'passwd': password,
'host': row[1], 'port': row[2], 'host': row[1], 'port': row[2],
'socket': None, 'ssl_ca': self.ssl_ca, 'socket': None, 'ssl_ca': self.ssl_ca,
'ssl_cert': self.ssl_cert, 'ssl_cert': self.ssl_cert,
skipping to change at line 1311 skipping to change at line 1317
(user, passwd, host, port, socket) (user, passwd, host, port, socket)
role Name or role of server (e.g., server, master) role Name or role of server (e.g., server, master)
verbose print extra data during operations (optional) verbose print extra data during operations (optional)
default value = False default value = False
charset Default character set for the connection. charset Default character set for the connection.
(default latin1) (default latin1)
""" """
if options is None: if options is None:
options = {} options = {}
assert not options.get("conn_info") is None assert options.get("conn_info") is not None
self.options = options self.options = options
Server.__init__(self, options) Server.__init__(self, options)
self.master_info = None self.master_info = None
def get_status(self, col_options=None): def get_status(self, col_options=None):
"""Return the slave status """Return the slave status
col_options[in] options for displaying columns (optional) col_options[in] options for displaying columns (optional)
skipping to change at line 1576 skipping to change at line 1582
if not res: if not res:
return None return None
rpl_do_db = res[0][_SLAVE_DO_DB] rpl_do_db = res[0][_SLAVE_DO_DB]
rpl_ignore_db = res[0][_SLAVE_IGNORE_DB] rpl_ignore_db = res[0][_SLAVE_IGNORE_DB]
rpl_do_table = res[0][_SLAVE_DO_TABLE] rpl_do_table = res[0][_SLAVE_DO_TABLE]
rpl_ignore_table = res[0][_SLAVE_IGNORE_TABLE] rpl_ignore_table = res[0][_SLAVE_IGNORE_TABLE]
rpl_wild_do_table = res[0][_SLAVE_WILD_DO_TABLE] rpl_wild_do_table = res[0][_SLAVE_WILD_DO_TABLE]
rpl_wild_ignore_table = res[0][_SLAVE_WILD_IGNORE_TABLE] rpl_wild_ignore_table = res[0][_SLAVE_WILD_IGNORE_TABLE]
if (rpl_do_db or rpl_ignore_db or rpl_do_table or rpl_ignore_table if (rpl_do_db or rpl_ignore_db or rpl_do_table or rpl_ignore_table or
or rpl_wild_do_table or rpl_wild_ignore_table): rpl_wild_do_table or rpl_wild_ignore_table):
return (rpl_do_db, rpl_ignore_db, rpl_do_table, rpl_ignore_table, return (rpl_do_db, rpl_ignore_db, rpl_do_table, rpl_ignore_table,
rpl_wild_do_table, rpl_wild_ignore_table) rpl_wild_do_table, rpl_wild_ignore_table)
else: else:
return () return ()
def show_status(self): def show_status(self):
"""Display the slave status from the slave server """Display the slave status from the slave server
""" """
col_options = { col_options = {
'columns': True 'columns': True
skipping to change at line 1945 skipping to change at line 1951
if master_user: if master_user:
change_master += "MASTER_USER = '%s', " % master_user change_master += "MASTER_USER = '%s', " % master_user
# To rewrite a current password with blank password, not check against # To rewrite a current password with blank password, not check against
# empty string. # empty string.
if master_passwd is not None: if master_passwd is not None:
change_master += "MASTER_PASSWORD = '%s', " % master_passwd change_master += "MASTER_PASSWORD = '%s', " % master_passwd
change_master += "MASTER_PORT = %s" % master_port change_master += "MASTER_PORT = %s" % master_port
if master_ssl and master_ssl not in ('0', 'OFF'): if master_ssl and master_ssl not in ('0', 'OFF'):
change_master = "{0}, MASTER_SSL = {1}".format(change_master, 1) change_master = "{0}, MASTER_SSL = {1}".format(change_master, 1)
if master_ssl_ca is not None: if master_ssl_ca is not None:
change_master = ("{0}, MASTER_SSL_CA = '{1}'" change_master = (
).format(change_master, master_ssl_ca) "{0}, MASTER_SSL_CA = '{1}'"
).format(change_master, master_ssl_ca)
if master_ssl_cert: if master_ssl_cert:
change_master = ("{0}, MASTER_SSL_CERT = '{1}'" change_master = (
).format(change_master, master_ssl_cert) "{0}, MASTER_SSL_CERT = '{1}'"
).format(change_master, master_ssl_cert)
if master_ssl_key: if master_ssl_key:
change_master = ("{0}, MASTER_SSL_KEY = '{1}'" change_master = (
).format(change_master, master_ssl_key) "{0}, MASTER_SSL_KEY = '{1}'"
).format(change_master, master_ssl_key)
if self.supports_gtid() == "ON": if self.supports_gtid() == "ON":
change_master += ", MASTER_AUTO_POSITION=1" change_master += ", MASTER_AUTO_POSITION=1"
elif not from_beginning: elif not from_beginning:
change_master += ", MASTER_LOG_FILE = '%s'" % master_log_file change_master += ", MASTER_LOG_FILE = '%s'" % master_log_file
if master_log_pos >= 0: if master_log_pos >= 0:
change_master += ", MASTER_LOG_POS = %s" % master_log_pos change_master += ", MASTER_LOG_POS = %s" % master_log_pos
return change_master return change_master
def is_configured_for_master(self, master, verify_state=False, def is_configured_for_master(self, master, verify_state=False,
 End of changes. 17 change blocks. 
24 lines changed or deleted 32 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS