コード例 #1
0
def test_guest_start_unload():
    device_id = "AC35EE26450B"
    url = TD.url85() + '/guest/start_unload'
    body = {"device_id": device_id}

    mqtt.req83(ename="DEVICE_ID", etype="text", evalue=device_id)

    with allure.step("Начало выгрузки"):
        r = requests.post(TD.url85().guest.start.unload.perf(),
                          json=body,
                          headers=TD.headers())

    LOGGER.debug(r.json())
    LOGGER.debug(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)

    with allure.step('Validate schema'):
        pass
コード例 #2
0
def test_guest_accept_unload():
    device_id = "AC35EE26450B"

    mqtt.req83(ename="DEVICE_ID", etype="text", evalue=device_id)
    mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
    mqtt.req83(ename="RFID_2", etype="text", evalue="777")
    mqtt.req83(ename="bunker_level", etype="value", evalue="81")

    req = Post(TD.url83()).host.search.start_unload.perf()
    LOGGER.debug(r'\n*** host.search.start_unload :: ' + str(req.json()))

    mqtt.req83(ename="unloader_bypass", etype="switch", evalue="1")
    req = Get(TD.url83()).get.status.perf()
    LOGGER.debug(r'\n*** get.status ::' +
                 str(req.json()))  # state=-3, bypass=True

    req = Post(TD.url85()).guest.accept_unload.body(device_id=device_id).perf()
    mqtt.req85(ename="RFID_2", etype="text", evalue="777")
    LOGGER.debug(r'\n*** guest.accept_unload ::' + str(req.json()))
コード例 #3
0
def handler(event, context):
    evt_lst = json.loads(event)
    creds = context.credentials
    auth = oss2.StsAuth(creds.access_key_id, creds.access_key_secret,
                        creds.security_token)

    evt = evt_lst['events'][0]
    bucket_name = evt['oss']['bucket']['name']
    # local debug
    # endpoint = 'oss-' + evt['region'] + '.aliyuncs.com'
    endpoint = 'oss-' + evt['region'] + '-internal.aliyuncs.com'
    bucket = oss2.Bucket(auth, endpoint, bucket_name)
    object_name = evt['oss']['object']['key']

    if "ObjectCreated:PutSymlink" == evt['eventName']:
        object_name = bucket.get_symlink(object_name).target_key
    if object_name == "":
        raise RuntimeError('{} is invalid symlink file'.format(
            evt['oss']['object']['key']))

    lst = object_name.split("/")
    file_name = lst[-1]
    PROCESSED_DIR = os.environ.get("PROCESSED_DIR", "")
    if PROCESSED_DIR and PROCESSED_DIR[-1] != "/":
        PROCESSED_DIR += "/"
    newKey = PROCESSED_DIR + file_name
    open_mode = "r"
    if object_name.endswith(".tar.gz"):
        open_mode = "r:gz"
        newKey = newKey.replace(".tar.gz", "/")

    elif object_name.endswith(".tgz"):
        open_mode = "r:gz"
        newKey = newKey.replace(".tgz", "/")

    elif object_name.endswith(".tar.bz2"):
        open_mode = "r:bz2"
        newKey = newKey.replace(".tar.bz2", "/")

    elif object_name.endswith(".tar.xz"):
        open_mode = "r:xz"
        newKey = newKey.replace(".tar.xz", "/")

    elif object_name.endswith(".tar"):
        open_mode = "r:"
        newKey = newKey.replace(".tar", "/")

    else:
        raise RuntimeError(
            '{} filetype is not in  [".tar.gz", ".tgz", ".tar.bz2", ".tar.xz", ".tar"]'
            .format(object_name))

    LOGGER.info("start to decompress tar file = {}".format(object_name))

    oss_file_obj = OssStreamFileLikeObject(bucket, object_name)
    with tarfile.open(fileobj=oss_file_obj, mode=open_mode) as tf:
        for entry in tf.getmembers():
            if not entry.isfile():
                continue
            LOGGER.debug("extract {} ...".format(entry.name))
            file_obj = tf.extractfile(entry)
            bucket.put_object(newKey + entry.name, file_obj)