本文整理汇总了Python中mysql.fabric.server.MySQLServer.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLServer.disconnect方法的具体用法?Python MySQLServer.disconnect怎么用?Python MySQLServer.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.fabric.server.MySQLServer
的用法示例。
在下文中一共展示了MySQLServer.disconnect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wrong_uuid
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [as 别名]
def test_wrong_uuid(self):
"""Test what happens when a server has a wrong uuid.
"""
# Check wrong uuid.
OPTIONS["uuid"] = _uuid.UUID("FD0AC9BB-1431-11E2-8137-11DEF124DCC5")
server = MySQLServer(**OPTIONS)
self.assertRaises(_errors.UuidError, server.connect)
server.disconnect()
ConnectionPool().purge_connections(OPTIONS["uuid"])
示例2: TestMySQLMaster
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [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 disconnect [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: TestErrorLog
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [as 别名]
class TestErrorLog(unittest.TestCase):
"""Unit test for testing ErrorLog.
"""
def setUp(self):
"""Configure the existing environment
"""
uuid = MySQLServer.discover_uuid(
tests.utils.MySQLInstances().get_address(0)
)
self.server = MySQLServer(_uuid.UUID(uuid),
tests.utils.MySQLInstances().get_address(0)
)
MySQLServer.add(self.server)
def tearDown(self):
"""Clean up the existing environment
"""
tests.utils.cleanup_environment()
self.server.disconnect()
MySQLServer.remove(self.server)
def test_init(self):
"""Test basic properties/methods in the ErrorLog.
"""
# Check that the input parameters are not changed.
interval = get_time_delta(1)
now = get_time()
input_whens = [ 30, 40 ]
input_reporters = [ "reporter", "reporter" ]
st = ErrorLog(self.server, interval, now, input_whens,
input_reporters)
self.assertEqual(st.server_uuid, self.server.uuid)
self.assertEqual(st.interval, interval)
self.assertEqual(st.now, now)
self.assertEqual(st.whens, input_whens)
self.assertEqual(st.reporters, input_reporters)
# If whens and reporters don't have the same length, an exception is
# raised
interval = get_time_delta(1)
now = get_time()
input_whens = [ 0, 0, 0, 0 ]
input_reporters = []
self.assertRaises(AssertionError, ErrorLog,
self.server, interval, now, input_whens,
input_reporters)
def test_persistence(self):
"""Test ErrorLog.
"""
# Update/Notify and fetch, they should match.
interval = get_time_delta(1)
now = get_time()
input_whens = [ now, now ]
input_reporters = [ "client:1000", "client:2000" ]
st = ErrorLog(self.server, interval, now, input_whens,
input_reporters)
ErrorLog.add(self.server, now, "client:1000", "error")
ErrorLog.add(self.server, now, "client:2000", "error")
new_st = ErrorLog.fetch(self.server, interval, now)
self.assertEqual(st.reporters, new_st.reporters)
self.assertEqual(st.whens, new_st.whens)
# Call remove, they should be empty and match.
interval = get_time_delta(1)
now = get_time()
input_whens = [ ]
input_reporters = [ ]
ErrorLog.remove(self.server)
st = ErrorLog(self.server, interval, now, input_whens,
input_reporters)
new_st = ErrorLog.fetch(self.server, interval, now)
self.assertEqual(st.reporters, new_st.reporters)
self.assertEqual(st.whens, new_st.whens)
# Update/Notify and refresh, they should match.
interval = get_time_delta(10)
now = get_time()
input_whens = [ now, now - get_time_delta(5) ]
input_reporters = [ "client:1000", "client:2000" ]
st = ErrorLog(self.server, interval, now, [], [])
ErrorLog.add(self.server, now, "client:1000", "error")
ErrorLog.add(self.server, now - get_time_delta(5),
"client:2000", "error")
ErrorLog.add(self.server, now - get_time_delta(11),
"client:3000", "error")
st.refresh()
self.assertEqual(set(st.reporters), set(input_reporters))
self.assertEqual(set(st.whens), set(input_whens))
# Check whether a statement similar to the one used in the
# event is fine.
ErrorLog.remove(self.server)
ErrorLog.add(self.server, now, "client:1000", "error")
ErrorLog.add(self.server, now, "client:2000", "error")
persister = _persistence.current_persister()
out = persister.exec_stmt(
"SELECT reported, UTC_TIMESTAMP() as now, "
"TIMEDIFF(UTC_TIMESTAMP(), reported - MAKETIME(2,0,0)) as diff "
"FROM error_log"
#.........这里部分代码省略.........
示例5: TestMySQLServer
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [as 别名]
class TestMySQLServer(unittest.TestCase):
"""Unit test for testing MySQLServer.
"""
def setUp(self):
"""Configure the existing environment
"""
uuid = MySQLServer.discover_uuid(OPTIONS["address"])
OPTIONS["uuid"] = _uuid.UUID(uuid)
self.server = MySQLServer(**OPTIONS)
MySQLServer.add(self.server)
def tearDown(self):
"""Clean up the existing environment
"""
tests.utils.cleanup_environment()
self.server.disconnect()
MySQLServer.remove(self.server)
def test_wrong_uuid(self):
"""Test what happens when a server has a wrong uuid.
"""
# Check wrong uuid.
OPTIONS["uuid"] = _uuid.UUID("FD0AC9BB-1431-11E2-8137-11DEF124DCC5")
server = MySQLServer(**OPTIONS)
self.assertRaises(_errors.UuidError, server.connect)
server.disconnect()
ConnectionPool().purge_connections(OPTIONS["uuid"])
def test_properties(self):
"""Test setting MySQLServer's properties.
"""
server = self.server
# Check property user.
self.assertEqual(server.user, tests.utils.MySQLInstances().user)
server.user = "user"
self.assertEqual(server.user, "user")
server.user = tests.utils.MySQLInstances().user
# Check property passwd.
self.assertEqual(server.passwd, tests.utils.MySQLInstances().passwd)
server.passwd = "passwd"
self.assertEqual(server.passwd, "passwd")
server.passwd = tests.utils.MySQLInstances().passwd
# Check property status.
self.assertEqual(server.status, MySQLServer.SECONDARY)
server.status = MySQLServer.FAULTY
self.assertEqual(server.status, MySQLServer.FAULTY)
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.status, fetched_server.status)
server.status = MySQLServer.SECONDARY
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.status, fetched_server.status)
# Check property mode.
self.assertEqual(server.mode, MySQLServer.READ_ONLY)
server.mode = MySQLServer.OFFLINE
self.assertEqual(server.mode, MySQLServer.OFFLINE)
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.mode, fetched_server.mode)
server.mode = MySQLServer.READ_ONLY
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.mode, fetched_server.mode)
# Check property weight.
self.assertEqual(server.weight, MySQLServer.DEFAULT_WEIGHT)
server.weight = 0.1
self.assertEqual(server.weight, 0.1)
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.weight, fetched_server.weight)
server.weight = MySQLServer.DEFAULT_WEIGHT
fetched_server = MySQLServer.fetch(server.uuid)
self.assertEqual(server.weight, fetched_server.weight)
# Create instance without connecting it with a server.
self.assertEqual(server.read_only, None)
self.assertEqual(server.server_id, None)
self.assertEqual(server.gtid_enabled, None)
self.assertEqual(server.binlog_enabled, None)
self.assertEqual(server.version, None)
# Bind instance to a server.
server.connect()
self.assertNotEqual(server.read_only, None)
self.assertNotEqual(server.server_id, 0)
self.assertEqual(server.gtid_enabled, True)
self.assertEqual(server.binlog_enabled, True)
# Check read_only property.
server.read_only = True
self.assertEqual(server.read_only, True)
server.read_only = False
self.assertEqual(server.read_only, False)
def test_version(self):
"""Check MySQLServer's version.
"""
server = self.server
server.connect()
#.........这里部分代码省略.........
示例6: test_privileges
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [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))
示例7: TestMySQLSlave
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import disconnect [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, )))
#.........这里部分代码省略.........