def test_openapi_cross_domain_by_time_create_instance_until_finshed(self, dbVersion,instanceStorageType,mongOpenAPI,openAPI_createMongoDb):
     #跨域根据时间点创建
     time.sleep(5)
     # 查询跨域服务
     status, resp = mongOpenAPI.openapi_query_backup_synchronicities_cap(1, 100)
     assert status == 200
     assert int(resp["result"]["totalCount"]) != 1
     service_id = None
     restore_time = None
     for dict in resp["result"]["backupSynchronicities"]:
         if dict["instanceId"] == openAPI_createMongoDb:
             service_id = dict["serviceId"]
             restore_time = utils.api_util.utc_to_local_time_stamp(dict["newestDataTime"])
             break
     assert service_id
     assert restore_time
     status, resp = MongOpenAPISteps().openapi_create_instance_until_finshed(dbVersion,instanceStorageType,mongOpenAPI, restoreTime=restore_time, flag=False, flags=False, serviceId=service_id)
     info_logger.info("resp is [{}]".format(resp))
     #if status != 200 or resp["result"]["totalCount"] is None:
     if  resp["result"]["totalCount"] is None:
         assert False
     assert resp["result"]["dbInstances"][0]["instanceStatus"] == 'RUNNING'
     instance = resp["result"]["dbInstances"][0]["instanceId"]
     time.sleep(20)
     flag = MongOpenAPISteps().openapi_delete_instance_until_finshed(mongOpenAPI, instance, flags=False)
     assert flag
     info_logger.info("test_openapi_cross_domain_by_time_create_instance_until_finshed success")
 def test_openapi_create_by_time_instance_until_finshed(self,dbVersion,instanceStorageType, mongOpenAPI,createByTimeId):
     #根据时间点创建
     time.sleep(5)
     publicIp = mongOpenAPI.openapi_describe_instance_attribute_cap(createByTimeId)["instancePublicDomain"].split(",")[0].split(":")[0]
     assert "jmongo" in publicIp
     dataCount = mongo_write_data.count_data(publicIp)
     date_time = int(time.time()-360)
     status, resp = MongOpenAPISteps().openapi_create_instance_until_finshed(dbVersion,instanceStorageType,mongOpenAPI, instance=createByTimeId, restoreTime=date_time, flag=False)
     if status != 200 or resp["result"]["totalCount"] is None:
         assert False,"resp is [{}]".format(resp)
     assert resp["result"]["dbInstances"][0]["instanceStatus"] == 'RUNNING'
     instance = resp["result"]["dbInstances"][0]["instanceId"]
     time.sleep(20)
     # 给instance开公网
     flag, resp = MongOpenAPISteps().openapi_enable_internet_access_until_finshed(mongOpenAPI, instance)
     # 先查询有无全0白名单,没有则添加全0白名单
     ret_status, res = mongOpenAPI.openapi_query_securityIps_cap(instance)
     assert ret_status == 200, "{}".format(res)
     if "0.0.0.0/0"  not in res["result"]["securityIps"]:
         status0, resp0 = mongOpenAPI.openapi_securityIps_cap(instance, "Add", ip="0.0.0.0/0")
         if status0 != 200 or "error" in resp0.keys():
             assert False, "[ERROR] modify_securityIps return {}".format(resp0)
     time.sleep(60)
     assert flag
     publicIp = resp["instancePublicDomain"].split(",")[0].split(":")[0]
     assert "jmongo" in publicIp
     newDataCount = mongo_write_data.count_data(publicIp)
     assert dataCount==newDataCount,"create mongo by time ,restore data error"
     flag = MongOpenAPISteps().openapi_delete_instance_until_finshed(mongOpenAPI, instance)
     assert flag
     info_logger.info("test_openapi_create_by_time_instance_until_finshed success")
    def test_openapi_describe_and_delete_sharding_backup(self, openAPIBackup, openAPI_createShardingMongodb):
        status, resp = openAPIBackup.openAPI_describeBackups_cap(openAPI_createShardingMongodb["instanceId"])
        if "error" in resp.keys():
            assert False, "[WAN] Interface return exception"
        assert resp["requestId"]
        if resp["result"]["totalCount"] == 0:
            info_logger.info("test_openapi_describe_backup_lists query is empty")
        else:
            assert resp["result"]["pageNumber"]
            assert len(resp["result"]["backups"][0]) == 9, "[ERROR] Field return element wrong"
            assert resp["result"]["backups"][0]["backupId"]
            assert resp["result"]["backups"][0]["backupName"]
            assert resp["result"]["backups"][0]["backupStatus"]
            info_logger.info("test_openapi_query_backup_lists success")

        status, resp = openAPIBackup.openAPI_describeBackups_cap(openAPI_createShardingMongodb["configserver"][0]["configserverNodeId"])
        if "error" in resp.keys():
            assert False, "[WAN] Interface return exception"
        assert resp["requestId"]
        if resp["result"]["totalCount"] == 0:
            info_logger.info("test_openapi_describe_backup_lists query is empty")
        else:
            assert resp["result"]["pageNumber"]
            assert len(resp["result"]["backups"][0]) == 9, "[ERROR] Field return element wrong"
            assert resp["result"]["backups"][0]["backupId"]
            assert resp["result"]["backups"][0]["backupName"]
            assert resp["result"]["backups"][0]["instanceId"] == openAPI_createShardingMongodb["configserver"][0]["configserverNodeId"]
            assert resp["result"]["backups"][0]["backupStatus"]
            info_logger.info("test_openapi_query_backup_lists success")
            flag = MongOpenAPISteps().openapi_delete_backup_until_finshed(openAPIBackup,
                                                                          resp["result"]["backups"][0]["backupId"])
            assert flag

        status, resp = openAPIBackup.openAPI_describeBackups_cap(
            openAPI_createShardingMongodb["shard"][0]["shardNodeId"])
        if "error" in resp.keys():
            assert False, "[WAN] Interface return exception"
        assert resp["requestId"]
        if resp["result"]["totalCount"] == 0:
            info_logger.info("test_openapi_describe_backup_lists query is empty")
        else:
            assert resp["result"]["pageNumber"]
            assert len(resp["result"]["backups"][0]) == 9, "[ERROR] Field return element wrong"
            assert resp["result"]["backups"][0]["backupId"]
            assert resp["result"]["backups"][0]["backupName"]
            assert resp["result"]["backups"][0]["instanceId"] == openAPI_createShardingMongodb["shard"][0]["shardNodeId"]
            assert resp["result"]["backups"][0]["backupStatus"]
            info_logger.info("test_openapi_query_backup_lists success")
            flag = MongOpenAPISteps().openapi_delete_backup_until_finshed(openAPIBackup,
                                                                          resp["result"]["backups"][0]["backupId"])
            assert flag
 def test_openapi_create_by_time_instance_exception_parametr(self, dbVersion,instanceStorageType,mongOpenAPI,openAPI_createMongoDb, date_time):
     #异常参数根据时间点创建
     time.sleep(2)
     status, resp = MongOpenAPISteps().openapi_create_instance_until_finshed(dbVersion,instanceStorageType,mongOpenAPI, instance=openAPI_createMongoDb, restoreTime=date_time, flag=False)
     #assert status == 200
     assert resp["error"]["message"]
     assert resp["error"]["status"] == 'INVALID_ARGUMENT'
     assert int(resp["error"]["code"]) == 400
     info_logger.info("test_openapi_create_by_time_instance_exception_parametr time:{} success".format(time))
Ejemplo n.º 5
0
 def test_openapi_create_instance_delete_success(self, mongOpenAPI, openAPIBackup, multiAZ, azId, dataCenter, flag):
     pin = mongOpenAPI.data_obj['create_mongoDb_instance']['x-jcloud-pin']
     region = mongOpenAPI.data_obj['create_mongoDb_instance']['dataCenter']
     azFlag = mongOpenAPI.data_obj['create_mongoDb_instance']['azFlag']
     if region != dataCenter or azFlag != flag:
         return
     instanceId = mongOpenAPI.instanceIds[pin]
     flag = MongOpenAPISteps().openapi_delete_instance_until_finshed(mongOpenAPI, instanceId)
     assert flag
     info_logger.info("test_openapi_create_instance_bytime_success delete instance success, instanceId is {}".format(instanceId))
 def test_openapi_create_instance_by_backup_until_finished(self, dbVersion,instanceStorageType,mongOpenAPI,createByTimeId,openAPIBackup):
     #根据备份创建实例,事前创建好实例,写入数据,要求固定的db及collection,admin.test_coll,并且开公网,
     time.sleep(10)
     # backupId,dataCount = openAPI_backupId
     # assert backupId is not None
     # 获取备份文件
     status, resp = openAPIBackup.openAPI_describeBackups_cap(instanceId=createByTimeId)
     assert resp["result"]["totalCount"]>0,"get backup list failed"
     backupId=""
     for i in range(len(resp["result"]["backups"])):
         if resp["result"]["backups"][i]["backupStatus"]=="Finished":
             backupId=resp["result"]["backups"][i]["backupId"]
             break
     assert "mongo" in backupId,"{}".format(resp)
     # 获取源实例公网
     publicIp = mongOpenAPI.openapi_describe_instance_attribute_cap(createByTimeId)["instancePublicDomain"].split(",")[0].split(":")[0]
     assert "jmongo" in publicIp
     dataCount = mongo_write_data.count_data(publicIp)
     # 根据备份创建实例
     status, resp = MongOpenAPISteps().openapi_create_instance_until_finshed(dbVersion,instanceStorageType,mongOpenAPI,backupId=backupId)
     if status != 200 or resp["result"]["totalCount"] is None:
         assert False
     assert resp["result"]["dbInstances"][0]["instanceStatus"] == 'RUNNING'
     instance = resp["result"]["dbInstances"][0]["instanceId"]
     time.sleep(20)
     # 给instance开公网,查询实例data count
     flag, resp = MongOpenAPISteps().openapi_enable_internet_access_until_finshed(mongOpenAPI, instance)
     assert flag
     publicIp = resp["instancePublicDomain"].split(",")[0].split(":")[0]
     assert "jmongo" in publicIp
     # 先查询有无全0白名单,没有则添加全0白名单
     ret_status, res = mongOpenAPI.openapi_query_securityIps_cap(instance)
     assert ret_status == 200,"{}".format(res)
     if "0.0.0.0/0" not in res["result"]["securityIps"]:
         status0, resp0 = mongOpenAPI.openapi_securityIps_cap(instance, "Add", ip="0.0.0.0/0")
         if status0 != 200 or "error" in resp0.keys():
             assert False, "[ERROR] modify_securityIps return {}".format(resp0)
     time.sleep(60)
     newDataCount = mongo_write_data.count_data(publicIp)
     assert dataCount==newDataCount,"create mongo by backup ,restore data error"
     flag = MongOpenAPISteps().openapi_delete_instance_until_finshed(mongOpenAPI, instance)
     assert flag
     info_logger.info("[test_openapi_create_instance_by_backup_until_finished success,data count is {}]".format(newDataCount))
 def test_openapi_restart_instance_until_finshed(self, mongOpenAPI,
                                                 openAPI_createMongoDb):
     time.sleep(10)
     status, instance_status = MongOpenAPISteps(
     ).openapi_restartInstance_until_finshed(mongOpenAPI,
                                             openAPI_createMongoDb)
     assert status == 200
     if instance_status == 'ERROR':
         assert False, "test_openapi_restart_instance_until_finshed Failed"
     assert instance_status == 'RUNNING'
     info_logger.info("test_openapi_restart_instance_until_finshed success")
Ejemplo n.º 8
0
 def test_openapi_create_instance_backup_fail(self, mongOpenAPI, openAPIBackup, multiAZ, azId, dataCenter, flag):
     pin = mongOpenAPI.data_obj['create_mongoDb_instance']['x-jcloud-pin']
     region = mongOpenAPI.data_obj['create_mongoDb_instance']['dataCenter']
     azFlag = mongOpenAPI.data_obj['create_mongoDb_instance']['azFlag']
     if region != dataCenter or azFlag != flag:
         return
     instanceId = mongOpenAPI.instanceIds[pin]
     #创建备份
     if not mongOpenAPI.backupId:
         backupId = MongOpenAPISteps().openapi_create_backup_until_finshed(openAPIBackup=openAPIBackup, instance=instanceId)
         mongOpenAPI.backupId = backupId
     time.sleep(1)
     info_logger.info("test_openapi_create_instance_backup_fail success")
     ret_code, ret_resp = MongOpenAPISteps().openapi_create_instance_3az_until_finshed(mongOpenAPI=mongOpenAPI,
                                                                                   multiAZ=multiAZ,
                                                                                   azId=azId.split(","),
                                                                                   backupId=mongOpenAPI.backupId,
                                                                                   instanceId='',
                                                                                   restoreTime='')
     if ret_code != 200 or 'error' in ret_resp.keys():
         info_logger.info("test_openapi_create_instance_backup_fail success")
    def test_openapi_create_and_view_sharding_backup(self, openAPIBackup, openAPI_createShardingMongodb):
        # 创建逻辑备份
        backupId = MongOpenAPISteps().openapi_create_backup_until_finshed(openAPIBackup, openAPI_createShardingMongodb["instanceId"], "Logical")
        if backupId is None:
            assert False
        # 查询逻辑备份的备份下载链接
        time.sleep(5)
        status, resp = openAPIBackup.openAPI_downloadURL_cap(backupId)
        assert status == 200
        if "error" in resp.keys():
            assert False, "[ERROR] Interface return failed:{}".format(resp)
        assert resp["requestId"]
        assert len(resp["result"]["backupDownloadURL"]) == 4

        # 创建物理备份
        backupId = MongOpenAPISteps().openapi_create_backup_until_finshed(openAPIBackup,
                                                                          openAPI_createShardingMongodb["instanceId"],
                                                                          "Physical")
        if backupId is None:
            assert False
        # 查询物理备份的备份下载链接
        time.sleep(5)
        status, resp = openAPIBackup.openAPI_downloadURL_cap(backupId)
        assert status == 200
        if "error" in resp.keys():
            assert False, "[ERROR] Interface return failed:{}".format(resp)
        assert resp["requestId"]
        assert len(resp["result"]["backupDownloadURL"]) == 4

        # 不存在的实例创建失败
        status, resp = openAPIBackup.openAPI_createBackup_cap(instacneId="mongo-xx", backupMethod="Physical")
        assert status >= 400

        # 备份ID不存在,查询备份下载链接失败
        status, resp = openAPIBackup.openAPI_downloadURL_cap("xxx")
        assert status >= 400
Ejemplo n.º 10
0
 def test_openapi_create_mongodb_month_until_finished(
         self, dbVersion, instanceStorageType, mongOpenAPI):
     #创建包年包月资源
     status, resp = MongOpenAPISteps(
     ).openapi_create_instance_until_finshed(dbVersion,
                                             instanceStorageType,
                                             mongOpenAPI=mongOpenAPI,
                                             mode='prepaid_by_duration')
     assert status == 200
     time.sleep(10)
     if status != 200 or resp["result"]["totalCount"] is None:
         assert False
     assert resp["result"]["dbInstances"][0]["instanceStatus"] == 'RUNNING'
     global instanceId
     instanceId = resp["result"]["dbInstances"][0]["instanceId"]
     info_logger.info(
         "test_openapi_create_mongodb_month_until_finished success")
    def test_openapi_by_instacne_public_domain_query_mongodb_lists(
            self, mongOpenAPI, openAPI_createMongoDb):
        # 按实例公网域名查询
        time.sleep(5)
        instanceId = openAPI_createMongoDb
        flag, resp = MongOpenAPISteps(
        ).openapi_enable_internet_access_until_finshed(mongOpenAPI, instanceId)
        assert flag
        assert resp["instancePublicDomain"] is not None and resp[
            "instancePublicDomain"] != ''

        status, resp0 = mongOpenAPI.openAPI_queryFilters_cap(
            publicDomain="{0}1".format(instanceId))
        utils.api_util.check_response(resp0)
        pytest.assume(
            resp0["result"]["dbInstances"][0]["instanceId"]
            or resp0["result"]["dbInstances"][0]["instanceId"] != instanceId)
        pytest.assume(
            resp0["result"]["dbInstances"][0]["instancePublicDomain"] or
            resp0["result"]["dbInstances"][0]["instancePublicDomain"] is None)
Ejemplo n.º 12
0
 def test_openapi_modify_mongodb_instancespec_month_until_finished(
         self,
         mongOpenAPI,
         instanceClass='mongo.s1.medium',
         instanceStorageGB=20):
     time.sleep(3)
     #升配2核4GB、disk=20G(包年包月)
     status, resp = MongOpenAPISteps(
     ).openapi_modifyMongoDBInstanceSpec_until_finshed(
         mongOpenAPI, instanceId, instanceClass, instanceStorageGB)
     assert status == 200 or 'error' not in resp.keys()
     if resp["result"]["totalCount"] is None:
         assert False
     elif resp["result"]["dbInstances"][0]["instanceStatus"] == 'ERROR':
         assert False, "test_openapi_modify_mongodb_instancespec_month_until_finished failed"
     assert resp["result"]["dbInstances"][0]["instanceId"] == instanceId
     assert resp["result"]["dbInstances"][0]["engine"] == 'MongoDB'
     assert resp["result"]["dbInstances"][0]["instanceStatus"] == 'RUNNING'
     info_logger.info(
         "test_openapi_modify_mongodb_instancespec_month_until_finished success"
     )
Ejemplo n.º 13
0
 def test_openapi_create_instance_success(self, mongOpenAPI, multiAZ, azId, dataCenter, flag):
     pin = mongOpenAPI.data_obj['create_mongoDb_instance']['x-jcloud-pin']
     region = mongOpenAPI.data_obj['create_mongoDb_instance']['dataCenter']
     azFlag = mongOpenAPI.data_obj['create_mongoDb_instance']['azFlag']
     if region != dataCenter or azFlag != flag:
         return
     ret_code, ret_resp = MongOpenAPISteps().openapi_create_instance_3az_until_finshed(mongOpenAPI=mongOpenAPI,
                                                                                           multiAZ=multiAZ,
                                                                                           azId=azId.split(","),
                                                                                           backupId='',
                                                                                           instanceId='',
                                                                                           restoreTime='')
     assert ret_resp["result"]["dbInstances"][0]["instanceId"]
     instanceId = ret_resp["result"]["dbInstances"][0]["instanceId"]
     info_logger.info("test_openapi_create_instance_success success, instanceId is {}".format(instanceId))
     if hasattr(mongOpenAPI, 'instanceIds'):
         mongOpenAPI.instanceIds.update({pin: instanceId})
     else:
         mongOpenAPI.backupId = {}
         mongOpenAPI.instanceIds = {}
         mongOpenAPI.instanceIds.update({pin: instanceId})
     info_logger.info("test_openapi_create_instance_success success")
 def test_openapi_create_backup_normal_parameter(self, openAPIBackup, mongOpenAPI, openAPI_createMongoDb):
     # backupId = MongOpenAPISteps().openapi_create_backup_until_finshed(openAPIBackup, openAPI_createMongoDb,
     #                                                                   backupMethod='Logical')
     # if backupId is None:
     #     assert False
     # status, resp = openAPIBackup.openAPI_describeBackups_cap(backupId=backupId)
     # assert status == 200
     # assert resp["result"]["backups"][0]["backupMethod"] == 'Logical'
     # info_logger.info("test_openapi_create_backup_normal_parameter Logical {} success".format(backupId))
     time.sleep(420)#刚创建的实例,会触发自动备份,备份用时候5分钟,所在再次备份需要sleep5分钟,这个没有sleep是因为执行前面case的时候超过了5分钟所以没sleep,如果前面case失败,5分钟内就执行到此case,此case会失败,因为备份失败。
     backupMethod = 'Logical'
     backupId = MongOpenAPISteps().openapi_create_backup_until_finshed(openAPIBackup, openAPI_createMongoDb,
                                                                       backupMethod=backupMethod)
     if backupId is None:
         assert False
     status, resp = openAPIBackup.openAPI_describeBackups_cap(backupId=backupId)
     assert status == 200
     instance = mongOpenAPI.openapi_describe_instance_attribute_cap(openAPI_createMongoDb)
     if instance["instanceStorageType"] == "EBS_SSD":
         assert resp["result"]["backups"][0]["backupMethod"] == 'Logical'
     else:
         assert resp["result"]["backups"][0]["backupMethod"] == backupMethod
     info_logger.info("test_openapi_create_backup_normal_parameter Physical {} success".format(backupId))
 def test_openapi_delete_backup_util_finished(self, openAPIBackup, openAPI_backupId):
     #备份删除
     time.sleep(10)
     flag = MongOpenAPISteps().openapi_delete_backup_until_finshed(openAPIBackup, openAPI_backupId)
     assert flag
     info_logger.info("[INFO] test_openapi_delete_backup_util_finished success")
Ejemplo n.º 16
0
    def test_openapi_mongodb_promotion_until_finshed(self, mongOpenAPI,
                                                     openAPI_createMongoDb,
                                                     flag, instanceClass,
                                                     instanceStorageGB,
                                                     instance_data):
        if instance_data[
                "resize_write_data_flag"] == 1:  #resize_write_data_flag是在配置文件里读出来的,1是边变配边打数据,用于线上环境
            # 获取公网
            spaceInfo = mongOpenAPI.openapi_describe_instance_attribute_cap(
                openAPI_createMongoDb)
            publicIp = spaceInfo["instancePublicDomain"]
            domain = spaceInfo["instanceDomain"]
            replicaSetName = spaceInfo["replicaSetName"]
            # 如果没有公网,开启
            if publicIp is None or publicIp == "":
                publicFlag, resp = MongOpenAPISteps(
                ).openapi_enable_internet_access_until_finshed(
                    mongOpenAPI, openAPI_createMongoDb)
                # publicFlag, resp = MongOpenAPISteps().openapi_enable_internet_access_until_finshed(mongOpenAPI, openAPI_createMongoDb)
                time.sleep(60)
                assert publicFlag
                publicIp = resp["instancePublicDomain"]
                assert "jmongo" in publicIp

            # 添加全0白名单
            status0, resp0 = mongOpenAPI.openapi_securityIps_cap(
                openAPI_createMongoDb, "Add", ip="0.0.0.0/0")

            # resize
            t1 = threading.Thread(target=MongOpenAPISteps(
            ).openapi_modifyMongoDBInstanceSpec_until_finshed,
                                  args=(mongOpenAPI, openAPI_createMongoDb,
                                        instanceClass, instanceStorageGB))
            # write data
            mongo_write_data.drop_collection(
                publicIp.split(',')[0].split(":")[0])
            t2 = threading.Thread(
                target=utils.mongo_write_data.write_data_ssh_thread,
                args=(domain, replicaSetName, instance_data))
            t1.start()
            t2.start()
            t1.join()
            # 变配结束后,设置写数据线程结束
            utils.ssh_and_cmd.write_thread_flag = False

            new_data_count = mongo_write_data.count_data(
                publicIp.split(',')[0].split(":")[0])
            assert new_data_count == utils.ssh_and_cmd.write_data_count, "new_data_count is [{}],old_data_count is [{}]".format(
                new_data_count, utils.ssh_and_cmd.write_data_count)
            info_logger.info(
                "mongodb promotion success,data correct [{}]".format(
                    new_data_count))
        else:  #resize_write_data_flag不等于1的时候,只变配,不写数据
            time.sleep(30)
            status, resp = MongOpenAPISteps(
            ).openapi_modifyMongoDBInstanceSpec_until_finshed(
                mongOpenAPI, openAPI_createMongoDb, instanceClass,
                instanceStorageGB)
            if flag != 3:
                assert status == 200
            else:
                assert status == 500
            # assert status == 200
            if 'error' not in resp.keys():
                if len(resp["result"]["dbInstances"]) == 0:
                    assert False, "openapi_modifyMongoDBInstanceSpec_until_finshed interface exception"
                if resp["result"]["dbInstances"][0][
                        "instanceStatus"] == 'ERROR':
                    assert False, "test_openapi_mongodb_promotion_until_finshed Failed"

                assert resp["result"]["dbInstances"][0][
                    "instanceStatus"] == 'RUNNING'
                assert resp["result"]["dbInstances"][0][
                    "instanceClass"] == instanceClass
                assert resp["result"]["dbInstances"][0][
                    "instanceStorageGB"] == instanceStorageGB
                info_logger.info(
                    "test_openapi_mongodb_promotion_until_finshedinstanceClass:{0},instanceStorageGB:{1} success"
                    .format(instanceClass, instanceStorageGB))
            else:
                assert resp["error"]["message"] in 'flavor is same.'
                assert resp["error"]["status"] == 'INTERNAL'
                assert int(resp["error"]["code"]) == 500
                info_logger.info(
                    "test_openapi_mongodb_promotion_until_finshedinstanceClass:{0},instanceStorageGB:{1} flavor is same Failed"
                    .format(instanceClass, instanceStorageGB))