2020-11-30 10:33:05 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import requests
|
2020-12-04 12:28:59 +00:00
|
|
|
import shutil
|
2020-11-30 10:33:05 +00:00
|
|
|
|
|
|
|
from robot.api.deco import keyword
|
|
|
|
from robot.api import logger
|
|
|
|
import robot.errors
|
|
|
|
from robot.libraries.BuiltIn import BuiltIn
|
|
|
|
|
|
|
|
|
|
|
|
ROBOT_AUTO_KEYWORDS = False
|
|
|
|
|
|
|
|
if os.getenv('ROBOT_PROFILE') == 'selectel_smoke':
|
|
|
|
from selectelcdn_smoke_vars import (NEOGO_CLI_PREFIX, NEO_MAINNET_ENDPOINT,
|
|
|
|
NEOFS_NEO_API_ENDPOINT, NEOFS_ENDPOINT, HTTP_GATE)
|
|
|
|
else:
|
|
|
|
from neofs_int_vars import (NEOGO_CLI_PREFIX, NEO_MAINNET_ENDPOINT,
|
|
|
|
NEOFS_NEO_API_ENDPOINT, NEOFS_ENDPOINT, HTTP_GATE)
|
|
|
|
|
|
|
|
|
|
|
|
@keyword('Get via HTTP Gate')
|
|
|
|
def get_via_http_gate(cid: str, oid: str):
|
|
|
|
"""
|
|
|
|
This function gets given object from HTTP gate
|
|
|
|
:param cid: CID to get object from
|
|
|
|
:param oid: object OID
|
|
|
|
"""
|
2020-12-04 12:28:59 +00:00
|
|
|
request = f'{HTTP_GATE}/get/{cid}/{oid}'
|
|
|
|
resp = requests.get(request, stream=True)
|
|
|
|
|
2020-11-30 10:33:05 +00:00
|
|
|
if not resp.ok:
|
2020-12-04 12:28:59 +00:00
|
|
|
raise Exception(f"""Failed to get object via HTTP gate:
|
2020-11-30 10:33:05 +00:00
|
|
|
request: {resp.request.path_url},
|
|
|
|
response: {resp.text},
|
|
|
|
status code: {resp.status_code} {resp.reason}""")
|
|
|
|
return
|
|
|
|
|
2020-12-04 12:28:59 +00:00
|
|
|
logger.info(f'Request: {request}')
|
2020-11-30 10:33:05 +00:00
|
|
|
filename = os.path.curdir + f"/{cid}_{oid}"
|
2020-12-04 12:28:59 +00:00
|
|
|
with open(filename, "wb") as f:
|
|
|
|
shutil.copyfileobj(resp.raw, f)
|
|
|
|
del resp
|
2020-12-04 12:34:06 +00:00
|
|
|
return filename
|