示例#1
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)
示例#2
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 ")