Example #1
0
    def setUp(self):
        self.root_directory = os.path.dirname(os.path.realpath(__file__))

        mha_helper_config_dir = os.path.join(self.root_directory, 'conf',
                                             'good')
        if not mha_helper_config_dir:
            self.fail(msg='mha_helper configuration dir not set')

        ConfigHelper.MHA_HELPER_CONFIG_DIR = mha_helper_config_dir
        if not ConfigHelper.load_config():
            self.fail(msg='Could not load mha_helper configuration from %s' %
                      mha_helper_config_dir)

        self.ssh_host = os.getenv('SSH_TEST_HOST')
        self.ssh_host_ip = os.getenv('SSH_TEST_IP')
        self.ssh_user = os.getenv('SSH_TEST_USER')
        self.ssh_port = os.getenv('SSH_TEST_PORT')

        if not self.ssh_host or not self.ssh_host_ip or not self.ssh_user or not self.ssh_port:
            self.fail(msg='SSH connection information not set')

        self.vip_helper = VIPMetalHelper(host=self.ssh_host,
                                         host_ip=self.ssh_host_ip,
                                         ssh_user=self.ssh_user,
                                         ssh_port=self.ssh_port,
                                         ssh_options=None)
Example #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()
Example #3
0
    def test_status(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 status 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 the status command")
        cmd = """{0} --command=status --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 still attached on the original master,
        # so we are going to confirm that separately here
        self.assertTrue(VIPMetalHelper(self.orig_master_host, self.orig_master_ip, self.orig_master_ssh_user,
                                       self.orig_master_ssh_port).has_vip())
Example #4
0
    def test_execute_stop_ssh_command_with_minimum_params(self):
        # Setup mha_helper object with hard failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_HARD)

        # 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_ssh command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip,
                       self.orig_master_ssh_user,
                       self.orig_master_ssh_port).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_STOPSSH_CMD,
                orig_master_host=self.orig_master_host,
                orig_master_ip=self.orig_master_ip,
                orig_master_port=self.orig_master_port))

        # Once the STOP SSH command completes successfully, the VIP should be removed from the original master
        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()
Example #5
0
    def test_execute_stop_hard_command_with_all_params(self):
        # Setup mha_helper object with hard failover type
        self.mha_helper = MHAHelper(MHAHelper.FAILOVER_TYPE_HARD)

        # 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_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,
                ssh_options=self.ssh_options))

        # Once the STOP HARD command completes successfully, there is no change in state on the original master
        # because there is nothing to do as STOP HARD means in bare metal no SSH basically
        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()
Example #6
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())
Example #7
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()
Example #8
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()
Example #9
0
    def test_execute_status_command_with_all_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 status command
        VIPMetalHelper(self.orig_master_host, self.orig_master_ip,
                       self.orig_master_ssh_user,
                       self.orig_master_ssh_port).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_STATUS_CMD,
                orig_master_host=self.orig_master_host,
                orig_master_ip=self.orig_master_ip,
                orig_master_port=self.orig_master_port,
                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,
                ssh_options=self.ssh_options))

        # 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()

        # And then we test the status command again to make sure that it actually returns false this time
        self.assertFalse(
            self.mha_helper.execute_command(
                command=MHAHelper.FAILOVER_STATUS_CMD,
                orig_master_host=self.orig_master_host,
                orig_master_ip=self.orig_master_ip,
                orig_master_port=self.orig_master_port,
                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,
                ssh_options=self.ssh_options))
    def setUp(self):
        self.root_directory = os.path.dirname(os.path.realpath(__file__))

        mha_helper_config_dir = os.path.join(self.root_directory, 'conf', 'good')
        if not mha_helper_config_dir:
            self.fail(msg='mha_helper configuration dir not set')

        ConfigHelper.MHA_HELPER_CONFIG_DIR = mha_helper_config_dir
        if not ConfigHelper.load_config():
            self.fail(msg='Could not load mha_helper configuration from %s' % mha_helper_config_dir)

        self.ssh_host = os.getenv('SSH_TEST_HOST')
        self.ssh_host_ip = os.getenv('SSH_TEST_IP')
        self.ssh_user = os.getenv('SSH_TEST_USER')
        self.ssh_port = os.getenv('SSH_TEST_PORT')

        if not self.ssh_host or not self.ssh_host_ip or not self.ssh_user or not self.ssh_port:
            self.fail(msg='SSH connection information not set')

        self.vip_helper = VIPMetalHelper(host=self.ssh_host, host_ip=self.ssh_host_ip, ssh_user=self.ssh_user,
                                         ssh_port=self.ssh_port, ssh_options=None)
Example #11
0
class TestVIPMetalHelper(unittest.TestCase):
    def setUp(self):
        self.root_directory = os.path.dirname(os.path.realpath(__file__))

        mha_helper_config_dir = os.path.join(self.root_directory, 'conf',
                                             'good')
        if not mha_helper_config_dir:
            self.fail(msg='mha_helper configuration dir not set')

        ConfigHelper.MHA_HELPER_CONFIG_DIR = mha_helper_config_dir
        if not ConfigHelper.load_config():
            self.fail(msg='Could not load mha_helper configuration from %s' %
                      mha_helper_config_dir)

        self.ssh_host = os.getenv('SSH_TEST_HOST')
        self.ssh_host_ip = os.getenv('SSH_TEST_IP')
        self.ssh_user = os.getenv('SSH_TEST_USER')
        self.ssh_port = os.getenv('SSH_TEST_PORT')

        if not self.ssh_host or not self.ssh_host_ip or not self.ssh_user or not self.ssh_port:
            self.fail(msg='SSH connection information not set')

        self.vip_helper = VIPMetalHelper(host=self.ssh_host,
                                         host_ip=self.ssh_host_ip,
                                         ssh_user=self.ssh_user,
                                         ssh_port=self.ssh_port,
                                         ssh_options=None)

    def tearDown(self):
        self.vip_helper.remove_vip()

    def test_assign_vip(self):
        # We test assigning a VIP to a host that already does not have the VIP
        self.assertTrue(self.vip_helper.assign_vip())

        # We then test assigning a VIP to a host that already has the the VIP assigned
        self.assertFalse(self.vip_helper.assign_vip())

    def test_remove_vip(self):
        # We test removing the VIP from the host that already does not have the VIP
        self.assertFalse(self.vip_helper.remove_vip())

        # We then test removing the VIP from the host that already has the the VIP assigned
        self.vip_helper.assign_vip()
        self.assertTrue(self.vip_helper.remove_vip())

    def test_has_vip(self):
        # We test to see that we are able to validate the function against a host without the VIP
        self.assertFalse(self.vip_helper.has_vip())

        # We now test to see that we are able to validate the function against a host that does have the VIP
        self.vip_helper.assign_vip()
        self.assertTrue(self.vip_helper.has_vip())
class TestVIPMetalHelper(unittest.TestCase):
    def setUp(self):
        self.root_directory = os.path.dirname(os.path.realpath(__file__))

        mha_helper_config_dir = os.path.join(self.root_directory, 'conf', 'good')
        if not mha_helper_config_dir:
            self.fail(msg='mha_helper configuration dir not set')

        ConfigHelper.MHA_HELPER_CONFIG_DIR = mha_helper_config_dir
        if not ConfigHelper.load_config():
            self.fail(msg='Could not load mha_helper configuration from %s' % mha_helper_config_dir)

        self.ssh_host = os.getenv('SSH_TEST_HOST')
        self.ssh_host_ip = os.getenv('SSH_TEST_IP')
        self.ssh_user = os.getenv('SSH_TEST_USER')
        self.ssh_port = os.getenv('SSH_TEST_PORT')

        if not self.ssh_host or not self.ssh_host_ip or not self.ssh_user or not self.ssh_port:
            self.fail(msg='SSH connection information not set')

        self.vip_helper = VIPMetalHelper(host=self.ssh_host, host_ip=self.ssh_host_ip, ssh_user=self.ssh_user,
                                         ssh_port=self.ssh_port, ssh_options=None)

    def tearDown(self):
        self.vip_helper.remove_vip()

    def test_assign_vip(self):
        # We test assigning a VIP to a host that already does not have the VIP
        self.assertTrue(self.vip_helper.assign_vip())

        # We then test assigning a VIP to a host that already has the the VIP assigned
        self.assertFalse(self.vip_helper.assign_vip())

    def test_remove_vip(self):
        # We test removing the VIP from the host that already does not have the VIP
        self.assertFalse(self.vip_helper.remove_vip())

        # We then test removing the VIP from the host that already has the the VIP assigned
        self.vip_helper.assign_vip()
        self.assertTrue(self.vip_helper.remove_vip())

    def test_has_vip(self):
        # We test to see that we are able to validate the function against a host without the VIP
        self.assertFalse(self.vip_helper.has_vip())

        # We now test to see that we are able to validate the function against a host that does have the VIP
        self.vip_helper.assign_vip()
        self.assertTrue(self.vip_helper.has_vip())