def testSlaveWaitAndStop(self): "Test the slave_wait_and_stop function" slave = self.slaves[0] master = self.master slave.sql("STOP SLAVE") pos1 = fetch_master_position(master) change_master(slave, master, pos1) slave.sql("START SLAVE") master.sql("DROP TABLE IF EXISTS t1", db="test") master.sql("CREATE TABLE t1 (a INT)", db="test") master.sql("INSERT INTO t1 VALUES (1),(2)", db="test") pos2 = fetch_master_position(master) master.sql("INSERT INTO t1 VALUES (3),(4)", db="test") pos3 = fetch_master_position(master) slave_wait_and_stop(slave, pos2) pos4 = fetch_slave_position(slave) self.assertEqual(pos2, pos4) row = slave.sql("SELECT COUNT(*) AS count FROM t1", db="test") self.assertEqual(row['count'], 2) slave.sql("START SLAVE") slave_wait_and_stop(slave, pos3) row = slave.sql("SELECT COUNT(*) AS count FROM t1", db="test") self.assertEqual(row['count'], 4)
def testSlaveWaitForPos(self): "Test the slave_wait_for_pos function" slave = self.slaves[0] master = self.master slave.sql("STOP SLAVE") pos1 = fetch_master_position(master) change_master(slave, master, pos1) slave.sql("START SLAVE") master.sql("DROP TABLE IF EXISTS t1", db="test") master.sql("CREATE TABLE t1 (a INT)", db="test") master.sql("INSERT INTO t1 VALUES (1),(2)", db="test") pos2 = fetch_master_position(master) slave_wait_for_pos(slave, pos2) pos3 = fetch_slave_position(slave) self.assert_(pos3 >= pos2)
def testSlaveStatusWaitUntil(self): "Test slave_status_wait_until" slave = self.slaves[0] master = self.master slave.sql("STOP SLAVE") pos1 = fetch_master_position(master) change_master(slave, master, pos1) slave.sql("START SLAVE")
def testGetMasterPosition(self): "Fetching master position from the master and checking format" try: position = fetch_master_position(self.master) self.assertTrue(position is None or _POS_CRE.match(str(position)), "Position '%s' is not correct" % (str(position))) except NotMasterError: self.fail("Unable to test fetch_master_position since" " master is not configured as a master")
def testGetMasterPosition(self): "Fetching master position from the master and checking format" try: position = fetch_master_position(self.master) self.assertTrue(position is None or _POS_CRE.match(str(position)), "Position '%s' is not correct" % (str(position))) except NotMasterError: self.fail( "Unable to test fetch_master_position since" " master is not configured as a master" )
def backup_server(self, server, database="*"): from mysql.replicant.commands import ( fetch_master_position, ) datadir = server.fetch_config().get('datadir') if database == "*": database = [ d for d in os.listdir(datadir) if os.path.isdir(os.path.join(datadir, d)) ] server.sql("FLUSH TABLES WITH READ LOCK") position = fetch_master_position(server) if server.host != "localhost": path = os.path.basename(self.url.path) else: path = self.url.path server.ssh(["tar", "zpscf", path, "-C", datadir] + database) if server.host != "localhost": subprocess.check_call( ["scp", server.host + ":" + path, self.url.path]) server.sql("UNLOCK TABLES") return position
def backup_server(self, server, database="*"): from mysql.replicant.commands import ( fetch_master_position, ) datadir = server.fetch_config().get('datadir') if database == "*": database = [d for d in os.listdir(datadir) if os.path.isdir(os.path.join(datadir, d))] server.sql("FLUSH TABLES WITH READ LOCK") position = fetch_master_position(server) if server.host != "localhost": path = os.path.basename(self.url.path) else: path = self.url.path server.ssh(["tar", "zpscf", path, "-C", datadir] + database) if server.host != "localhost": subprocess.check_call([ "scp", server.host + ":" + path, self.url.path ]) server.sql("UNLOCK TABLES") return position