Example #1
0
    def test_reset_promote(self):
        """Check the sequence reset master on a slave and promote it to master.
        """
        # Configure replication.
        instances = tests.utils.MySQLInstances()
        user = instances.user
        passwd = instances.passwd
        instances.configure_instances({0 : [{1 : []}, {2 : []}]}, user, passwd)
        master = instances.get_instance(0)
        slave_1 = instances.get_instance(1)
        slave_2 = instances.get_instance(2)

        self.proxy.group.create("group_id", "")
        self.proxy.group.add("group_id", master.address)
        self.proxy.group.add("group_id", slave_1.address)
        self.proxy.group.add("group_id", slave_2.address)
        status = self.proxy.group.promote("group_id", str(master.uuid))
        self.check_xmlrpc_command_result(status)

        # Create some data.
        master.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
        master.exec_stmt("USE test")
        master.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")

        # Demote the master and gurantee that everything is synchronized.
        status = self.proxy.group.demote("group_id")
        self.check_xmlrpc_command_result(status)

        # Call reset master on the slave and promote it to master. 
        _repl.reset_master(slave_1)
        status = self.proxy.group.promote("group_id", str(slave_1.uuid))
        self.check_xmlrpc_command_result(status)
    def test_reset_promote(self):
        """Check the sequence reset master on a slave and promote it to master.
        """
        # Configure replication.
        instances = tests.utils.MySQLInstances()
        user = instances.user
        passwd = instances.passwd
        instances.configure_instances({0 : [{1 : []}, {2 : []}]}, user, passwd)
        master = instances.get_instance(0)
        slave_1 = instances.get_instance(1)
        slave_2 = instances.get_instance(2)

        self.proxy.group.create("group_id", "")
        self.proxy.group.add("group_id", master.address)
        self.proxy.group.add("group_id", slave_1.address)
        self.proxy.group.add("group_id", slave_2.address)
        status = self.proxy.group.promote("group_id", str(master.uuid))
        self.assertStatus(status, _executor.Job.SUCCESS)

        # Create some data.
        master.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
        master.exec_stmt("USE test")
        master.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")

        # Demote the master and gurantee that everything is synchronized.
        status = self.proxy.group.demote("group_id")
        self.assertStatus(status, _executor.Job.SUCCESS)
        self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
        self.assertEqual(status[1][-1]["description"],
                         "Executed action (_wait_slaves_demote).")

        # Call reset master on the slave and promote it to master. 
        _repl.reset_master(slave_1)
        status = self.proxy.group.promote("group_id", str(slave_1.uuid))
        self.assertStatus(status, _executor.Job.SUCCESS)
Example #3
0
def cleanup_environment():
    """Clean up the existing environment
    """
    #Clean up information on instances.
    MySQLInstances().__instances = {}

    #Clean up information in the state store.
    uuid_server = _server.MySQLServer.discover_uuid(
        MySQLInstances().state_store_address, MySQLInstances().root_user,
        MySQLInstances().root_passwd
    )
    server = _server.MySQLServer(_uuid.UUID(uuid_server),
        MySQLInstances().state_store_address, MySQLInstances().root_user,
        MySQLInstances().root_passwd
    )
    server.connect()

    server.set_foreign_key_checks(False)
    tables = server.exec_stmt(
        "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE "
        "TABLE_SCHEMA = 'fabric' and TABLE_TYPE = 'BASE TABLE'"
    )
    for table in tables:
        server.exec_stmt("TRUNCATE fabric.%s" % (table[0], ))
    server.set_foreign_key_checks(True)

    #Remove all the databases from the running MySQL instances
    #other than the standard ones
    server_count = MySQLInstances().get_number_addresses()

    for i in range(0, server_count):
        uuid_server = _server.MySQLServer.discover_uuid(
            MySQLInstances().get_address(i)
        )
        server = _server.MySQLServer(
            _uuid.UUID(uuid_server), MySQLInstances().get_address(i)
        )
        server.connect()
        _replication.stop_slave(server, wait=True)

        server.set_foreign_key_checks(False)
        databases = server.exec_stmt("SHOW DATABASES", {"fetch" : True})
        for database in databases:
            if database[0] not in _server.MySQLServer.NO_USER_DATABASES:
                server.exec_stmt(
                    "DROP DATABASE IF EXISTS %s" % (database[0], )
                )
        server.set_foreign_key_checks(True)

        _replication.reset_master(server)
        _replication.reset_slave(server, clean=True)

    for __file in glob.glob(os.path.join(os.getcwd(), "*.sql")):
        os.remove(__file)
    def test_demote_promote(self):
        """Check the sequence demote and promote when some candidates have no
        information on GTIDs.
        """
        # Configure replication.
        instances = tests.utils.MySQLInstances()
        user = instances.user
        passwd = instances.passwd
        instances.configure_instances({0 : [{1 : []}, {2 : []}]}, user, passwd)
        master = instances.get_instance(0)
        slave_1 = instances.get_instance(1)
        slave_2 = instances.get_instance(2)

        self.proxy.group.create("group_id", "")
        self.proxy.group.add("group_id", master.address)
        self.proxy.group.add("group_id", slave_1.address)
        self.proxy.group.add("group_id", slave_2.address)
        self.proxy.group.promote("group_id", str(master.uuid))

        # Create some data.
        master.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
        master.exec_stmt("USE test")
        master.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")

        for server in [slave_2, slave_1, master]:
            # Demote the current master.
            status = self.proxy.group.demote("group_id")
            self.assertStatus(status, _executor.Job.SUCCESS)
            self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
            self.assertEqual(status[1][-1]["description"],
                             "Executed action (_wait_slaves_demote).")

            # Reset any information on GTIDs on a server.
            _repl.reset_slave(server, clean=True)
            _repl.reset_master(server)

            # Promote a new master.
            status = self.proxy.group.promote("group_id")
            self.assertStatus(status, _executor.Job.SUCCESS)
            self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
            self.assertEqual(status[1][-1]["description"],
                             "Executed action (_change_to_candidate).")

            # Create some data.
            server.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
            server.exec_stmt("USE test")
            server.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")
Example #5
0
    def test_demote_promote(self):
        """Check the sequence demote and promote when some candidates have no
        information on GTIDs.
        """
        # Configure replication.
        instances = tests.utils.MySQLInstances()
        user = instances.user
        passwd = instances.passwd
        instances.configure_instances({0 : [{1 : []}, {2 : []}]}, user, passwd)
        master = instances.get_instance(0)
        slave_1 = instances.get_instance(1)
        slave_2 = instances.get_instance(2)

        self.proxy.group.create("group_id", "")
        self.proxy.group.add("group_id", master.address)
        self.proxy.group.add("group_id", slave_1.address)
        self.proxy.group.add("group_id", slave_2.address)
        self.proxy.group.promote("group_id", str(master.uuid))

        # Create some data.
        master.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
        master.exec_stmt("USE test")
        master.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")

        for server in [slave_2, slave_1, master]:
            # Demote the current master.
            status = self.proxy.group.demote("group_id")
            self.check_xmlrpc_command_result(status)

            # Reset any information on GTIDs on a server.
            _repl.reset_slave(server, clean=True)
            _repl.reset_master(server)

            # Promote a new master.
            status = self.proxy.group.promote("group_id")
            self.check_xmlrpc_command_result(status)

            # Create some data.
            server.exec_stmt("CREATE DATABASE IF NOT EXISTS test")
            server.exec_stmt("USE test")
            server.exec_stmt("CREATE TABLE IF NOT EXISTS t_1(id INTEGER)")
Example #6
0
def cleanup_environment():
    """Clean up the existing environment
    """
    #Clean up information on instances.
    MySQLInstances().__instances = {}

    #Clean up information in the state store.
    uuid_server = _server.MySQLServer.discover_uuid(
        MySQLInstances().state_store_address,
        MySQLInstances().user,
        MySQLInstances().passwd)
    server = _server.MySQLServer(uuid.UUID(uuid_server),
                                 MySQLInstances().state_store_address,
                                 MySQLInstances().user,
                                 MySQLInstances().passwd)
    server.connect()

    server.set_foreign_key_checks(False)
    tables = server.exec_stmt(
        "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE "
        "TABLE_SCHEMA = '%s' and TABLE_TYPE = 'BASE TABLE'" %
        (MySQLInstances().store_db, ))
    for table in tables:
        server.exec_stmt("TRUNCATE %s.%s" % (
            MySQLInstances().store_db,
            table[0],
        ))
    server.set_foreign_key_checks(True)

    #Remove all the databases from the running MySQL instances
    #other than the standard ones
    server_count = MySQLInstances().get_number_addresses()

    for i in range(0, server_count):
        uuid_server = _server.MySQLServer.discover_uuid(
            MySQLInstances().get_address(i),
            MySQLInstances().user,
            MySQLInstances().passwd)
        server = _server.MySQLServer(uuid.UUID(uuid_server),
                                     MySQLInstances().get_address(i),
                                     MySQLInstances().user,
                                     MySQLInstances().passwd)
        server.connect()
        server.read_only = False
        _replication.stop_slave(server, wait=True)

        server.set_foreign_key_checks(False)
        databases = server.exec_stmt("SHOW DATABASES")
        for database in databases:
            if database[0] not in _server.MySQLServer.NO_USER_DATABASES:
                server.exec_stmt("DROP DATABASE IF EXISTS %s" %
                                 (database[0], ))
        server.set_foreign_key_checks(True)

        _replication.reset_master(server)
        _replication.reset_slave(server, clean=True)

        server.disconnect()

    for __file in glob.glob(os.path.join(os.getcwd(), "*.sql")):
        os.remove(__file)
    def test_clone_permissions(self):
        """Verify the permissions, needed for a clone operation.
        Change password of the backup user, clone fails on backup.
        Change password back,
        Revoke SELECT from the backup user, clone fails on backup.
        Grant SELECT back,
        Change password of the restore user, clone fails on restore.
        Change password back,
        Revoke CREATE from the restore user, clone fails on restore.
        Grant CREATE back.
        Clone succeeds.
        """

        #
        # Skip test in trial-mode. Users are the same as admin user.
        # Admin won't be able to grant a privilege back to itself.
        #
        if ((MySQLInstances().backup_user == MySQLInstances().user)
                or (MySQLInstances().restore_user == MySQLInstances().user)):
            # The trailing comma prevents a newline.
            print "Skipping test_clone_permissions in trial-mode --- ",
            return

        server1 = self.__server_1
        server2 = self.__server_2
        server3 = self.__server_3

        #
        # Construct a group in the backing store.
        #
        self.__group_1 = Group("GROUPID1", "First description.")
        Group.add(self.__group_1)
        self.__group_1.add_server(server1)
        self.__group_1.add_server(server2)
        self.__group_1.master = server2.uuid

        #
        # Change password of the the backup user, try a clone, which
        # fails, because the Fabric instance does still use the old
        # password, change password back. This works, because Fabric
        # does not pool the connections for backup and restore users. So
        # they have to be freshly connected for backup and restore
        # operations.
        #
        server1.exec_stmt(
            "SET PASSWORD FOR '{user}'@'%' ="
            " PASSWORD('foobar')".format(user=MySQLInstances().backup_user))
        status = self.proxy.server.clone("GROUPID1", server3.address, None)
        self.check_xmlrpc_command_result(status, has_error=True)
        server1.exec_stmt("SET PASSWORD FOR '{user}'@'%' ="
                          " PASSWORD('{passwd}')".format(
                              user=MySQLInstances().backup_user,
                              passwd=MySQLInstances().backup_passwd))

        #
        # Revoke the SELECT privilege from the backup user,
        # try a clone, which fails, grant SELECT back.
        #
        server1.exec_stmt("REVOKE SELECT ON *.* FROM '{user}'@'%'".format(
            user=MySQLInstances().backup_user))
        status = self.proxy.server.clone("GROUPID1", server3.address, None)
        self.check_xmlrpc_command_result(status, has_error=True)
        server1.exec_stmt("GRANT SELECT ON *.* TO '{user}'@'%'".format(
            user=MySQLInstances().backup_user))

        #
        # Change password of the the restore user, try a clone, which
        # fails, because the Fabric instance does still use the old
        # password, change password back. This works, because Fabric
        # does not pool the connections for backup and restore users. So
        # they have to be freshly connected for backup and restore
        # operations.
        #
        server3.exec_stmt(
            "SET PASSWORD FOR '{user}'@'%' ="
            " PASSWORD('foobar')".format(user=MySQLInstances().restore_user))
        status = self.proxy.server.clone("GROUPID1", server3.address, None)
        self.check_xmlrpc_command_result(status, has_error=True)
        server3.exec_stmt("SET PASSWORD FOR '{user}'@'%' ="
                          " PASSWORD('{passwd}')".format(
                              user=MySQLInstances().restore_user,
                              passwd=MySQLInstances().restore_passwd))

        #
        # Revoke the CREATE privilege from the restore user,
        # try a clone, which fails, grant CREATE back.
        #
        server3.exec_stmt("REVOKE CREATE ON *.* FROM '{user}'@'%'".format(
            user=MySQLInstances().restore_user))
        # We have to clear GTID_EXECUTED before we can restore.
        reset_master(server3)
        status = self.proxy.server.clone("GROUPID1", server3.address, None)
        self.check_xmlrpc_command_result(status, has_error=True)
        server3.exec_stmt("GRANT CREATE ON *.* TO '{user}'@'%'".format(
            user=MySQLInstances().restore_user))
        # We have to clear GTID_EXECUTED before we can try the next restore.
        reset_master(server3)

        #
        # Run a successful clone.
        #
        status = self.proxy.server.clone("GROUPID1", server3.address, None)
        self.check_xmlrpc_command_result(status)

        rows = server3.exec_stmt("SELECT NAME FROM db1.t1", {"fetch": True})
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'TEST 1')
        self.assertEqual(rows[1][0], 'TEST 2')
        rows = server3.exec_stmt("SELECT NAME FROM db2.t1", {"fetch": True})
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'TEST 1')
        self.assertEqual(rows[1][0], 'TEST 2')