def test_create_by_time_shard(dbVersion,instance_data,http_client,createMongoSharding,disk_type):
    # 按时间点创建分片集群
    # backupId = create_backup   #创建完mongo后的自动备份是物理备份,需要等5分钟,所以这里手动创建备份比较快
    # assert backupId != None or backupId != "", "backup false,backupId is null!!!"
    # time.sleep(60)
    # 向mongo中插入数据
    origin_spaceId = createMongoSharding
    if instance_data["create_by_time_write_date_flag"]==1: #从配置文件读取该值,1为校验数据准确性,其它值不校验:
        # dataCount=50000
        floating_ip = basics.get_docker_info.get_docker_info("GetFloatingIpBySpaceId", origin_spaceId, http_client)
        basics.write_data.write_data(floating_ip, instance_data["write_data_count"], "ip")
        # basics.write_data.write_data_by_floatIP(get_docker_info_shard["floating_ip"], dataCount,"ip")
        time.sleep(600)
        spaceId=create_mongo_api(dbVersion,instance_data,http_client,"2",disk_type,origin_spaceId=origin_spaceId)
        wait_mongo_status_is_100(http_client,spaceId,3000,"create sharding by time")
        # assert basics.write_data.count_data(get_docker_info["floating_ip"])==5000,"data count is [{}]".format(basics.write_data.count_data(get_docker_info["floating_ip"]))
        #获取按时间点创建实例的floatingIp
        floating_ip = basics.get_docker_info.get_docker_info("GetFloatingIpBySpaceId", spaceId, http_client)
        log.debug("create by time floatingIp is [{}]".format(floating_ip))
        # 按时间点创建实例的data count
        by_time_data_count=basics.write_data.count_data(floating_ip)
        assert by_time_data_count == instance_data["write_data_count"], "create by time data count is [{}]".format(by_time_data_count)
        log.info("create mongo by time success!!!data count:{}".format(by_time_data_count))
        delete_mongo(http_client, spaceId)
        print "==========================================================================================="
    else:
        time.sleep(350)  # 等待新创建的实例备份完成
        spaceId = create_mongo_api(dbVersion, instance_data, http_client, "2", disk_type, origin_spaceId=origin_spaceId)
        wait_mongo_status_is_100(http_client, spaceId, 3000, "create sharding by time")
        log.info("create mongo by time success!!!")
        delete_mongo(http_client, spaceId)
Ejemplo n.º 2
0
def createMongoDts(request, instance_data, http_client, instance_type,
                   disk_type, dbVersion, replicationFactor):
    spaceId = create_mongo_api(dbVersion, instance_data, http_client,
                               instance_type, disk_type, replicationFactor)
    #time,等待的时间,单位s
    wait_mongo_status_is_100(http_client, spaceId, 1000, "create mongo")
    # host_ip, docker_id, failover_flag, floating_ip, _, _ = basics.get_hostIp_dockerId_floatIp.get_host_docker(
    # spaceId, mysql_client)
    # coll = MongodbConnect(floating_ip)
    # coll.run()
    print "=========================================================================================="

    #return spaceId

    def teardown():
        #删除mongo
        httpStatus, res_data, headers = http_client.httpRequest(
            "DELETE", "clusters/{0}".format(spaceId))
        if httpStatus == 200:
            log.info("[INFO]delete mongo {} success".format(spaceId))
        else:
            log.error("delete mongo {} failed".format(spaceId))

    request.addfinalizer(teardown)
    return spaceId
def test_create_by_backup(dbVersion,instance_data,http_client,instance_type,disk_type,create_backup,replicationFactor):
    # 按备份创建
    backupId=create_backup
    assert backupId != None or backupId != "", "backup false,backupId is null!!!"
    log.info("backupId is [{}]".format(backupId))
    spaceId=create_mongo_api(dbVersion,instance_data,http_client,instance_type,disk_type,replicationFactor,backupId=backupId)
    wait_mongo_status_is_100(http_client,spaceId,1000,"create mongo by backup")
    log.info("create mongo by backup success!!!spaceId is {}".format(spaceId))
    delete_mongo(http_client, spaceId)
    print "==========================================================================================="