def check_replication(master_vals, slave_vals, options): """Check replication among a master and a slave. master_vals[in] Master connection in form: user:passwd@host:port:socket or login-path:port:socket slave_vals[in] Slave connection in form user:passwd@host:port:socket or login-path:port:socket options[in] dictionary of options (verbosity, quiet, pedantic) Returns bool - True if all tests pass, False if errors, warnings, failures """ quiet = options.get("quiet", False) width = options.get("width", 75) slave_status = options.get("slave_status", False) test_errors = False conn_options = { 'quiet': quiet, 'src_name': "master", 'dest_name': 'slave', 'version': "5.0.0", 'unique': True, } certs_paths = {} if 'ssl_ca' in dir(options) and options.ssl_ca is not None: certs_paths['ssl_ca'] = options.ssl_ca if 'ssl_cert' in dir(options) and options.ssl_cert is not None: certs_paths['ssl_cert'] = options.ssl_cert if 'ssl_key' in dir(options) and options.ssl_key is not None: certs_paths['ssl_key'] = options.ssl_key conn_options.update(certs_paths) servers = connect_servers(master_vals, slave_vals, conn_options) rpl_options = options.copy() rpl_options['verbosity'] = options.get("verbosity", 0) > 0 # Create an instance of the replication object rpl = Replication(servers[0], servers[1], rpl_options) if not quiet: print "Test Description", print ' ' * (width - 24), print "Status" print '-' * width for test in _get_replication_tests(rpl, options): if not test.exec_test(): test_errors = True if slave_status and not quiet: try: print "\n#\n# Slave status: \n#" rpl.slave.show_status() except UtilRplError, e: print "ERROR:", e.errmsg
def setup_replication(master_vals, slave_vals, rpl_user, options, test_db=None): """Setup replication among a master and a slave. master_vals[in] Master connection in form user:passwd@host:port:sock slave_vals[in] Slave connection in form user:passwd@host:port:sock rpl_user[in] Replication user in the form user:passwd options[in] dictionary of options (verbosity, quiet, pedantic) test_db[in] Test replication using this database name (optional) default = None """ verbosity = options.get("verbosity", 0) conn_options = { 'src_name': "master", 'dest_name': 'slave', 'version': "5.0.0", 'unique': True, } servers = connect_servers(master_vals, slave_vals, conn_options) master = servers[0] slave = servers[1] rpl_options = options.copy() rpl_options['verbosity'] = verbosity > 0 # Create an instance of the replication object rpl = Replication(master, slave, rpl_options) errors = rpl.check_server_ids() for error in errors: print error # Check for server_id uniqueness if verbosity > 0: print "# master id = %s" % master.get_server_id() print "# slave id = %s" % slave.get_server_id() errors = rpl.check_server_uuids() for error in errors: print error # Check for server_uuid uniqueness if verbosity > 0: print "# master uuid = %s" % master.get_server_uuid() print "# slave uuid = %s" % slave.get_server_uuid() # Check InnoDB compatibility if verbosity > 0: print "# Checking InnoDB statistics for type and version conflicts." errors = rpl.check_innodb_compatibility(options) for error in errors: print error # Checking storage engines if verbosity > 0: print "# Checking storage engines..." errors = rpl.check_storage_engines(options) for error in errors: print error # Check master for binary logging print "# Checking for binary logging on master..." errors = rpl.check_master_binlog() if errors != []: raise UtilError(errors[0]) # Setup replication print "# Setting up replication..." if not rpl.setup(rpl_user, 10): raise UtilError("Cannot setup replication.") # Test the replication setup. if test_db: rpl.test(test_db, 10) print "# ...done."
def _setup_replication(self, master_vals, use_rpl_setup=True): """Setup replication among a master and a slave. master_vals[in] Master server connection dictionary. use_rpl_setup[in] Use Replication.setup() if True otherwise use switch_master() on the slave. This is used to control the first pass in the masters round-robin scheduling. """ conn_options = { "src_name": "master", "dest_name": "slave", "version": "5.0.0", "unique": True, } (master, slave,) = connect_servers(master_vals, self.slave_vals, conn_options) rpl_options = self.options.copy() rpl_options["verbosity"] = self.verbosity > 0 # Start from beginning only on the first pass if rpl_options.get("from_beginning", False) and not use_rpl_setup: rpl_options["from_beginning"] = False # Create an instance of the replication object rpl = Replication(master, slave, rpl_options) if use_rpl_setup: # Check server ids errors = rpl.check_server_ids() for error in errors: self._report(error, logging.ERROR, True) # Check for server_id uniqueness errors = rpl.check_server_uuids() for error in errors: self._report(error, logging.ERROR, True) # Check InnoDB compatibility errors = rpl.check_innodb_compatibility(self.options) for error in errors: self._report(error, logging.ERROR, True) # Checking storage engines errors = rpl.check_storage_engines(self.options) for error in errors: self._report(error, logging.ERROR, True) # Check master for binary logging errors = rpl.check_master_binlog() if not errors == []: raise UtilRplError(errors[0]) # Setup replication if not rpl.setup(self.rpl_user, 10): msg = "Cannot setup replication." self._report(msg, logging.CRITICAL, False) raise UtilRplError(msg) else: # Parse user and password (support login-paths) (r_user, r_pass,) = parse_user_password(self.rpl_user) # Switch master and start slave slave.switch_master(master, r_user, r_pass) slave.start({'fetch': False}) # Disconnect from servers master.disconnect() slave.disconnect()
def setup_replication(master_vals, slave_vals, rpl_user, options, test_db=None): """Setup replication among a master and a slave. master_vals[in] Master connection in form user:passwd@host:port:sock slave_vals[in] Slave connection in form user:passwd@host:port:sock rpl_user[in] Replication user in the form user:passwd options[in] dictionary of options (verbosity, quiet, pedantic) test_db[in] Test replication using this database name (optional) default = None """ from mysql.utilities.common.server import connect_servers from mysql.utilities.common.replication import Replication verbosity = options.get("verbosity", 0) conn_options = { 'src_name' : "master", 'dest_name' : 'slave', 'version' : "5.0.0", 'unique' : True, } servers = connect_servers(master_vals, slave_vals, conn_options) master = servers[0] slave = servers[1] rpl_options = options.copy() rpl_options['verbosity'] = verbosity > 0 # Create an instance of the replication object rpl = Replication(master, slave, rpl_options) errors = rpl.check_server_ids() for error in errors: print error # Check for server_id uniqueness if verbosity > 0: print "# master id = %s" % master.get_server_id() print "# slave id = %s" % slave.get_server_id() errors = rpl.check_server_uuids() for error in errors: print error # Check for server_uuid uniqueness if verbosity > 0: print "# master uuid = %s" % master.get_server_uuid() print "# slave uuid = %s" % slave.get_server_uuid() # Check InnoDB compatibility if verbosity > 0: print "# Checking InnoDB statistics for type and version conflicts." errors = rpl.check_innodb_compatibility(options) for error in errors: print error # Checking storage engines if verbosity > 0: print "# Checking storage engines..." errors = rpl.check_storage_engines(options) for error in errors: print error # Check master for binary logging print "# Checking for binary logging on master..." errors = rpl.check_master_binlog() if not errors == []: raise UtilError(errors[0]) # Setup replication print "# Setting up replication..." if not rpl.setup(rpl_user, 10): raise UtilError("Cannot setup replication.") # Test the replication setup. if test_db: rpl.test(test_db, 10) print "# ...done."
def _setup_replication(self, master_vals, use_rpl_setup=True): """Setup replication among a master and a slave. master_vals[in] Master server connection dictionary. use_rpl_setup[in] Use Replication.setup() if True otherwise use switch_master() on the slave. This is used to control the first pass in the masters round-robin scheduling. """ conn_options = { "src_name": "master", "dest_name": "slave", "version": "5.0.0", "unique": True, } (master, slave,) = connect_servers(master_vals, self.slave_vals, conn_options) rpl_options = self.options.copy() rpl_options["verbosity"] = self.verbosity > 0 # Start from beginning only on the first pass if rpl_options.get("from_beginning", False) and not use_rpl_setup: rpl_options["from_beginning"] = False # Create an instance of the replication object rpl = Replication(master, slave, rpl_options) if use_rpl_setup: # Check server ids errors = rpl.check_server_ids() for error in errors: self._report(error, logging.ERROR, True) # Check for server_id uniqueness errors = rpl.check_server_uuids() for error in errors: self._report(error, logging.ERROR, True) # Check InnoDB compatibility errors = rpl.check_innodb_compatibility(self.options) for error in errors: self._report(error, logging.ERROR, True) # Checking storage engines errors = rpl.check_storage_engines(self.options) for error in errors: self._report(error, logging.ERROR, True) # Check master for binary logging errors = rpl.check_master_binlog() if errors != []: raise UtilRplError(errors[0]) # Setup replication if not rpl.setup(self.rpl_user, 10): msg = "Cannot setup replication." self._report(msg, logging.CRITICAL, False) raise UtilRplError(msg) else: # Parse user and password (support login-paths) try: (r_user, r_pass,) = parse_user_password(self.rpl_user) except FormatError: raise UtilError(USER_PASSWORD_FORMAT.format("--rpl-user")) # Switch master and start slave slave.switch_master(master, r_user, r_pass) slave.start({'fetch': False}) # Disconnect from servers master.disconnect() slave.disconnect()