本文整理汇总了Python中mysql.fabric.server.MySQLServer.connect方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLServer.connect方法的具体用法?Python MySQLServer.connect怎么用?Python MySQLServer.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.fabric.server.MySQLServer
的用法示例。
在下文中一共展示了MySQLServer.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_max_connections
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
def test_max_connections(self):
uuid = MySQLServer.discover_uuid(OPTIONS["address"])
server = MySQLServer(
_uuid.UUID(uuid), OPTIONS["address"],
)
server.connect()
res = server.get_variable("max_connections")
self.assertNotEqual(int(res), 0)
示例2: TestMySQLMaster
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestMySQLMaster(unittest.TestCase):
"""Unit test for the configuration file handling.
"""
def setUp(self):
"""Configure the existing environment
"""
uuid = MySQLServer.discover_uuid(OPTIONS_MASTER["address"])
OPTIONS_MASTER["uuid"] = _uuid.UUID(uuid)
self.master = MySQLServer(**OPTIONS_MASTER)
self.master.connect()
reset_master(self.master)
self.master.read_only = True
self.master.read_only = False
def tearDown(self):
"""Clean up the existing environment
"""
cleanup_environment()
self.master.disconnect()
def test_master_binary_log(self):
"""Test the get_master_status() function.
"""
# Note this is only being tested with the binary log.
master = self.master
# Get master status.
check = re.compile('\w+-bin.000001')
ret = get_master_status(master)
self.assertNotEqual(check.match(ret[0][0]), None)
# Reset Master.
reset_master(master)
ret = get_master_status(master)
self.assertEqual(int(ret[0][1]), 151) # Format descriptor event.
def test_master_health(self):
"""Test the check_master_issues() function.
"""
# Note this is only being tested with the binary log.
master = self.master
# Check health as a master before calling connect.
master.disconnect()
ret = check_master_issues(master)
self.assertEqual(ret, {'is_running': False})
# Check health as a master after calling connect.
master.connect()
ret = check_master_issues(master)
self.assertEqual(ret, {})
示例3: configure_servers
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
def configure_servers(options):
"""Check if some MySQL's addresses were specified and the number is
greater than NUMBER_OF_SERVERS.
"""
import tests.utils as _test_utils
from mysql.fabric.server import (
MySQLServer,
ConnectionPool,
)
try:
servers = _test_utils.MySQLInstances()
servers.state_store_address = "{host}:{port}".format(
host=options.host, port=options.port
)
servers.user = options.db_user
servers.passwd = None
servers.root_user = options.user
servers.root_passwd = options.password
if options.servers:
for address in options.servers.split():
servers.add_address(address)
uuid = MySQLServer.discover_uuid(
address=address, user=servers.root_user,
passwd=servers.root_passwd
)
server = MySQLServer(
_uuid.UUID(uuid), address=address, user=servers.root_user,
passwd=servers.root_passwd
)
server.connect()
server.set_session_binlog(False)
server.exec_stmt(
"GRANT {privileges} ON *.* TO '{user}'@'%%'".format(
privileges=", ".join(MySQLServer.ALL_PRIVILEGES),
user=servers.user)
)
server.exec_stmt("FLUSH PRIVILEGES")
server.set_session_binlog(True)
server.disconnect()
ConnectionPool().purge_connections(server.uuid)
if servers.get_number_addresses() < NUMBER_OF_SERVERS:
print "<<<<<<<<<< Some unit tests need %s MySQL Instances. " \
">>>>>>>>>> " % (NUMBER_OF_SERVERS, )
return False
except Exception as error:
print "Error configuring servers:", error
return False
return True
示例4: test_connection_pool
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
def test_connection_pool(self):
"""Test connection pool.
"""
# Configuration
uuid = MySQLServer.discover_uuid(OPTIONS["address"])
OPTIONS["uuid"] = uuid = _uuid.UUID(uuid)
server_1 = MySQLServer(**OPTIONS)
server_2 = MySQLServer(**OPTIONS)
cnx_pool = ConnectionPool()
# Purge connections and check the number of connections in
# the pool.
cnx_pool.purge_connections(uuid)
self.assertEqual(cnx_pool.get_number_connections(uuid), 0)
# Connect and check the number of connections in the pool.
server_1.connect()
server_2.connect()
self.assertEqual(cnx_pool.get_number_connections(uuid), 0)
# Delete one of the servers and check the number of
# connections in the pool.
del server_1
self.assertEqual(cnx_pool.get_number_connections(uuid), 1)
# Delete one of the servers and check the number of
# connections in the pool.
del server_2
self.assertEqual(cnx_pool.get_number_connections(uuid), 2)
# Purge connections and check the number of connections in
# the pool. However, call purge_connections twice.
cnx_pool.purge_connections(uuid)
self.assertEqual(cnx_pool.get_number_connections(uuid), 0)
cnx_pool.purge_connections(uuid)
self.assertEqual(cnx_pool.get_number_connections(uuid), 0)
示例5: TestHashMoveGlobal
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestHashMoveGlobal(unittest.TestCase):
"""Contains unit tests for testing the shard move operation and for
verifying that the global server configuration remains constant after
the shard move configuration.
"""
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Configure the existing environment
"""
tests.utils.cleanup_environment()
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__server_1.connect()
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID INT PRIMARY KEY, name VARCHAR(30))")
for i in range(1, 1001):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_2.exec_stmt("CREATE DATABASE db2")
self.__server_2.exec_stmt("CREATE TABLE db2.t2"
"(userID INT, salary INT, "
"CONSTRAINT FOREIGN KEY(userID) "
"REFERENCES db1.t1(userID))")
for i in range(1, 1001):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_3.exec_stmt("CREATE DATABASE db1")
self.__server_3.exec_stmt("CREATE TABLE db1.t1"
"(userID INT PRIMARY KEY, name VARCHAR(30))")
for i in range(1, 1001):
self.__server_3.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_3.exec_stmt("CREATE DATABASE db2")
self.__server_3.exec_stmt("CREATE TABLE db2.t2"
"(userID INT, salary INT, "
"CONSTRAINT FOREIGN KEY(userID) "
"REFERENCES db1.t1(userID))")
for i in range(1, 1001):
self.__server_3.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
self.__group_3 = Group("GROUPID3", "Third description.")
Group.add( self.__group_3)
self.__group_3.add_server(self.__server_3)
#.........这里部分代码省略.........
示例6: TestShardingPrune
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestShardingPrune(unittest.TestCase):
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Creates the following topology for testing,
GROUPID1 - localhost:13001, localhost:13002 - Global Group
GROUPID2 - localhost:13003, localhost:13004 - shard 1
GROUPID3 - localhost:13005, localhost:13006 - shard 2
"""
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 601):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_3.exec_stmt("CREATE DATABASE db1")
self.__server_3.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 601):
self.__server_3.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_3 = Group("GROUPID3", "Third description.")
Group.add( self.__group_3)
self.__group_3.add_server(self.__server_3)
tests.utils.configure_decoupled_master(self.__group_3, self.__server_3)
self.__options_4 = {
"uuid" : _uuid.UUID("{bb45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(3),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd
}
uuid_server4 = MySQLServer.discover_uuid(self.__options_4["address"])
self.__options_4["uuid"] = _uuid.UUID(uuid_server4)
self.__server_4 = MySQLServer(**self.__options_4)
MySQLServer.add(self.__server_4)
self.__server_4.connect()
self.__server_4.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_4.exec_stmt("CREATE DATABASE db1")
self.__server_4.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 601):
#.........这里部分代码省略.........
示例7: TestShardingServices
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestShardingServices(unittest.TestCase):
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Configure the existing environment
"""
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__group_3 = Group("GROUPID3", "Third description.")
Group.add( self.__group_3)
self.__group_3.add_server(self.__server_3)
tests.utils.configure_decoupled_master(self.__group_3, self.__server_3)
self.__options_4 = {
"uuid" : _uuid.UUID("{bb45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(3),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server4 = MySQLServer.discover_uuid(self.__options_4["address"])
self.__options_4["uuid"] = _uuid.UUID(uuid_server4)
self.__server_4 = MySQLServer(**self.__options_4)
MySQLServer.add(self.__server_4)
self.__group_4 = Group("GROUPID4", "Fourth description.")
Group.add( self.__group_4)
self.__group_4.add_server(self.__server_4)
tests.utils.configure_decoupled_master(self.__group_4, self.__server_4)
self.__server_4.connect()
self.__server_4.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_4.exec_stmt("CREATE DATABASE db2")
self.__server_4.exec_stmt("CREATE TABLE db2.t2"
"(userID2 INT, name VARCHAR(30))")
for i in range(1, 201):
self.__server_4.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__options_5 = {
"uuid" : _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(4),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"])
self.__options_5["uuid"] = _uuid.UUID(uuid_server5)
self.__server_5 = MySQLServer(**self.__options_5)
MySQLServer.add(self.__server_5)
#.........这里部分代码省略.........
示例8: TestHashSplitGlobal
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestHashSplitGlobal(unittest.TestCase):
"""Contains unit tests for testing the shard split operation and for
verifying that the global server configuration remains constant after
the shard split configuration.
"""
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Configure the existing environment
"""
tests.utils.cleanup_environment()
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__server_1.connect()
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID INT PRIMARY KEY, name VARCHAR(30))")
for i in range(1, 1001):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_2.exec_stmt("CREATE DATABASE db2")
self.__server_2.exec_stmt("CREATE TABLE db2.t2"
"(userID INT, salary INT, "
"CONSTRAINT FOREIGN KEY(userID) "
"REFERENCES db1.t1(userID))")
for i in range(1, 1001):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db3")
self.__server_2.exec_stmt("CREATE DATABASE db3")
self.__server_2.exec_stmt("CREATE TABLE db3.t3"
"(userID INT, Department INT, "
"CONSTRAINT FOREIGN KEY(userID) "
"REFERENCES db1.t1(userID))")
for i in range(1, 1001):
self.__server_2.exec_stmt("INSERT INTO db3.t3 "
"VALUES(%s, %s)" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_3.exec_stmt("CREATE DATABASE db1")
self.__server_3.exec_stmt("CREATE TABLE db1.t1"
"(userID INT PRIMARY KEY, name VARCHAR(30))")
for i in range(1, 1001):
self.__server_3.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_3.exec_stmt("CREATE DATABASE db2")
self.__server_3.exec_stmt("CREATE TABLE db2.t2"
"(userID INT, salary INT, "
"CONSTRAINT FOREIGN KEY(userID) "
#.........这里部分代码省略.........
示例9: TestHashSharding
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestHashSharding(unittest.TestCase):
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 501):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_3.exec_stmt("CREATE DATABASE db1")
self.__server_3.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 501):
self.__server_3.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_3 = Group("GROUPID3", "Third description.")
Group.add( self.__group_3)
self.__group_3.add_server(self.__server_3)
tests.utils.configure_decoupled_master(self.__group_3, self.__server_3)
self.__options_4 = {
"uuid" : _uuid.UUID("{bb45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(3),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server4 = MySQLServer.discover_uuid(self.__options_4["address"])
self.__options_4["uuid"] = _uuid.UUID(uuid_server4)
self.__server_4 = MySQLServer(**self.__options_4)
MySQLServer.add(self.__server_4)
self.__server_4.connect()
self.__server_4.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_4.exec_stmt("CREATE DATABASE db1")
self.__server_4.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
for i in range(1, 501):
self.__server_4.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_4 = Group("GROUPID4", "Fourth description.")
Group.add( self.__group_4)
self.__group_4.add_server(self.__server_4)
tests.utils.configure_decoupled_master(self.__group_4, self.__server_4)
#.........这里部分代码省略.........
示例10: TestSharding
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestSharding(unittest.TestCase):
def setUp(self):
"""Configure the existing environment
"""
self.__options_1 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : "server_1.mysql.com:3060",
}
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"),
"address" : "server_2.mysql.com:3060",
}
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
self.__group_1.add_server(self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add(self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS prune_db")
self.__server_3.exec_stmt("CREATE DATABASE prune_db")
self.__server_3.exec_stmt("CREATE TABLE prune_db.prune_table"
"(userID INT, name VARCHAR(30))")
self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table "
"VALUES(101, 'TEST 1')")
self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table "
"VALUES(202, 'TEST 2')")
self.__options_4 = {
"uuid" : _uuid.UUID("{dd75a12a-98d1-414c-96af-9e9d4b179678}"),
"address" : "server_4.mysql.com:3060",
}
self.__server_4 = MySQLServer(**self.__options_4)
MySQLServer.add(self.__server_4)
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_3)
self.__group_2.add_server(self.__server_4)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_3)
self.__options_5 = {
"uuid" : _uuid.UUID("{ee75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"])
self.__options_5["uuid"] = _uuid.UUID(uuid_server5)
self.__server_5 = MySQLServer(**self.__options_5)
MySQLServer.add(self.__server_5)
self.__server_5.connect()
self.__server_5.exec_stmt("DROP DATABASE IF EXISTS prune_db")
self.__server_5.exec_stmt("CREATE DATABASE prune_db")
self.__server_5.exec_stmt("CREATE TABLE prune_db.prune_table"
"(userID INT, name VARCHAR(30))")
self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table "
"VALUES(101, 'TEST 1')")
self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table "
"VALUES(202, 'TEST 2')")
self.__options_6 = {
"uuid" : _uuid.UUID("{ff75a12a-98d1-414c-96af-9e9d4b179678}"),
"address" : "server_6.mysql.com:3060",
}
self.__server_6 = MySQLServer(**self.__options_6)
MySQLServer.add(self.__server_6)
self.__group_3 = Group("GROUPID3", "Third description.")
Group.add(self.__group_3)
self.__group_3.add_server(self.__server_5)
self.__group_3.add_server(self.__server_6)
tests.utils.configure_decoupled_master(self.__group_3, self.__server_5)
group_4 = Group("GROUPID4", "4TH description.")
Group.add(group_4)
group_5 = Group("GROUPID5", "5TH description.")
Group.add(group_5)
group_6 = Group("GROUPID6", "6TH description.")
Group.add(group_6)
group_7 = Group("GROUPID7", "7TH description.")
Group.add(group_7)
group_8 = Group("GROUPID8", "8TH description.")
Group.add(group_8)
group_9 = Group("GROUPID9", "9TH description.")
Group.add(group_9)
group_10 = Group("GROUPID10", "10TH description.")
Group.add(group_10)
#.........这里部分代码省略.........
示例11: test_privileges
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
def test_privileges(self):
"""Test whether user's have the appropriate privileges.
"""
# Some privileges
MINIMUM_PRIVILEGES = [
"REPLICATION SLAVE", "REPLICATION CLIENT", "SUPER",
"SHOW DATABASES", "RELOAD"
]
# Connect to server as root and create temporary user.
uuid = MySQLServer.discover_uuid(OPTIONS["address"])
server = MySQLServer(
_uuid.UUID(uuid), OPTIONS["address"],
tests.utils.MySQLInstances().root_user,
tests.utils.MySQLInstances().root_passwd
)
ConnectionPool().purge_connections(_uuid.UUID(uuid))
server.connect()
server.set_session_binlog(False)
server.exec_stmt(
"CREATE USER 'jeffrey'@'%%' IDENTIFIED BY 'mypass'"
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# There is not privilege associate to jeffrey.
new_server = MySQLServer(
_uuid.UUID(uuid), OPTIONS["address"], "jeffrey", "mypass"
)
new_server.connect()
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# Grant required privileges except RELOAD
# There is no RELOAD on a global level.
privileges=", ".join([priv for priv in MINIMUM_PRIVILEGES
if priv != "RELOAD"]
)
server.exec_stmt(
"GRANT {privileges} ON *.* TO 'jeffrey'@'%%'".format(
privileges=privileges)
)
server.exec_stmt("FLUSH PRIVILEGES")
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# The RELOAD on a global level was granted.
server.exec_stmt("GRANT RELOAD ON *.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertTrue(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# Revoke privilegs from temporary user.
# There is no ALL on a global level.
server.exec_stmt("REVOKE ALL PRIVILEGES, GRANT OPTION FROM "
"'jeffrey'@'%%'"
)
server.exec_stmt("GRANT ALL ON fabric.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# The ALL on a global level was granted.
server.exec_stmt("GRANT ALL ON *.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertTrue(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Drop temporary user.
server.exec_stmt("DROP USER 'jeffrey'@'%%'")
server.set_session_binlog(True)
server.disconnect()
new_server.disconnect()
ConnectionPool().purge_connections(_uuid.UUID(uuid))
示例12: TestShardingPrune
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestShardingPrune(unittest.TestCase):
"""Contains unit tests for testing the shard split operation and for
verifying that the global server configuration remains constant after
the shard split configuration.
"""
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Creates the topology for testing.
"""
tests.utils.cleanup_environment()
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd": MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__server_1.connect()
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd": MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID INT PRIMARY KEY, name VARCHAR(30))")
for i in range(1, 71):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
for i in range(101, 301):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
for i in range(1001, 1201):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
for i in range(10001, 10201):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
for i in range(100001, 100201):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_2.exec_stmt("CREATE DATABASE db2")
self.__server_2.exec_stmt("CREATE TABLE db2.t2"
"(userID INT, salary INT, "
"CONSTRAINT FOREIGN KEY(userID) "
"REFERENCES db1.t1(userID))")
for i in range(1, 71):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
for i in range(101, 301):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
for i in range(1001, 1201):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
for i in range(10001, 10201):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
for i in range(100001, 100201):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, %s)" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd": MySQLInstances().passwd,
}
#.........这里部分代码省略.........
示例13: TestServerClone
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestServerClone(unittest.TestCase):
"""Tests the mysqlfabric clone command to clone all the data in a server
registered in Fabric into another server. Create a Group and add some
servers. Insert data into one of the servers. Now clone this server into
the other servers in the group. Now start replication and ensure everything
works fine.
"""
def assertStatus(self, status, expect):
"""Asserts that the status obtained is similar to the status
expected.
"""
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Create the setup for performing the testing of the server clone
command.
"""
from __main__ import mysqldump_path, mysqlclient_path
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address": MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__server_1.connect()
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address":MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__options_3 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address":MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add(self.__server_3)
self.__server_3.connect()
#Insert data into Server 1
self.__server_1.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_1.exec_stmt("CREATE DATABASE db1")
self.__server_1.exec_stmt("CREATE TABLE db1.t1"
"(userID INT, name VARCHAR(30))")
self.__server_1.exec_stmt("INSERT INTO db1.t1 "
"VALUES(101, 'TEST 1')")
self.__server_1.exec_stmt("INSERT INTO db1.t1 "
"VALUES(202, 'TEST 2')")
self.__server_1.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_1.exec_stmt("CREATE DATABASE db2")
self.__server_1.exec_stmt("CREATE TABLE db2.t1"
"(userID INT, name VARCHAR(30))")
self.__server_1.exec_stmt("INSERT INTO db2.t1 "
"VALUES(101, 'TEST 1')")
self.__server_1.exec_stmt("INSERT INTO db2.t1 "
"VALUES(202, 'TEST 2')")
def test_clone_from_group(self):
"""Verify the clone operation from a group.
"""
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
self.__group_1.add_server(self.__server_2)
self.__group_1.master = self.__server_2.uuid
try:
status = self.proxy.server.clone("GROUPID1", self.__server_2.address,
str(self.__server_1.uuid))
raise Exception("Cloning to a server inside Fabric should "
"throw a fault")
except:
pass
try:
status = self.proxy.server.clone("GROUPID1", self.__server_2.address,
uuid_server3)
raise Exception("Cloning from a server outside the "
#.........这里部分代码省略.........
示例14: TestShardingServices
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestShardingServices(unittest.TestCase):
def assertStatus(self, status, expect):
items = (item['diagnosis'] for item in status[1] if item['diagnosis'])
self.assertEqual(status[1][-1]["success"], expect, "\n".join(items))
def setUp(self):
"""Configure the existing environment
"""
tests.utils.cleanup_environment()
self.manager, self.proxy = tests.utils.setup_xmlrpc()
self.__options_1 = {
"uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(0),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"])
self.__options_1["uuid"] = _uuid.UUID(uuid_server1)
self.__server_1 = MySQLServer(**self.__options_1)
MySQLServer.add(self.__server_1)
self.__group_1 = Group("GROUPID1", "First description.")
Group.add(self.__group_1)
self.__group_1.add_server(self.__server_1)
tests.utils.configure_decoupled_master(self.__group_1, self.__server_1)
self.__options_2 = {
"uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(1),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"])
self.__options_2["uuid"] = _uuid.UUID(uuid_server2)
self.__server_2 = MySQLServer(**self.__options_2)
MySQLServer.add(self.__server_2)
self.__server_2.connect()
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_2.exec_stmt("CREATE DATABASE db1")
self.__server_2.exec_stmt("CREATE TABLE db1.t1"
"(userID1 INT, name VARCHAR(30))")
for i in range(1, 201):
self.__server_2.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_2.exec_stmt("CREATE DATABASE db2")
self.__server_2.exec_stmt("CREATE TABLE db2.t2"
"(userID2 INT, name VARCHAR(30))")
for i in range(201, 401):
self.__server_2.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db3")
self.__server_2.exec_stmt("CREATE DATABASE db3")
self.__server_2.exec_stmt("CREATE TABLE db3.t3"
"(userID3 INT, name VARCHAR(30))")
for i in range(401, 601):
self.__server_2.exec_stmt("INSERT INTO db3.t3 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__group_2 = Group("GROUPID2", "Second description.")
Group.add(self.__group_2)
self.__group_2.add_server(self.__server_2)
tests.utils.configure_decoupled_master(self.__group_2, self.__server_2)
self.__options_3 = {
"uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
"address" : MySQLInstances().get_address(2),
"user" : MySQLInstances().user,
"passwd" : MySQLInstances().passwd,
}
uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"])
self.__options_3["uuid"] = _uuid.UUID(uuid_server3)
self.__server_3 = MySQLServer(**self.__options_3)
MySQLServer.add( self.__server_3)
self.__server_3.connect()
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1")
self.__server_3.exec_stmt("CREATE DATABASE db1")
self.__server_3.exec_stmt("CREATE TABLE db1.t1"
"(userID1 INT, name VARCHAR(30))")
for i in range(1, 201):
self.__server_3.exec_stmt("INSERT INTO db1.t1 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db2")
self.__server_3.exec_stmt("CREATE DATABASE db2")
self.__server_3.exec_stmt("CREATE TABLE db2.t2"
"(userID2 INT, name VARCHAR(30))")
for i in range(201, 401):
self.__server_3.exec_stmt("INSERT INTO db2.t2 "
"VALUES(%s, 'TEST %s')" % (i, i))
self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db3")
self.__server_3.exec_stmt("CREATE DATABASE db3")
self.__server_3.exec_stmt("CREATE TABLE db3.t3"
"(userID3 INT, name VARCHAR(30))")
for i in range(401, 601):
self.__server_3.exec_stmt("INSERT INTO db3.t3 "
#.........这里部分代码省略.........
示例15: TestMySQLSlave
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import connect [as 别名]
class TestMySQLSlave(unittest.TestCase):
"""Unit test for the configuration file handling.
"""
def setUp(self):
"""Configure the existing environment
"""
uuid = MySQLServer.discover_uuid(OPTIONS_MASTER["address"])
OPTIONS_MASTER["uuid"] = _uuid.UUID(uuid)
self.master = MySQLServer(**OPTIONS_MASTER)
self.master.connect()
reset_master(self.master)
uuid = MySQLServer.discover_uuid(OPTIONS_SLAVE["address"])
OPTIONS_SLAVE["uuid"] = _uuid.UUID(uuid)
self.slave = MySQLServer(**OPTIONS_SLAVE)
self.slave.connect()
stop_slave(self.slave, wait=True)
reset_master(self.slave)
reset_slave(self.slave, clean=True)
def tearDown(self):
"""Clean up the existing environment
"""
cleanup_environment()
stop_slave(self.slave, wait=True)
self.slave.disconnect()
self.master.disconnect()
def test_switch_master_(self):
"""Test the switch_master() function.
"""
# Note this is only being tested with gtids.
# Set up replication.
master = self.master
slave = self.slave
# Check that is slave is not connected to any master.
self.assertFalse(is_slave_thread_running(slave, (IO_THREAD, )))
self.assertNotEqual(slave_has_master(slave), str(master.uuid))
# Switch to a master.
switch_master(slave, master, MySQLInstances().user,
MySQLInstances().passwd)
start_slave(slave, wait=True)
self.assertTrue(is_slave_thread_running(slave, (IO_THREAD, )))
# The IO_THREAD status and the UUID are not atomically updated
# for that reason master_uuid can be None.
master_uuid = slave_has_master(slave)
self.assertTrue(
master_uuid == None or master_uuid == str(master.uuid)
)
# It is not possible to switch when replication is running.
self.assertRaises(_errors.DatabaseError, switch_master, slave,
master, MySQLInstances().user, MySQLInstances().passwd
)
# Reset and try to reconnect master and slave.
stop_slave(slave, wait=True)
reset_slave(slave, clean=True)
switch_master(slave, master, MySQLInstances().user,
MySQLInstances().passwd
)
start_slave(slave, wait=True)
self.assertTrue(is_slave_thread_running(slave, (IO_THREAD, )))
self.assertEqual(slave_has_master(slave), str(master.uuid))
# Change master's password, reset and try to reconnect master
# and slave.
stop_slave(slave, wait=True)
master.set_session_binlog(False)
master.exec_stmt(
"SET PASSWORD FOR '{user}'@'%%' = PASSWORD('foobar')".format(
user=MySQLInstances().user)
)
master.exec_stmt("FLUSH PRIVILEGES")
master.set_session_binlog(True)
switch_master(slave, master, MySQLInstances().user, "foobar")
start_slave(slave, wait=True)
self.assertTrue(is_slave_thread_running(slave, (IO_THREAD, )))
self.assertEqual(slave_has_master(slave), str(master.uuid))
# Reset master's password, reset and try to reconnect master
# and slave.
stop_slave(slave, wait=True)
master.set_session_binlog(False)
master.exec_stmt(
"SET PASSWORD FOR '{user}'@'%%' = "
"PASSWORD('{passwd}')".format(user=MySQLInstances().user,
passwd=MySQLInstances().passwd or "")
)
master.exec_stmt("FLUSH PRIVILEGES")
master.set_session_binlog(True)
switch_master(slave, master, MySQLInstances().user,
MySQLInstances().passwd
)
start_slave(slave, wait=True)
self.assertTrue(is_slave_thread_running(slave, (IO_THREAD, )))
#.........这里部分代码省略.........