示例#1
0
    def test_execute_stop_command_with_minimum_params(self):
        # Setup mha_helper object with online failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_ONLINE)

        # We setup the VIP first on the original master as it is assumed that the master already has the VIP attached
        # to it before we enter the stop command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip).assign_vip()

        # First we test by passing in all the parameters that MHA would pass to mha_helper
        self.assertTrue(self.mha_helper.execute_command(command=MHAHelper.FAILOVER_STOP_CMD,
                                                        orig_master_host=self.orig_master_host,
                                                        orig_master_ip=self.orig_master_ip,
                                                        orig_master_user=self.orig_master_user,
                                                        orig_master_password=self.orig_master_password))

        # Once the STOP command completes successfully, we would have read_only enabled on both new and original master
        # and we would have the VIP removed from the original master, so we are going to confirm that separately here
        orig_mysql = MySQLHelper(self.orig_master_ip, None, self.orig_master_user, self.orig_master_password)
        orig_mysql.connect()
        self.assertTrue(orig_mysql.is_read_only())

        self.assertFalse(VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                                        self.orig_master_ssh_port).has_vip())

        # We remove the VIP again just to have a clean slate at the end of the test
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                       self.orig_master_ssh_port).remove_vip()
示例#2
0
    def test_execute_stop_command_with_minimum_params(self):
        # Setup mha_helper object with online failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_ONLINE)

        # We setup the VIP first on the original master as it is assumed that the master already has the VIP attached
        # to it before we enter the stop command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip).assign_vip()

        # First we test by passing in all the parameters that MHA would pass to mha_helper
        self.assertTrue(
            self.mha_helper.execute_command(
                command=MHAHelper.FAILOVER_STOP_CMD,
                orig_master_host=self.orig_master_host,
                orig_master_ip=self.orig_master_ip,
                orig_master_user=self.orig_master_user,
                orig_master_password=self.orig_master_password))

        # Once the STOP command completes successfully, we would have read_only enabled on both new and original master
        # and we would have the VIP removed from the original master, so we are going to confirm that separately here
        orig_mysql = MySQLHelper(self.orig_master_ip, None,
                                 self.orig_master_user,
                                 self.orig_master_password)
        orig_mysql.connect()
        self.assertTrue(orig_mysql.is_read_only())

        self.assertFalse(
            VIPMetalHelper(self.orig_master_host, self.orig_master_ip,
                           self.orig_master_ssh_user,
                           self.orig_master_ssh_port).has_vip())

        # We remove the VIP again just to have a clean slate at the end of the test
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip,
                       self.orig_master_ssh_user,
                       self.orig_master_ssh_port).remove_vip()
示例#3
0
    def test_has_ssh(self):
        # We setup the VIP first on the original master as it is assumed that the master already has the VIP attached
        # to it before we enter the stop command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                       self.orig_master_ssh_port).assign_vip()

        print("\n- Testing 'disable write on the current master' stage by executing stopssh command")
        cmd = """{0} --command=stopssh --orig_master_host={1} --orig_master_ip={2} --orig_master_port={3} \
        --orig_master_ssh_host={4} --orig_master_ssh_ip={5} --orig_master_ssh_port={6} --ssh_user={7} \
        --test_config_path={8}""".format(self.failover_script_path, self.orig_master_host, self.orig_master_ip,
                                         self.orig_master_port, self.orig_master_ssh_host, self.orig_master_ssh_ip,
                                         self.orig_master_ssh_port, self.orig_master_ssh_user,
                                         self.mha_helper_config_dir)

        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = proc.communicate()
        print("STDOUT: \n%s" % stdout)
        print("STDERR: \n%s" % stderr)

        self.assertEqual(proc.returncode, 0)

        # Once the STOP command completes successfully, we would have the VIP removed from the original master,
        # so we are going to confirm that separately here
        self.assertFalse(VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                                        self.orig_master_ssh_port).has_vip())

        print("\n- Testing 'enable writes on the active master' stage by executing start command")
        cmd = """{0} --command=start --orig_master_host={1} --orig_master_ip={2} --orig_master_port={3} \
        --orig_master_ssh_host={4} --orig_master_ssh_ip={5} --orig_master_ssh_port={6} --new_master_host={7} \
        --new_master_ip={8} --new_master_port={9} --new_master_user={10} --new_master_password={11} --ssh_user={12} \
        --new_master_ssh_host={13} --new_master_ssh_ip={14} --new_master_ssh_port={15} \
        --test_config_path={16}""".format(self.failover_script_path, self.orig_master_host, self.orig_master_ip,
                                          self.orig_master_port, self.orig_master_ssh_host, self.orig_master_ssh_ip,
                                          self.orig_master_ssh_port, self.new_master_host, self.new_master_ip,
                                          self.new_master_port, self.new_master_user, self.new_master_password,
                                          self.new_master_ssh_user, self.new_master_ssh_host, self.new_master_ssh_ip,
                                          self.new_master_ssh_port, self.mha_helper_config_dir)

        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = proc.communicate()
        print("STDOUT: \n%s" % stdout)
        print("STDERR: \n%s" % stderr)

        self.assertEqual(proc.returncode, 0)

        # Once the START command completes successfully, we would have read_only disabled on the new master and we
        # would have the VIP assigned to the new master, so we are going to confirm that separately here
        new_mysql = MySQLHelper(self.new_master_ip, self.new_master_port, self.new_master_user,
                                self.new_master_password)

        new_mysql.connect()
        self.assertFalse(new_mysql.is_read_only())

        self.assertTrue(VIPMetalHelper(self.new_master_host, self.new_master_ip, self.new_master_ssh_user,
                                       self.new_master_ssh_port).has_vip())
示例#4
0
    def test_execute_start_command_with_all_params(self):
        # Setup mha_helper object with online failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_ONLINE)

        # We remove the VIP first from the original master as it is assumed that the master already has the VIP removed
        # from it before we enter the start command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip,
                       self.orig_master_ssh_user,
                       self.orig_master_ssh_port).remove_vip()

        # First we test by passing in all the parameters that MHA would pass to mha_helper
        self.assertTrue(
            self.mha_helper.execute_command(
                command=MHAHelper.FAILOVER_START_CMD,
                orig_master_host=self.orig_master_host,
                orig_master_ip=self.orig_master_ip,
                orig_master_port=self.orig_master_port,
                orig_master_user=self.orig_master_user,
                orig_master_password=self.orig_master_password,
                orig_master_ssh_host=self.orig_master_ssh_host,
                orig_master_ssh_ip=self.orig_master_ssh_ip,
                orig_master_ssh_port=self.orig_master_ssh_port,
                orig_master_ssh_user=self.orig_master_ssh_user,
                new_master_host=self.new_master_host,
                new_master_ip=self.new_master_ip,
                new_master_port=self.new_master_port,
                new_master_user=self.new_master_user,
                new_master_password=self.new_master_password,
                new_master_ssh_user=self.new_master_ssh_user,
                new_master_ssh_host=self.new_master_ssh_host,
                new_master_ssh_ip=self.new_master_ssh_ip,
                new_master_ssh_port=self.new_master_ssh_port,
                ssh_options=self.ssh_options))

        # Once the START command completes successfully, we would have read_only disabled on the new master and we
        # would have the VIP assigned to the new master, so we are going to confirm that separately here
        new_mysql = MySQLHelper(self.new_master_ip, self.new_master_port,
                                self.new_master_user, self.new_master_password)

        new_mysql.connect()
        self.assertFalse(new_mysql.is_read_only())

        self.assertTrue(
            VIPMetalHelper(self.new_master_host, self.new_master_ip,
                           self.new_master_ssh_user,
                           self.new_master_ssh_port).has_vip())

        # We remove the VIP again just to have a clean slate at the end of the test
        VIPMetalHelper(self.new_master_host, self.new_master_ip,
                       self.new_master_ssh_user,
                       self.new_master_ssh_port).remove_vip()
示例#5
0
    def test_kill_connection(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = int(os.getenv('MYSQL_TEST_PORT'))

        mysql_conn = MySQLHelper(host=mysql_host, port=mysql_port, user=mysql_user, password=mysql_password)
        if not mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        mysql_conn_id = mysql_conn.get_connection_id()
        self.assertTrue(self.mysql_conn.kill_connection(mysql_conn_id))

        del mysql_conn
示例#6
0
    def test_kill_connection(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = int(os.getenv('MYSQL_TEST_PORT'))

        mysql_conn = MySQLHelper(host=mysql_host,
                                 port=mysql_port,
                                 user=mysql_user,
                                 password=mysql_password)
        if not mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        mysql_conn_id = mysql_conn.get_connection_id()
        self.assertTrue(self.mysql_conn.kill_connection(mysql_conn_id))

        del mysql_conn
示例#7
0
    def setUp(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = os.getenv('MYSQL_TEST_PORT')

        if not mysql_host or not mysql_user or not mysql_password or not mysql_port:
            self.fail(msg='MySQL database connection information not set')

        self.mysql_conn = MySQLHelper(host=mysql_host,
                                      port=mysql_port,
                                      user=mysql_user,
                                      password=mysql_password)
        if not self.mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        self.mysql_version = os.getenv('MYSQL_TEST_VERSION')
示例#8
0
    def test_execute_start_command_with_all_params(self):
        # Setup mha_helper object with online failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_ONLINE)

        # We remove the VIP first from the original master as it is assumed that the master already has the VIP removed
        # from it before we enter the start command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                       self.orig_master_ssh_port).remove_vip()

        # First we test by passing in all the parameters that MHA would pass to mha_helper
        self.assertTrue(self.mha_helper.execute_command(command=MHAHelper.FAILOVER_START_CMD,
                                                        orig_master_host=self.orig_master_host,
                                                        orig_master_ip=self.orig_master_ip,
                                                        orig_master_port=self.orig_master_port,
                                                        orig_master_user=self.orig_master_user,
                                                        orig_master_password=self.orig_master_password,
                                                        orig_master_ssh_host=self.orig_master_ssh_host,
                                                        orig_master_ssh_ip=self.orig_master_ssh_ip,
                                                        orig_master_ssh_port=self.orig_master_ssh_port,
                                                        orig_master_ssh_user=self.orig_master_ssh_user,
                                                        new_master_host=self.new_master_host,
                                                        new_master_ip=self.new_master_ip,
                                                        new_master_port=self.new_master_port,
                                                        new_master_user=self.new_master_user,
                                                        new_master_password=self.new_master_password,
                                                        new_master_ssh_user=self.new_master_ssh_user,
                                                        new_master_ssh_host=self.new_master_ssh_host,
                                                        new_master_ssh_ip=self.new_master_ssh_ip,
                                                        new_master_ssh_port=self.new_master_ssh_port,
                                                        ssh_options=self.ssh_options))

        # Once the START command completes successfully, we would have read_only disabled on the new master and we
        # would have the VIP assigned to the new master, so we are going to confirm that separately here
        new_mysql = MySQLHelper(self.new_master_ip, self.new_master_port, self.new_master_user,
                                self.new_master_password)

        new_mysql.connect()
        self.assertFalse(new_mysql.is_read_only())

        self.assertTrue(VIPMetalHelper(self.new_master_host, self.new_master_ip, self.new_master_ssh_user,
                                       self.new_master_ssh_port).has_vip())

        # We remove the VIP again just to have a clean slate at the end of the test
        VIPMetalHelper(self.new_master_host, self.new_master_ip, self.new_master_ssh_user,
                       self.new_master_ssh_port).remove_vip()
示例#9
0
    def setUp(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = os.getenv('MYSQL_TEST_PORT')

        if not mysql_host or not mysql_user or not mysql_password or not mysql_port:
            self.fail(msg='MySQL database connection information not set')

        self.mysql_conn = MySQLHelper(host=mysql_host, port=mysql_port, user=mysql_user, password=mysql_password)
        if not self.mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        self.mysql_version = os.getenv('MYSQL_TEST_VERSION')
示例#10
0
 def test_is_read_only_query(self):
     self.assertEqual(MySQLHelper.is_read_only_query('SELECT 1'), True)
     self.assertEqual(
         MySQLHelper.is_read_only_query('INSERT INTO foo VALUES ("bar")'),
         False)
示例#11
0
class TestMySQLHelper(unittest.TestCase):
    def setUp(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = os.getenv('MYSQL_TEST_PORT')

        if not mysql_host or not mysql_user or not mysql_password or not mysql_port:
            self.fail(msg='MySQL database connection information not set')

        self.mysql_conn = MySQLHelper(host=mysql_host,
                                      port=mysql_port,
                                      user=mysql_user,
                                      password=mysql_password)
        if not self.mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        self.mysql_version = os.getenv('MYSQL_TEST_VERSION')

    def tearDown(self):
        self.mysql_conn.disconnect()

    def test_is_read_only_query(self):
        self.assertEqual(MySQLHelper.is_read_only_query('SELECT 1'), True)
        self.assertEqual(
            MySQLHelper.is_read_only_query('INSERT INTO foo VALUES ("bar")'),
            False)

    def test_get_version(self):
        self.assertEqual(self.mysql_conn.get_version(), self.mysql_version)

    def test_get_connection_id(self):
        self.assertNotEqual(self.mysql_conn.get_connection_id(), None)

    def test_get_current_user(self):
        self.assertNotEqual(self.mysql_conn.get_current_user(), None)

    def test_set_read_only(self):
        self.mysql_conn.set_read_only()
        self.assertEqual(self.mysql_conn.is_read_only(), True)

    def test_unset_read_only(self):
        self.mysql_conn.unset_read_only()
        self.assertEqual(self.mysql_conn.is_read_only(), False)

    def test_get_processlist(self):
        processlist = self.mysql_conn.get_processlist()
        self.assertTrue(len(processlist) >= 1)

    def test_kill_connection(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = int(os.getenv('MYSQL_TEST_PORT'))

        mysql_conn = MySQLHelper(host=mysql_host,
                                 port=mysql_port,
                                 user=mysql_user,
                                 password=mysql_password)
        if not mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        mysql_conn_id = mysql_conn.get_connection_id()
        self.assertTrue(self.mysql_conn.kill_connection(mysql_conn_id))

        del mysql_conn
示例#12
0
    def tearDown(self):
        # We remove the VIP just to have a clean slate at the end of the test
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                       self.orig_master_ssh_port).remove_vip()
        VIPMetalHelper(self.new_master_host, self.new_master_ip, self.new_master_ssh_user,
                       self.new_master_ssh_port).remove_vip()

        # We unset read only on original master to have a clean slate at the end of the test
        orig_mysql = MySQLHelper(self.orig_master_ip, self.orig_master_port, self.orig_master_user,
                                 self.orig_master_password)
        orig_mysql.connect()
        orig_mysql.unset_read_only()

        # We set read only on new master to have a clean slate at the end of the test
        new_mysql = MySQLHelper(self.new_master_ip, self.new_master_port, self.new_master_user,
                                self.new_master_password)
        new_mysql.connect()
        new_mysql.set_read_only()
示例#13
0
 def test_is_read_only_query(self):
     self.assertEqual(MySQLHelper.is_read_only_query('SELECT 1'), True)
     self.assertEqual(MySQLHelper.is_read_only_query('INSERT INTO foo VALUES ("bar")'), False)
示例#14
0
class TestMySQLHelper(unittest.TestCase):
    def setUp(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = os.getenv('MYSQL_TEST_PORT')

        if not mysql_host or not mysql_user or not mysql_password or not mysql_port:
            self.fail(msg='MySQL database connection information not set')

        self.mysql_conn = MySQLHelper(host=mysql_host, port=mysql_port, user=mysql_user, password=mysql_password)
        if not self.mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        self.mysql_version = os.getenv('MYSQL_TEST_VERSION')

    def tearDown(self):
        self.mysql_conn.disconnect()

    def test_is_read_only_query(self):
        self.assertEqual(MySQLHelper.is_read_only_query('SELECT 1'), True)
        self.assertEqual(MySQLHelper.is_read_only_query('INSERT INTO foo VALUES ("bar")'), False)

    def test_get_version(self):
        self.assertEqual(self.mysql_conn.get_version(), self.mysql_version)

    def test_get_connection_id(self):
        self.assertNotEqual(self.mysql_conn.get_connection_id(), None)

    def test_get_current_user(self):
        self.assertNotEqual(self.mysql_conn.get_current_user(), None)

    def test_set_read_only(self):
        self.mysql_conn.set_read_only()
        self.assertEqual(self.mysql_conn.is_read_only(), True)

    def test_unset_read_only(self):
        self.mysql_conn.unset_read_only()
        self.assertEqual(self.mysql_conn.is_read_only(), False)

    def test_get_processlist(self):
        processlist = self.mysql_conn.get_processlist()
        self.assertTrue(len(processlist) >= 1)

    def test_kill_connection(self):
        mysql_host = os.getenv('MYSQL_TEST_IP')
        mysql_user = os.getenv('MYSQL_TEST_USER')
        mysql_password = os.getenv('MYSQL_TEST_PASSWORD')
        mysql_port = int(os.getenv('MYSQL_TEST_PORT'))

        mysql_conn = MySQLHelper(host=mysql_host, port=mysql_port, user=mysql_user, password=mysql_password)
        if not mysql_conn.connect():
            self.fail(msg='Could not connect to the MySQL database')

        mysql_conn_id = mysql_conn.get_connection_id()
        self.assertTrue(self.mysql_conn.kill_connection(mysql_conn_id))

        del mysql_conn