Skip to content

Commit

Permalink
Centralize MySQL Flavor handling in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
enisoc committed Jul 28, 2014
1 parent 59b771c commit f358837
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
51 changes: 51 additions & 0 deletions test/mysql_flavor.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 2 additions & 6 deletions test/reparent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down
10 changes: 2 additions & 8 deletions test/tablet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import environment
import utils
from mysql_flavor import mysql_flavor

tablet_cell_map = {
62344: 'nj',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f358837

Please sign in to comment.