Ejemplo n.º 1
0
    def test_on_mysql_newmaster_up(self):
        bus.queryenv_service = _QueryEnv()
        bus.platform = _Platform()
        config = bus.config
        sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
        handler = _MysqlHandler()
        root_pass, repl_pass, stat_pass = handler._add_mysql_users(mysql.ROOT_USER, mysql.REPL_USER, mysql.STAT_USER)
        handler._update_config( {mysql.OPT_ROOT_PASSWORD : root_pass,
                                                         mysql.OPT_REPL_PASSWORD : repl_pass,
                                                         mysql.OPT_STAT_PASSWORD : stat_pass})
        message = _Message()
        if linux.os.redhat_family:
            daemon = "/usr/libexec/mysqld"
        else:
            daemon = "/usr/sbin/mysqld"
        initd.stop("mysql")
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf', '--skip-grant-tables'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        myclient = pexpect.spawn('/usr/bin/mysql -h'+LOCAL_IP)
        myclient.expect('mysql>')
        repl_password = re.sub('[^\w]','', cryptotool.keygen(20))
        sql = "update mysql.user set password = PASSWORD('"+repl_password+"') where user = '******';"
        myclient.sendline(sql)
        myclient.expect('mysql>')
        result = myclient.before
        if re.search('ERROR', result):
            os.kill(myd.pid, signal.SIGTERM)
            raise BaseException("Cannot update user", result)
        myclient.sendline('FLUSH TABLES WITH READ LOCK;')
        myclient.expect('mysql>')
#               system('cp -pr /var/lib/mysql /var/lib/backmysql')
#               system('rm -rf /var/lib/mysql && cp -pr /var/lib/mysql2 /var/lib/mysql')
        myclient.sendline('SHOW MASTER STATUS;')
        myclient.expect('mysql>')
        # retrieve log file and position
        try:
            master_status = myclient.before.split('\r\n')[4].split('|')
        except:
            raise BaseException("Cannot get master status")
        finally:
            myclient.sendline('UNLOCK TABLES;')
            os.kill(myd.pid, signal.SIGTERM)
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        message.log_file = master_status[1].strip()
        message.log_pos = master_status[2].strip()
        message.repl_user = mysql.REPL_USER
        message.repl_password = repl_password
        message.root_password = root_pass
        handler.on_Mysql_NewMasterUp(message)
        os.kill(myd.pid, signal.SIGTERM)
        initd.stop("mysql")
        system ('rm -rf /var/lib/mysql && cp -pr /var/lib/backmysql /var/lib/mysql && rm -rf /var/lib/backmysql')
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
Ejemplo n.º 2
0
    def test_on_mysql_newmaster_up(self):
        bus.queryenv_service = _QueryEnv()
        bus.platform = _Platform()
        config = bus.config
        sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
        handler = _MysqlHandler()
        root_pass, repl_pass, stat_pass = handler._add_mysql_users(mysql.ROOT_USER, mysql.REPL_USER, mysql.STAT_USER)
        handler._update_config( {mysql.OPT_ROOT_PASSWORD : root_pass,
                                                         mysql.OPT_REPL_PASSWORD : repl_pass,
                                                         mysql.OPT_STAT_PASSWORD : stat_pass})
        message = _Message()
        if disttool.is_redhat_based():
            daemon = "/usr/libexec/mysqld"
        else:
            daemon = "/usr/sbin/mysqld"
        initd.stop("mysql")
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf', '--skip-grant-tables'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        myclient = pexpect.spawn('/usr/bin/mysql -h'+LOCAL_IP)
        myclient.expect('mysql>')
        repl_password = re.sub('[^\w]','', cryptotool.keygen(20))
        sql = "update mysql.user set password = PASSWORD('"+repl_password+"') where user = '******';"
        myclient.sendline(sql)
        myclient.expect('mysql>')
        result = myclient.before
        if re.search('ERROR', result):
            os.kill(myd.pid, signal.SIGTERM)
            raise BaseException("Cannot update user", result)
        myclient.sendline('FLUSH TABLES WITH READ LOCK;')
        myclient.expect('mysql>')
#               system('cp -pr /var/lib/mysql /var/lib/backmysql')
#               system('rm -rf /var/lib/mysql && cp -pr /var/lib/mysql2 /var/lib/mysql')
        myclient.sendline('SHOW MASTER STATUS;')
        myclient.expect('mysql>')
        # retrieve log file and position
        try:
            master_status = myclient.before.split('\r\n')[4].split('|')
        except:
            raise BaseException("Cannot get master status")
        finally:
            myclient.sendline('UNLOCK TABLES;')
            os.kill(myd.pid, signal.SIGTERM)
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        message.log_file = master_status[1].strip()
        message.log_pos = master_status[2].strip()
        message.repl_user = mysql.REPL_USER
        message.repl_password = repl_password
        message.root_password = root_pass
        handler.on_Mysql_NewMasterUp(message)
        os.kill(myd.pid, signal.SIGTERM)
        initd.stop("mysql")
        system ('rm -rf /var/lib/mysql && cp -pr /var/lib/backmysql /var/lib/mysql && rm -rf /var/lib/backmysql')
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
Ejemplo n.º 3
0
 def test_on_Mysql_PromoteToMaster(self):
     bus.queryenv_service = _QueryEnv()
     bus.platform = _Platform()
     config = bus.config
     sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
     message = _Message()
     message.root_password = '******'
     message.repl_password = '******'
     message.stat_password = '******'
     handler = _MysqlHandler()
     handler.on_Mysql_PromoteToMaster(message)
Ejemplo n.º 4
0
 def test_on_Mysql_PromoteToMaster(self):
     bus.queryenv_service = _QueryEnv()
     bus.platform = _Platform()
     config = bus.config
     sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
     message = _Message()
     message.root_password = '******'
     message.repl_password = '******'
     message.stat_password = '******'
     handler = _MysqlHandler()
     handler.on_Mysql_PromoteToMaster(message)
Ejemplo n.º 5
0
 def test_on_before_host_up_slave_eph(self):
     bus.queryenv_service = _QueryEnv()
     bus.platform = _Platform()
     message = _Message()
     config = bus.config
     sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
     bus.queryenv_service.storage = 'eph'
     handler = _MysqlHandler()
     handler.on_before_host_up(message)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
     datadir, log_bin = extract_datadir_and_log()
     self.assertEqual(datadir, '/mnt/dbstorage/mysql-data/')
     self.assertEqual(log_bin, '/mnt/dbstorage/mysql-misc/binlog.log')
Ejemplo n.º 6
0
 def test_on_before_host_up_slave_eph(self):
     bus.queryenv_service = _QueryEnv()
     bus.platform = _Platform()
     message = _Message()
     config = bus.config
     sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
     bus.queryenv_service.storage = 'eph'
     handler = _MysqlHandler()
     handler.on_before_host_up(message)
     config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
     datadir, log_bin = extract_datadir_and_log()
     self.assertEqual(datadir, '/mnt/dbstorage/mysql-data/')
     self.assertEqual(log_bin, '/mnt/dbstorage/mysql-misc/binlog.log')
Ejemplo n.º 7
0
 def tearDown(self):
     initd.stop("mysql")
     system('cp /etc/mysql/my.cnf /tmp/etc'+time.strftime("%d%b%H%M%S", time.gmtime()))
     system('rm -rf /etc/mysql/')
     system('rm -rf /var/lib/mysql')
     system('cp -pr /tmp/mysqletc/ /etc/mysql/ ')
     system('cp -pr /tmp/mysqldata/ /var/lib/mysql ')
     system('rm -rf /tmp/mysql*')
     system('rm -rf /mnt/dbstorage/*')
     system('rm -rf /mnt/tmpdir/*')
     initd.start("mysql")
     config = bus.config
     section = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     try:
         config.remove_option(section, mysql.OPT_ROOT_USER)
         config.remove_option(section, mysql.OPT_ROOT_PASSWORD)
         config.remove_option(section, mysql.OPT_REPL_USER)
         config.remove_option(section, mysql.OPT_REPL_PASSWORD)
         config.remove_option(section, mysql.OPT_STAT_USER)
         config.remove_option(section, mysql.OPT_STAT_PASSWORD)
     except:
         pass
Ejemplo n.º 8
0
 def tearDown(self):
     initd.stop("mysql")
     system('cp /etc/mysql/my.cnf /tmp/etc'+time.strftime("%d%b%H%M%S", time.gmtime()))
     system('rm -rf /etc/mysql/')
     system('rm -rf /var/lib/mysql')
     system('cp -pr /tmp/mysqletc/ /etc/mysql/ ')
     system('cp -pr /tmp/mysqldata/ /var/lib/mysql ')
     system('rm -rf /tmp/mysql*')
     system('rm -rf /mnt/dbstorage/*')
     system('rm -rf /mnt/tmpdir/*')
     initd.start("mysql")
     config = bus.config
     section = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
     try:
         config.remove_option(section, mysql.OPT_ROOT_USER)
         config.remove_option(section, mysql.OPT_ROOT_PASSWORD)
         config.remove_option(section, mysql.OPT_REPL_USER)
         config.remove_option(section, mysql.OPT_REPL_PASSWORD)
         config.remove_option(section, mysql.OPT_STAT_USER)
         config.remove_option(section, mysql.OPT_STAT_PASSWORD)
     except:
         pass