def test_show_slave_status_noslave(): mocker = Mocker() connect = mocker.replace('MySQLdb.connect') link = connect(ARGS, KWARGS) mocker.result(link) cursor = link.cursor() sql = 'SHOW SLAVE STATUS' cursor.execute(sql) cursor.description fields = ( ('Slave_IO_State', ), ('Master_Host', ), ('Master_User', ), ('Master_Port', ), ('Connect_Retry', ), ('Master_Log_File', ), ('Read_Master_Log_Pos', ), ('Relay_Log_File', ), ('Relay_Log_Pos', ), ('Relay_Master_Log_File', ), ('Slave_IO_Running', ), ('Slave_SQL_Running', ), ('Replicate_Do_DB', ), ('Replicate_Ignore_DB', ), ('Replicate_Do_Table', ), ('Replicate_Ignore_Table', ), ('Replicate_Wild_Do_Table', ), ('Replicate_Wild_Ignore_Table', ), ('Last_Errno', ), ('Last_Error', ), ('Skip_Counter', ), ('Exec_Master_Log_Pos', ), ('Relay_Log_Space', ), ('Until_Condition', ), ('Until_Log_File', ), ('Until_Log_Pos', ), ('Master_SSL_Allowed', ), ('Master_SSL_CA_File', ), ('Master_SSL_CA_Path', ), ('Master_SSL_Cert', ), ('Master_SSL_Cipher', ), ('Master_SSL_Key', ), ('Seconds_Behind_Master', ), ('Master_SSL_Verify_Server_Cert', ), ('Last_IO_Errno', ), ('Last_IO_Error', ), ('Last_SQL_Errno', ), ('Last_SQL_Error', ), ) mocker.result(fields) cursor.fetchone() result = None mocker.result(result) cursor.close() mocker.replay() try: client = MySQLClient(read_default_file='/etc/my.cnf') expected_status = None slave_status = client.show_slave_status() assert_equals(slave_status, expected_status) mocker.verify() finally: mocker.restore()
def test_show_slave_status_noslave(): mocker = Mocker() connect = mocker.replace('MySQLdb.connect') link = connect(ARGS, KWARGS) mocker.result(link) cursor = link.cursor() sql = 'SHOW SLAVE STATUS' cursor.execute(sql) cursor.description fields = ( ('Slave_IO_State',), ('Master_Host',), ('Master_User',), ('Master_Port',), ('Connect_Retry',), ('Master_Log_File',), ('Read_Master_Log_Pos',), ('Relay_Log_File',), ('Relay_Log_Pos',), ('Relay_Master_Log_File',), ('Slave_IO_Running',), ('Slave_SQL_Running',), ('Replicate_Do_DB',), ('Replicate_Ignore_DB',), ('Replicate_Do_Table',), ('Replicate_Ignore_Table',), ('Replicate_Wild_Do_Table',), ('Replicate_Wild_Ignore_Table',), ('Last_Errno',), ('Last_Error',), ('Skip_Counter',), ('Exec_Master_Log_Pos',), ('Relay_Log_Space',), ('Until_Condition',), ('Until_Log_File',), ('Until_Log_Pos',), ('Master_SSL_Allowed',), ('Master_SSL_CA_File',), ('Master_SSL_CA_Path',), ('Master_SSL_Cert',), ('Master_SSL_Cipher',), ('Master_SSL_Key',), ('Seconds_Behind_Master',), ('Master_SSL_Verify_Server_Cert',), ('Last_IO_Errno',), ('Last_IO_Error',), ('Last_SQL_Errno',), ('Last_SQL_Error',), ) mocker.result(fields) cursor.fetchone() result = None mocker.result(result) cursor.close() mocker.replay() try: client = MySQLClient(read_default_file='/etc/my.cnf') expected_status = None slave_status = client.show_slave_status() assert_equals(slave_status, expected_status) mocker.verify() finally: mocker.restore()
def test_show_slave_status(): mocker = Mocker() connect = mocker.replace('MySQLdb.connect') link = connect(ARGS, KWARGS) mocker.result(link) cursor = link.cursor() sql = 'SHOW SLAVE STATUS' cursor.execute(sql) cursor.description fields = ( ('Slave_IO_State', ), ('Master_Host', ), ('Master_User', ), ('Master_Port', ), ('Connect_Retry', ), ('Master_Log_File', ), ('Read_Master_Log_Pos', ), ('Relay_Log_File', ), ('Relay_Log_Pos', ), ('Relay_Master_Log_File', ), ('Slave_IO_Running', ), ('Slave_SQL_Running', ), ('Replicate_Do_DB', ), ('Replicate_Ignore_DB', ), ('Replicate_Do_Table', ), ('Replicate_Ignore_Table', ), ('Replicate_Wild_Do_Table', ), ('Replicate_Wild_Ignore_Table', ), ('Last_Errno', ), ('Last_Error', ), ('Skip_Counter', ), ('Exec_Master_Log_Pos', ), ('Relay_Log_Space', ), ('Until_Condition', ), ('Until_Log_File', ), ('Until_Log_Pos', ), ('Master_SSL_Allowed', ), ('Master_SSL_CA_File', ), ('Master_SSL_CA_Path', ), ('Master_SSL_Cert', ), ('Master_SSL_Cipher', ), ('Master_SSL_Key', ), ('Seconds_Behind_Master', ), ('Master_SSL_Verify_Server_Cert', ), ('Last_IO_Errno', ), ('Last_IO_Error', ), ('Last_SQL_Errno', ), ('Last_SQL_Error', ), ) mocker.result(fields) cursor.fetchone() result = ('Waiting for master to send event', '127.0.0.1', 'msandbox', 23351, 60, 'mysql-bin.000004', 106, 'mysql_sandbox23353-relay-bin.001724', 251, 'mysql-bin.000004', 'Yes', 'Yes', '', '', '', '', '', '', 0, '', 0, 106, 564, 'None', '', 0, 'No', '', '', '', '', '', 0, 'No', 0, '', 0, '') mocker.result(result) cursor.close() mocker.replay() try: client = MySQLClient(read_default_file='/etc/my.cnf') expected_status = dict( list(zip([f[0].lower() for f in fields], result))) slave_status = client.show_slave_status() assert_equals(slave_status, expected_status) mocker.verify() finally: mocker.restore()
def test_show_slave_status(): mocker = Mocker() connect = mocker.replace('MySQLdb.connect') link = connect(ARGS, KWARGS) mocker.result(link) cursor = link.cursor() sql = 'SHOW SLAVE STATUS' cursor.execute(sql) cursor.description fields = ( ('Slave_IO_State',), ('Master_Host',), ('Master_User',), ('Master_Port',), ('Connect_Retry',), ('Master_Log_File',), ('Read_Master_Log_Pos',), ('Relay_Log_File',), ('Relay_Log_Pos',), ('Relay_Master_Log_File',), ('Slave_IO_Running',), ('Slave_SQL_Running',), ('Replicate_Do_DB',), ('Replicate_Ignore_DB',), ('Replicate_Do_Table',), ('Replicate_Ignore_Table',), ('Replicate_Wild_Do_Table',), ('Replicate_Wild_Ignore_Table',), ('Last_Errno',), ('Last_Error',), ('Skip_Counter',), ('Exec_Master_Log_Pos',), ('Relay_Log_Space',), ('Until_Condition',), ('Until_Log_File',), ('Until_Log_Pos',), ('Master_SSL_Allowed',), ('Master_SSL_CA_File',), ('Master_SSL_CA_Path',), ('Master_SSL_Cert',), ('Master_SSL_Cipher',), ('Master_SSL_Key',), ('Seconds_Behind_Master',), ('Master_SSL_Verify_Server_Cert',), ('Last_IO_Errno',), ('Last_IO_Error',), ('Last_SQL_Errno',), ('Last_SQL_Error',), ) mocker.result(fields) cursor.fetchone() result = ( 'Waiting for master to send event', '127.0.0.1', 'msandbox', 23351L, 60L, 'mysql-bin.000004', 106L, 'mysql_sandbox23353-relay-bin.001724', 251L, 'mysql-bin.000004', 'Yes', 'Yes', '', '', '', '', '', '', 0L, '', 0L, 106L, 564L, 'None', '', 0L, 'No', '', '', '', '', '', 0L, 'No', 0L, '', 0L, '' ) mocker.result(result) cursor.close() mocker.replay() try: client = MySQLClient(read_default_file='/etc/my.cnf') expected_status = dict(zip([f[0].lower() for f in fields], result)) slave_status = client.show_slave_status() assert_equals(slave_status, expected_status) mocker.verify() finally: mocker.restore()