Beispiel #1
0
    def _override_master_to_point_in_time_after_operation(self, op_method):
        old_master_inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        master = utils.get_builtin_instance(old_master_inst_id)
        master_vid = master.virtual_instance_id

        # Prepare data before resize.
        db_count = 100 
        utils.generate_databases(master_vid, count = db_count)
        utils.check_generated_databases(master_vid, count = db_count)
        time.sleep(3)
        dt1 = datetime.datetime.now()
        time1 = dt1.strftime('%Y-%m-%d %H:%M:%S')

        def _get_restorable_time(sleep = None):
            if sleep != None:
                time.sleep(sleep)
                
            restorable_time = utils.get_restorable_time(master_vid)
            return restorable_time
        
        before_rt = _get_restorable_time(30)
        op_method()
        after_op_master = utils.get_builtin_instance(master_vid)
        after_rt = _get_restorable_time(30)
        assert before_rt.begin == after_rt.begin and after_rt.end > before_rt.end, \
                                ("before: [%s, %s], after: [%s, %s]" % (before_rt.begin, before_rt.end, after_rt.begin, after_rt.end)) 
        
        # Clear data after resize.
        utils.clear_generated_databases(master_vid, count = db_count)
        utils.check_generated_databases(master_vid, count = 0)
        
        # Restore & check data correctness.
        utils.override_with_backup_byclient(master_vid, None, time1)
        utils.check_server_deleted(after_op_master.id, DBInstanceType.PENDING, timeout = RESTORE_TIME_OUT)
        utils.check_generated_databases(master_vid, count = db_count)
Beispiel #2
0
    def override_with_backup(self, instance_id=None):
        self.inst_id = instance_id
        if not self.inst_id:
            self.create()
            self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)

        old_master_instance = utils.get_builtin_instance(self.inst_id)
        old_group_id = old_master_instance.group_id
        
        old_adm_user_1 = utils.check_mysql_adminuser(self.inst_id)
        backup1 = utils.create_backup_byclient(self.inst_id)
        utils.check_backup_status(backup1.id)
                
        new_password = "******" + str(random.randint(0, 100))
        utils.reset_admin_user_byclient(self.inst_id, new_password)
        new_adm_user_1 = utils.check_mysql_adminuser(self.inst_id)
        assert old_adm_user_1['_password'] != new_adm_user_1['_password'], \
            (old_adm_user_1['_password'], new_adm_user_1['_password'])
        backup2 = utils.create_backup_byclient(self.inst_id)
        utils.check_backup_status(backup2.id)
        
        utils.override_with_backup_byclient(self.inst_id, backup1.id)
        utils.check_server_deleted(old_master_instance.id, type = DBInstanceType.PENDING, timeout = 600)


        self.inst_id = utils.get_instance_id(old_group_id, DBInstanceType.MASTER)
        new_master_instance = utils.get_builtin_instance(self.inst_id)
        self.dbslave_id = utils.get_instance_id(old_group_id, DBInstanceType.STANDBY)
        self.vip_id = utils.get_vip_id(self.inst_id)
        self.group_id = new_master_instance.group_id
        self.validate()
        
        new_adm_user_2 = utils.check_mysql_adminuser(self.inst_id)
        assert old_adm_user_1['_password'] == new_adm_user_2['_password'], \
            (old_adm_user_1['_password'], new_adm_user_2['_password'])
Beispiel #3
0
    def resize_ha(self, instance_id=None):
        self.inst_id = instance_id
        if not self.inst_id:
            self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        _inst = utils.get_instance(self.inst_id, deleted=0)
        self.group_id = _inst.group_id

        master = InstanceGroupItem.get_by_gid_type(utils.get_context(), self.group_id, DBInstanceType.MASTER)
        standby = InstanceGroupItem.get_by_gid_type(utils.get_context(), self.group_id, DBInstanceType.STANDBY)
        if master:
            old_master_inst_id = master.instance_id
        if standby:
            old_standy_inst_id = standby.instance_id
        
        old_master_inst = utils.get_builtin_instance(old_master_inst_id)
        old_flavor_id = old_master_inst.flavor_id
        old_virtual_instance_id = old_master_inst.virtual_instance_id
        self.inst_id = old_master_inst.id
        
        if old_flavor_id not in ['1', '2', '3', '4']:
            raise Exception("It is not support to do resizing based on flavor id: %s, supported flavor_ids should be in (1,2,3,4)" % (old_flavor_id))
        
        flavor = str(int(old_flavor_id) + 1)
        LOG.info("old flavor : %s, new flavor : %s" % (old_flavor_id, flavor))
        
        utils.resize_flavor_byclient(self.inst_id, flavor)
        inst_ids = utils.check_resize_status(self.group_id)

        if len(inst_ids) >= 2:
            utils.check_rpl_delay(inst_ids[0])
            utils.check_rpl_delay(inst_ids[1])

            import time

            time.sleep(60)

            new_master = utils.get_builtin_instance(old_virtual_instance_id)
            new_standby = InstanceGroupItem.get_by_gid_type(utils.get_context(), new_master.group_id, DBInstanceType.STANDBY)

            if new_master.virtual_instance_id == old_virtual_instance_id and \
                            new_master.id != old_master_inst.id:
                self.inst_id = new_master.id
                self.dbslave_id = new_standby.instance_id
                self.vip_id = utils.get_vip_id(self.inst_id)
            else:
                raise Exception("resize for ha failed,new_master.virtual_instance_id %s,"
                                " old_virtual_instance_id %s, new_master.id %s,"
                                " old_master_inst.id %s, new_standby_id %s,"
                                " old_standy_inst_id %s" % (
                                    new_master.virtual_instance_id, old_virtual_instance_id,
                                    new_master.id, old_master_inst.id,
                                    new_standby.instance_id, old_standy_inst_id))
            
            self.validate()
            
        else:
            raise Exception("the num of instance_id should be equal or greater than two after resize HA ")
Beispiel #4
0
 def switch_master(self):
     self.create()
     inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
     inst = utils.get_builtin_instance(inst_id)
     inst_standby_id = utils.get_instance_id(inst.group_id, DBInstanceType.STANDBY)
     utils.check_switch_master(inst.id, inst_standby_id)
     pass
Beispiel #5
0
 def restart(self, instance_id=None):
     self.inst_id = instance_id
     if self.inst_id is None:
         self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
     utils.restart_mysql(self.inst_id)
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.STANDBY,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=240)
     self.vip_id = utils.get_vip_id(self.inst_id)
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     assert self.inst_id == _inst.virtual_instance_id, (self.inst_id, _inst.virtual_instance_id)
     self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
     LOG.info('master_id:%s slave_id:%s' % (self.inst_id, self.dbslave_id))
     
     utils.check_server_status(self.dbslave_id, expected_task=utils.tasks.InstanceTasks.REBOOTING,
                               type=DBInstanceType.STANDBY,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=240)
     
     utils.check_server_status(self.dbslave_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.STANDBY,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=240)
     self.validate()
Beispiel #6
0
    def resize(self):
        old_rr_inst_id = self._get_rid()
        rr_instance = utils.get_builtin_instance(old_rr_inst_id)
        old_flavor_id = rr_instance.flavor_id
        old_virtual_inst_id = rr_instance.virtual_instance_id
        
        flavor = old_flavor_id + 1 if old_flavor_id < 5 else 5
        _ret_inst = utils.resize_flavor_byclient(old_rr_inst_id,flavor)

        utils.check_server_status(old_virtual_inst_id, type = DBInstanceType.READ_REPLI, 
                                  expected_task = utils.tasks.InstanceTasks.RESIZING)
        
        insts = utils.check_resize_status(self.group_id)
        new_rr_id = insts[0] 
        
        utils.check_server_status(new_rr_id, type = DBInstanceType.READ_REPLI, 
                                  expected_task = utils.tasks.InstanceTasks.NONE, 
                                  expected_svr_status = utils.ServiceStatuses.RUNNING, 
                                  deleted = False, timeout = 120)
        new_rr_instance = utils.get_instance(new_rr_id, deleted = False)
        new_flavor_id = new_rr_instance.flavor_id
        
        assert  old_flavor_id != new_flavor_id
        
        self._validate(self.master_id, new_rr_id)
Beispiel #7
0
 def _validate(self, master_id, validated_inst_id):
     utils.check_server_status(validated_inst_id,expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.READ_REPLI,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False,timeout=300)
     
     utils.check_mysql_adminuser(validated_inst_id)
     utils.check_vip(master_id)
     vip_id = utils.get_vip_id(validated_inst_id)
     utils.check_vip(validated_inst_id,vip_id=vip_id)
 
     utils.check_rpl_delay(validated_inst_id)
     
     master_ip = utils.check_allocate_ip(utils.get_builtin_instance(master_id).server)
     rr_ip = utils.check_allocate_ip(utils.get_builtin_instance(validated_inst_id).server)
     
     utils.check_rpl_consist(master_id, [validated_inst_id],master_ip,[rr_ip])
     utils.check_rpl_topo_rr(self.group_id)
 def __trigger_host_reboot(cls, inst_id):
     inst = test_utils.get_builtin_instance( inst_id)
     nova_inst = inst.server
     hypervisor_host = nova_inst.__getattr__('OS-EXT-SRV-ATTR:host')
     test_utils.reboot_host(hypervisor_host)
     
     connectible = test_utils.check_connectible(hypervisor_host, interval = 2, count = 20)
     if connectible:
         raise Exception("host machine %s rebooted failed." % (hypervisor_host))
Beispiel #9
0
    def migrate(self):
        
        rr_inst_id = self._get_rid()
        old_rr_inst = utils.get_builtin_instance(rr_inst_id)
        old_rr_id = old_rr_inst.id
        
        rr_vid = old_rr_inst.virtual_instance_id
        
        _ret = rpc.call(utils.get_context(), "taskmanager",
                       {"method": "migrate",
                        "args": {'migrate_id': old_rr_inst.id}})

        utils.check_server_status(rr_vid, DBInstanceType.READ_REPLI, InstanceTasks.NONE, utils.ServiceStatuses.RUNNING, timeout = 600)
        new_rr_inst = utils.get_builtin_instance(rr_vid)
        assert new_rr_inst.virtual_instance_id == rr_vid and new_rr_inst.id != old_rr_id, (rr_vid, new_rr_inst.id)
        
        master_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        self._validate(master_id, rr_vid)
Beispiel #10
0
    def modify(self):
        modify_name = 'modify_name' + str(random.randint(0, 100))
        modify_admin_user = '******' + str(random.randint(0, 100))
        modify_admin_password = str(random.randint(0, 32))
        self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.READ_REPLI)
        if self.inst_id is None:
            raise Exception("not found RR instance")
        instance = utils.get_builtin_instance(self.inst_id)
        LOG.info("rr instance: '%s'" % instance.name)

        utils.modify_byclient(self.inst_id, modify_name)
        inst = utils.get_builtin_instance(self.inst_id)
        assert inst.name == modify_name, (modify_name, inst.name)
        
        try:
            utils.modify_byclient(self.inst_id, modify_name, modify_admin_user, modify_admin_password)
            assert False, ("Not allow to modify RR's admin_user and admin_password")
        except:
            pass
Beispiel #11
0
    def modify(self):
        modify_name = 'modify_name' + str(random.randint(0, 100))
        modify_admin_user = '******' + str(random.randint(0, 100))
        modify_admin_password = str(random.randint(0, 100))
        self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.SINGLE)
        if self.inst_id is None:
            raise Exception("not found SINGLE instance")
        instance = utils.get_builtin_instance(self.inst_id)

        utils.check_modify(self, instance, modify_name, modify_admin_user, modify_admin_password)
Beispiel #12
0
 def restorable_time_failover_twice(self):
     
     def failover(id):
         rpc.call(utils.get_context(), "taskmanager",
              {"method": "failover",
                "args": {'instance_id':id}})
     
     self.create()
     master = utils.get_builtin_instance(self.inst_id)
     master_vid = master.virtual_instance_id
     rt_1 = utils.get_restorable_time(master_vid)
     
     # case1: failover only
     failover1_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     failover(master.id)
     
     utils.check_server_status(master_vid, DBInstanceType.MASTER, timeout = 360)
     new_slave_id = master.id
     utils.check_server_status(new_slave_id, DBInstanceType.STANDBY, timeout = 360)
     
     rt_2 = utils.get_restorable_time(master_vid)
     assert rt_2.end > rt_1.end and rt_1.begin <= rt_2.begin, \
             ("before first failover rt: [%s, %s], after first failover rt: [%s, %s]" % (rt_1.begin, rt_1.end, rt_2.begin, rt_2.end))
     
     # case2: restart & failover
     master2 = utils.get_builtin_instance(master_vid)
     failover(master2.id)
     utils.check_server_status(master_vid, DBInstanceType.MASTER, timeout = 360)
     new_slave_id2 = master2.id
     utils.check_server_status(new_slave_id2, DBInstanceType.STANDBY, timeout = 360)
     
     rt_3 = utils.get_restorable_time(master_vid)
     assert rt_3.begin > failover1_time and rt_3.end > rt_2.end, (rt_3.begin, failover1_time, rt_3.end, rt_2.end)
     
     print rt_1.begin, rt_1.end
     print rt_2.begin, rt_2.end
     print rt_3.begin, rt_3.end
     print "the first failover time: %s" % (failover1_time)
     
     time.sleep(60)
     rt_4 = utils.get_restorable_time(master_vid)
     print rt_4.begin, rt_4.end
     assert rt_4.end > rt_3.end
Beispiel #13
0
 def restart(self):
     
     self.inst_id  = self._get_rid()
     old_rr_inst = utils.get_builtin_instance(self.inst_id)
     rr_vid = old_rr_inst.virtual_instance_id
     utils.check_server_status(rr_vid,  DBInstanceType.READ_REPLI, InstanceTasks.NONE, utils.ServiceStatuses.RUNNING, timeout = 600)
     
     utils.restart_mysql(rr_vid)
     utils.check_server_status(rr_vid, DBInstanceType.READ_REPLI, InstanceTasks.REBOOTING, utils.ServiceStatuses.RUNNING, timeout = 60)
     utils.check_server_status(rr_vid, DBInstanceType.READ_REPLI, InstanceTasks.NONE, utils.ServiceStatuses.RUNNING, timeout = 60)
     
     self.validate()
Beispiel #14
0
    def restore_to_point_in_time(self):
        self.create()
        old_master_inst = utils.get_builtin_instance(self.inst_id)
        master_vid = old_master_inst.virtual_instance_id
        
        db_count = 100
        utils.generate_databases(self.inst_id, count = db_count)        
        utils.check_generated_databases(self.inst_id, count = db_count)
        time.sleep(3)
        time1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 
        utils.clear_generated_databases(self.inst_id, count = db_count)
        time.sleep(3)
        dt2 = datetime.datetime.now()
        time2 = dt2.strftime('%Y-%m-%d %H:%M:%S')

        while True:
            restorable_time = utils.get_restorable_time(self.inst_id)
            dt = datetime.datetime.strptime(restorable_time.end, '%Y-%m-%d %H:%M:%S')
            if dt > dt2:
                break
            time.sleep(3)

        utils.restore_to_point_in_time_byclient(master_vid, time1) 
        time.sleep(10) # wait for compute instance appear
        new_inst1 = utils.get_restore_instance()
        utils.check_server_status(new_inst1, DBInstanceType.SINGLE, timeout=RESTORE_TIME_OUT) 
        utils.check_generated_databases(new_inst1, count = db_count)
        utils.delete_rds_byclient(new_inst1)
        utils.check_server_status(new_inst1, expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.SINGLE,
                                  expected_svr_status=utils.ServiceStatuses.DELETED,
                                  deleted=True, timeout=CONF.trove_delete_timeout)
            
        # delete original instance
        utils.delete_rds_byclient(master_vid)
        utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.MASTER,
                                  expected_svr_status=utils.ServiceStatuses.DELETED,
                                  deleted=True, timeout=CONF.trove_delete_timeout)
 
        # restore to point in time after deleting
        utils.restore_to_point_in_time_byclient(master_vid, time1)
        time.sleep(10) # wait for compute instance appear
        new_inst2 = utils.get_restore_instance()
        utils.check_server_status(new_inst2, DBInstanceType.SINGLE, timeout=RESTORE_TIME_OUT)
        utils.check_generated_databases(new_inst2, count = db_count)
        utils.delete_rds_byclient(new_inst2)
        utils.check_server_status(new_inst2, expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.SINGLE,
                                  expected_svr_status=utils.ServiceStatuses.DELETED,
                                  deleted=True, timeout=CONF.trove_delete_timeout)
Beispiel #15
0
    def override_to_point_in_time(self):
        
        self.create()
        old_master_inst = utils.get_builtin_instance(self.inst_id)
        master_vid = old_master_inst.virtual_instance_id

        db_count = 100
        utils.generate_databases(self.inst_id, count = db_count)        
        utils.check_generated_databases(self.inst_id, count = db_count)
        time.sleep(3)
        time1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 
        utils.clear_generated_databases(self.inst_id, count = db_count)
        time.sleep(3)
        dt2 = datetime.datetime.now()
        time2 = dt2.strftime('%Y-%m-%d %H:%M:%S')

        while True:
            restorable_time = utils.get_restorable_time(self.inst_id)
            dt = datetime.datetime.strptime(restorable_time.end, '%Y-%m-%d %H:%M:%S')
            if dt > dt2:
                break
            time.sleep(3)
            
        utils.override_with_backup_byclient(master_vid, None, time1)
        utils.check_server_deleted(old_master_inst.id, DBInstanceType.PENDING, timeout = RESTORE_TIME_OUT)
        new_master_inst1 = utils.get_builtin_instance(master_vid)
        self.inst_id = new_master_inst1.id
        utils.check_generated_databases(self.inst_id, count = db_count)
        
        time.sleep(3)
        
        utils.override_with_backup_byclient(master_vid, None, time2)
        utils.check_server_deleted(self.inst_id, DBInstanceType.PENDING, timeout = RESTORE_TIME_OUT)
        utils.check_generated_databases(master_vid, count = 0)
        
        self.inst_id = utils.get_instance_id(self.group_id, DBInstanceType.MASTER)
        self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
        self.validate()
Beispiel #16
0
 def validate(self):
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.MASTER,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=600)
     
     utils.check_server_status(self.dbslave_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.STANDBY,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=600)
     
     rr_items = InstanceGroupItem.get_by_gid_type(utils.get_context(), self.group_id, DBInstanceType.READ_REPLI, deleted = False)
     slave_ids = []
     for rr in rr_items:
         slave_ids.append(rr.instance_id)
     slave_ids.append(self.dbslave_id)
     
     utils.check_mysql_adminuser(self.inst_id)
     utils.check_mysql_adminuser(self.dbslave_id)
     
     for _id in [self.inst_id, self.dbslave_id]:
         utils.check_mysql_is_running(self.inst_id)
     
     utils.check_vip(self.inst_id, vip_id=self.vip_id)
     self.backup_id = utils.check_backup(self.group_id)
     utils.check_backup_status(self.backup_id) 
     utils.check_backup_path(self.backup_id)
     
     for slave_id in slave_ids:
         utils.check_rpl_delay(slave_id)
         
     master_inst = utils.get_builtin_instance(self.inst_id)
     slave_inst = utils.get_builtin_instance(self.dbslave_id)
     master_ip = utils.check_allocate_ip(master_inst.server)
     slave_ip = utils.check_allocate_ip(slave_inst.server)
     LOG.info("master_ip:%s  slave_ip:%s" % (master_ip, slave_ip))
     utils.check_rpl_consist(self.inst_id, slave_ids, master_ip, [slave_ip])
     utils.check_rpl_topo_ha(self.group_id)
Beispiel #17
0
 def _create_with_backup(self, backup, admin_user=None, admin_password=None):
     self.inst_id = utils.create_rds_byclient("HA", backup=backup.id, admin_user=admin_user,
                                              admin_password=admin_password)
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.MASTER,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=600)
     self.vip_id = utils.get_vip_id(self.inst_id)
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
     LOG.info('master_id:%s slave_id:%s' % (self.inst_id, self.dbslave_id))
     self.validate()
     return self.inst_id
Beispiel #18
0
 def _unlock(self):
     self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
     utils.unlock_byclient(self.inst_id)
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                       type=DBInstanceType.MASTER,
                       expected_svr_status=utils.ServiceStatuses.RUNNING,
                       deleted=False, timeout=240)
     self.vip_id = utils.get_vip_id(self.inst_id) 
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     assert self.inst_id == _inst.virtual_instance_id, (self.inst_id, _inst.virtual_instance_id)
     self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
     LOG.info('master_id:%s slave_id:%s' % (self.inst_id, self.dbslave_id))
     self.validate()
Beispiel #19
0
    def create_with_master_config(self):
        self.master_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        
        utils.check_server_status(self.master_id,expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.MASTER,
                                  expected_svr_status=utils.ServiceStatuses.RUNNING,
                                  deleted=False,timeout=10)
        _inst = utils.get_builtin_instance(self.master_id)
        self.group_id = _inst.group_id

        if not _inst.db_info.configuration_id:
            raise Exception("master configuration_id is None")
        self.inst_id = utils.create_rds_byclient("RR", instance_id=self.master_id,
                                                 config_id_from_master=_inst.db_info.configuration_id)
        self.validate()
        utils.check_instancedb_mysql_variables(self.inst_id)
Beispiel #20
0
    def create_with_config(self):
        self.master_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        
        utils.check_server_status(self.master_id,expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.MASTER,
                                  expected_svr_status=utils.ServiceStatuses.RUNNING,
                                  deleted=False,timeout=10)
        _inst = utils.get_builtin_instance(self.master_id)
        self.group_id = _inst.group_id

        config = utils.get_config_bytenant()
        if not config:
            raise Exception("not found template config")
        self.inst_id = utils.create_rds_byclient("RR",instance_id = self.master_id, config_id = config.id)
        self.validate()
        utils.check_instancedb_mysql_variables(self.inst_id)
Beispiel #21
0
 def configuration_patch(self):
     self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
     if self.inst_id is None:
         raise Exception("not found HA instance")
     utils.patch_instance_config_and_check(self.inst_id)
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.MASTER,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=240)
     self.vip_id = utils.get_vip_id(self.inst_id) 
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     self.inst_id = utils.get_instance_id(self.group_id, DBInstanceType.MASTER)
     self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
     LOG.info('master_id:%s slave_id:%s' % (self.inst_id, self.dbslave_id))
     self.validate()
     utils.check_instace_config_is_same(self.inst_id)
Beispiel #22
0
 def _failover(self, stop_mysqld = False, rm_mysql_data = False):
     self.inst_id = self._get_rid()
     utils.check_server_status(self.inst_id,expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.READ_REPLI,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False,timeout=10)
     self.vip_id = utils.get_vip_id(self.inst_id)
     _rr_server = utils.get_builtin_instance(self.inst_id)
     nova_instance = _rr_server.server
     self.group_id = _rr_server.db_info.group_id
     instance_id = self.inst_id
     
     ran_count = 56
     utils.generate_databases(self.master_id, count = ran_count)
     
     ip = utils.check_allocate_ip(nova_instance)
     if stop_mysqld:
         utils.stop_mysqld(ip)
     
     if rm_mysql_data:
         utils.mysql_data_lost(ip)
     
     utils.check_server_status(self.inst_id,expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.READ_REPLI,
                               expected_svr_status=utils.ServiceStatuses.SHUTDOWN,
                               deleted=False,timeout=120)
     _ret = rpc.call(utils.get_context(),"taskmanager",
                     {
                      "method": "failover",
                      "args": {'instance_id':instance_id}
                      }
                     )
     
     utils.check_server_status(self.inst_id,expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.READ_REPLI,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False,timeout=120)
     
     self.master_id = utils.get_instance_id(self.group_id,DBInstanceType.MASTER)
     self.inst_id = self.inst_id
     
     utils.check_generated_databases(self.inst_id, count = ran_count)
     self.validate()
    def __run_workload(cls, instance_id, do_prepare = False):

        inst = test_utils.get_builtin_instance( instance_id)

        if do_prepare:
            cmd = '''/usr/local/sysbench-0.5/bin/sysbench
                  --mysql-host=%s   
                  --mysql-port=%s     
                  --mysql-user=master    
                  --mysql-password=kingsoft 
                  --oltp-table-size=100000
                  --mysql-db=failover_db
                  --test=/tmp/sysbench-0.5/sysbench/tests/db/oltp.lua
                  prepare ''' % (inst.hostname, inst.port)
            
            p_utils.execute(cmd)
            
        cmd = '''/usr/local/sysbench-0.5/bin/sysbench
                  --mysql-host=%s   
                  --mysql-port=%s     
                  --mysql-user=master    
                  --mysql-password=kingsoft 
                  --oltp-table-size=100000
                  --mysql-db=failover_db
                  --test=/tmp/sysbench-0.5/sysbench/tests/db/oltp.lua
                  run 
              ''' % (inst.hostname, inst.port)
        
        args = cmd.splitlines()
        process = subprocess.Popen(args)
        
        def __proccess_done__():
            r_code = process.poll()
            return r_code != None
        
        utils.poll_until(__proccess_done__, sleep_time = 1, time_out = 60)
        
        try:
            process.terminate()
        except Exception, e:
            LOG.info(e)
Beispiel #24
0
    def validate(self):
        utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                                  expected_svr_status=utils.ServiceStatuses.RUNNING,
                                  deleted=False)
        inst_db_info = utils.get_instance(self.inst_id)
        self.group_id = inst_db_info.group_id

        utils.check_mysql_adminuser(inst_db_info.id)
        
        _ret = utils.get_builtin_instance(inst_db_info.id)
        self.nova_instance = _ret.server
        
#         ip = utils.check_allocate_ip(self.nova_instance)
        utils.check_mysql_is_running(inst_db_info.id)
        utils.check_vip(inst_db_info.id)
        
        self.backup_id = utils.check_backup(self.group_id)
        utils.check_backup_status(self.backup_id)
        utils.check_backup_path(self.backup_id)
        
        utils.check_rpl_topo_single(self.group_id)
Beispiel #25
0
    def _create_RRs(self, rr_count = 2, attach_same_vip = False):
        self.master_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)
        
        utils.check_server_status(self.master_id,expected_task=utils.tasks.InstanceTasks.NONE,
                                  type=DBInstanceType.MASTER,
                                  expected_svr_status=utils.ServiceStatuses.RUNNING,
                                  deleted=False,timeout=10)
        
        _inst = utils.get_builtin_instance(self.master_id)
        self.group_id = _inst.group_id
        
        rids = self._get_rids()
        if len(rids) == 0:
            vinst_id1 = utils.create_rds_byclient("RR", instance_id = self.master_id, attached_vip=None)
            self._validate(self.master_id, vinst_id1)
            origin_inst_id1 = inst_utils.virtual_instid_2_origin_instid(vinst_id1, get_deleted = False)
            vip_id = utils.get_vip_id(vinst_id1, deleted = False) 
            
            left_to_create = rr_count - 1
            while left_to_create > 0:
                if attach_same_vip:
                    utils.create_rds_byclient("RR", instance_id = self.master_id, attached_vip=vip_id)
                else:
                    utils.create_rds_byclient("RR", instance_id = self.master_id, attached_vip=None)
                    
                left_to_create -= 1
                
            rids = self._get_rids()
            map(lambda x: self._validate(self.master_id, x), rids)
            
            if attach_same_vip:
                utils.check_lbs_vip(vip_id, rids)
            else:
                utils.check_lbs_vip(vip_id, [origin_inst_id1])

        else:
            map(lambda x: self._validate(self.master_id, x), rids)
Beispiel #26
0
 def create_with_config(self):
     config = utils.get_config_bytenant()
     if not config:
         raise Exception("not found template config")
     self.inst_id = utils.create_rds_byclient("HA",config_id=config.id)
     
     utils.check_server_status(self.inst_id, expected_task=utils.tasks.InstanceTasks.NONE,
                               type=DBInstanceType.MASTER,
                               expected_svr_status=utils.ServiceStatuses.RUNNING,
                               deleted=False, timeout=240)
     self.vip_id = utils.get_vip_id(self.inst_id) 
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     self.inst_id =utils.get_instance_id(self.group_id, DBInstanceType.MASTER)
  
     self.dbslave_id = utils.get_instance_id(self.group_id, DBInstanceType.STANDBY)
      
     LOG.info('master_id:%s slave_id:%s' % (self.inst_id, self.dbslave_id))
     
     self.validate()
     
     utils.check_instancedb_mysql_variables(self.inst_id)
     utils.check_instancedb_mysql_variables(self.dbslave_id)
     utils.check_instace_config_is_same(self.inst_id)
Beispiel #27
0
 def show_errorlog(self):
     self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.SINGLE)
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     utils.get_errorlog(self.group_id, self.inst_id)
Beispiel #28
0
 def __prepare(self):
     self.master_id = utils.get_instance_id_bytenant(DBInstanceType.MASTER)        
     _inst = utils.get_builtin_instance(self.master_id)
     self.group_id = _inst.group_id
Beispiel #29
0
 def show_slowquery(self):
     self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.READ_REPLI)
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     sl_list = utils.get_slowquery(self.group_id, _inst.id)
     assert sl_list != None
Beispiel #30
0
 def show_errorlog(self):
     self.inst_id = utils.get_instance_id_bytenant(DBInstanceType.READ_REPLI)
     _inst = utils.get_builtin_instance(self.inst_id)
     self.group_id = _inst.group_id
     error_logs = utils.get_errorlog(self.group_id, _inst.id)
     assert error_logs != None