Example #1
0
    def test_target_master_and_proxy_failover(self, config, instance_data, expected_data):
        instance = instance_data["modify_standard_instance"]

        expected_object = baseCheckPoint(expected_data[instance["cacheInstanceClass"]],
                                         instance["instance_password"])
        client, _, instanceId = create_validate_instance(config, instance, expected_object)

        shard_num = instance["target_shardNumber"]
        resp = reset_class(config, instanceId, instance["target_cacheInstanceClass"], client, shard_num)
        assertRespNotNone(resp)

        expected_object = baseCheckPoint(expected_data[instance["target_cacheInstanceClass"]], instance["instance_password"])
        expected_object.side = 1
        expected_object.current_rs_type = "b"
        expected_object.next_rs_type = "a"

        # 等待spaceStatus变为DoingCopyfrom
        for i in range(0, 1200):
            resp_status = get_space_status(instanceId, config)
            if resp_status == "DoingCopyfrom":
                break
            sleep(1)

        # 触发master failover
        next_rs_type = get_next_rs_type(instanceId, config)
        redisNum = get_redis_num(instanceId, config, next_rs_type)
        redisId = get_shard_id(redisNum, 1)[0]
        replicasetName = instanceId + "-master-" + next_rs_type
        dockerName = replicasetName + "-" + str(redisId)
        oldRunTime = get_docker_running_time(config, instanceId, replicasetName, dockerName)
        status = trigger_docker_failover("redis", config, instanceId, config["region"], docker_name=dockerName)
        assert status == 200

        # 触发proxy failover
        proxyId = get_shard_id(get_proxy_num(instanceId, config), 1)[0]
        proxyReplicasetName = instanceId + "-proxy"
        proxyDockerName = proxyReplicasetName + "-" + str(proxyId)
        proxyOldRunTime = get_docker_running_time(config, instanceId, proxyReplicasetName, proxyDockerName)
        status = trigger_docker_failover("proxy", config, instanceId, config["region"],id=proxyId)
        assert status == 200

        # 等待redis failover结束
        assert wait_docker_run_time_change(config, instanceId, oldRunTime, replicasetName, dockerName)

        #等待proxy failover结束
        assert wait_docker_run_time_change(config, instanceId, proxyOldRunTime, proxyReplicasetName, proxyDockerName)

        # 手动调用任务恢复接口
        print("please run recover task interface.For example:curl http://127.0.0.1:1818/reloadTask -d '{\"taskId\":\"$taskId\",\"isRollback\":false}'")

        sleep(10)
        for i in range(0, 3600):
            if get_space_status(instanceId, config) == "Running":
                break
            sleep(1)

        assert check_admin_proxy_redis_configmap(instanceId, config, expected_object, shard_num)
Example #2
0
    def test_proxy_failover(self, config, instance_data, expected_data):
        instance = instance_data["modify_cluster_instance"]

        expected_object = baseCheckPoint(
            expected_data[instance["cacheInstanceClass"]],
            instance["instance_password"])
        client, _, instanceId = create_validate_instance(
            config, instance, expected_object)

        shard_num = instance["target_shardNumber"]
        resp = reset_class(config, instanceId,
                           instance["target_cacheInstanceClass"], client,
                           shard_num)
        assertRespNotNone(resp)

        expected_object = baseCheckPoint(
            expected_data[instance["target_cacheInstanceClass"]],
            instance["instance_password"])
        expected_object.side = 1
        expected_object.current_rs_type = "b"
        expected_object.next_rs_type = "a"

        # 等待resize开始
        for i in range(0, 600):
            resp_get_job = get_job(instanceId, config, str(resp.request_id))
            if resp_get_job["code"] == 0:
                break
            sleep(1)

        # 触发proxy failover
        proxyId = get_shard_id(get_proxy_num(instanceId, config), 1)[0]
        replicasetName = instanceId + "-proxy"
        dockerName = replicasetName + "-" + str(proxyId)
        oldRunTime = get_docker_running_time(config, instanceId,
                                             replicasetName, dockerName)
        status = trigger_docker_failover("proxy",
                                         config,
                                         instanceId,
                                         config["region"],
                                         id=proxyId)
        assert status == 200

        assert wait_docker_run_time_change(config, instanceId, oldRunTime,
                                           replicasetName, dockerName)
        print(
            "please run recover task interface.For example:curl http://127.0.0.1:1818/reloadTask -d '{\"taskId\":"
            ",\"isRollback\":false}'")

        sleep(10)
        for i in range(0, 3600):
            if get_space_status(instanceId, config) == "Running":
                break
            sleep(1)

        assert check_admin_proxy_redis_configmap(instanceId, config,
                                                 expected_object, shard_num)