diff --git a/test/mysql_flavor.py b/test/mysql_flavor.py new file mode 100644 index 00000000000..962b05b8d9b --- /dev/null +++ b/test/mysql_flavor.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import environment + + +class MysqlFlavor(object): + """Base class with default SQL statements""" + + def promote_slave_commands(self): + """Returns commands to convert a slave to a master.""" + return [ + "RESET MASTER", + "STOP SLAVE", + "RESET SLAVE", + "CHANGE MASTER TO MASTER_HOST = ''", + ] + + def reset_replication_commands(self): + return [ + "RESET MASTER", + "STOP SLAVE", + "RESET SLAVE", + 'CHANGE MASTER TO MASTER_HOST = ""', + ] + + +class GoogleMysql(MysqlFlavor): + """Overrides specific to Google MySQL""" + + +class MariaDB(MysqlFlavor): + """Overrides specific to MariaDB""" + + def promote_slave_commands(self): + return [ + "RESET MASTER", + "STOP SLAVE", + "RESET SLAVE", + ] + + def reset_replication_commands(self): + return [ + "RESET MASTER", + "STOP SLAVE", + "RESET SLAVE", + ] + +if environment.mysql_flavor == "MariaDB": + mysql_flavor = MariaDB() +else: + mysql_flavor = GoogleMysql() diff --git a/test/reparent.py b/test/reparent.py index 2c1de8804cb..dce20d5ded5 100755 --- a/test/reparent.py +++ b/test/reparent.py @@ -16,6 +16,7 @@ import environment import utils import tablet +from mysql_flavor import mysql_flavor tablet_62344 = tablet.Tablet(62344) tablet_62044 = tablet.Tablet(62044) @@ -409,12 +410,7 @@ def _test_reparent_from_outside(self, brutal=False): # now manually reparent 1 out of 2 tablets # 62044 will be the new master # 31981 won't be re-parented, so it will be busted - tablet_62044.mquery('', [ - "RESET MASTER", - "STOP SLAVE", - "RESET SLAVE", - "CHANGE MASTER TO MASTER_HOST = ''", - ]) + tablet_62044.mquery('', mysql_flavor.promote_slave_commands()) new_pos = tablet_62044.mquery('', 'show master status') logging.debug("New master position: %s" % str(new_pos)) diff --git a/test/tablet.py b/test/tablet.py index 5b63bc182e8..abe65ac1c2f 100644 --- a/test/tablet.py +++ b/test/tablet.py @@ -13,6 +13,7 @@ import environment import utils +from mysql_flavor import mysql_flavor tablet_cell_map = { 62344: 'nj', @@ -148,14 +149,7 @@ def assert_table_count(self, dbname, table, n, where=''): raise utils.TestError("expected %u rows in %s" % (n, table), result) def reset_replication(self): - commands = [ - 'RESET MASTER', - 'STOP SLAVE', - 'RESET SLAVE', - ] - if environment.mysql_flavor == "GoogleMysql": - commands.append('CHANGE MASTER TO MASTER_HOST = ""') - self.mquery('', commands) + self.mquery('', mysql_flavor.reset_replication_commands()) def populate(self, dbname, create_sql, insert_sqls=[]): self.create_db(dbname)