Fix code that constructs paths

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
Vladimir Domnich 2022-10-18 11:11:57 +04:00 committed by Vladimir
parent 7fcbdb6c34
commit 3de4d574d3
10 changed files with 40 additions and 49 deletions

View file

@ -148,7 +148,7 @@ def _encode_cid_for_eacl(cid: str) -> str:
def create_eacl(cid: str, rules_list: List[EACLRule], shell: Shell) -> str:
table_file_path = f"{os.getcwd()}/{ASSETS_DIR}/eacl_table_{str(uuid.uuid4())}.json"
table_file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"eacl_table_{str(uuid.uuid4())}.json")
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
cli.acl.extended_create(cid=cid, out=table_file_path, rule=rules_list)
@ -168,7 +168,7 @@ def form_bearertoken_file(
with bearer token and writes to file
"""
enc_cid = _encode_cid_for_eacl(cid)
file_path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}"
file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
eacl = get_eacl(wif, cid, shell=shell)
json_eacl = dict()

View file

@ -1,5 +1,3 @@
#!/usr/bin/python3
import logging
import os
import re
@ -39,10 +37,10 @@ def get_via_http_gate(cid: str, oid: str):
logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_{oid}"
with open(filename, "wb") as get_file:
shutil.copyfileobj(resp.raw, get_file)
return filename
file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}")
with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, file)
return file_path
@allure.step("Get via Zip HTTP Gate")
@ -66,14 +64,14 @@ def get_via_zip_http_gate(cid: str, prefix: str):
logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_archive.zip"
with open(filename, "wb") as get_file:
shutil.copyfileobj(resp.raw, get_file)
file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_archive.zip")
with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, file)
with zipfile.ZipFile(filename, "r") as zip_ref:
with zipfile.ZipFile(file_path, "r") as zip_ref:
zip_ref.extractall(ASSETS_DIR)
return f"{ASSETS_DIR}/{prefix}"
return os.path.join(os.getcwd(), ASSETS_DIR, prefix)
@allure.step("Get via HTTP Gate by attribute")
@ -99,10 +97,10 @@ def get_via_http_gate_by_attribute(cid: str, attribute: dict):
logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_{str(uuid.uuid4())}"
with open(filename, "wb") as get_file:
shutil.copyfileobj(resp.raw, get_file)
return filename
file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{str(uuid.uuid4())}")
with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, file)
return file_path
@allure.step("Upload via HTTP Gate")
@ -165,12 +163,12 @@ def get_via_http_curl(cid: str, oid: str) -> str:
:param oid: object OID
"""
request = f"{HTTP_GATE}/get/{cid}/{oid}"
filename = f"{ASSETS_DIR}/{cid}_{oid}_{str(uuid.uuid4())}"
cmd = f"curl {request} > {filename}"
file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}_{str(uuid.uuid4())}")
cmd = f"curl {request} > {file_path}"
_cmd_run(cmd)
return filename
return file_path
def _attach_allure_step(request: str, status_code: int, req_type="GET"):

View file

@ -1,11 +1,6 @@
#!/usr/bin/python3
"""
This module contains wrappers for NeoFS verbs executed via neofs-cli.
"""
import json
import logging
import os
import random
import re
import uuid
@ -55,7 +50,7 @@ def get_object(
if not write_object:
write_object = str(uuid.uuid4())
file_path = f"{ASSETS_DIR}/{write_object}"
file_path = os.path.join(ASSETS_DIR, write_object)
if not endpoint:
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
@ -254,7 +249,7 @@ def get_range(
Returns:
(str, bytes) - path to the file with range content and content of this file as bytes
"""
range_file = f"{ASSETS_DIR}/{uuid.uuid4()}"
range_file_path = os.path.join(ASSETS_DIR, str(uuid.uuid4()))
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
cli.object.range(
@ -263,15 +258,15 @@ def get_range(
cid=cid,
oid=oid,
range=range_cut,
file=range_file,
file=range_file_path,
bearer=bearer,
xhdr=xhdr,
session=session,
)
with open(range_file, "rb") as fout:
content = fout.read()
return range_file, content
with open(range_file_path, "rb") as file:
content = file.read()
return range_file_path, content
@allure.step("Search object")

View file

@ -30,7 +30,7 @@ def generate_session_token(owner: str, session_wallet: str, cid: str = "") -> st
Returns:
(str): the path to the generated session token file
"""
file_path = f"{os.getcwd()}/{ASSETS_DIR}/{uuid.uuid4()}"
file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
session_wlt_content = ""
with open(session_wallet) as fout:
@ -80,7 +80,7 @@ def create_session_token(owner: str, wallet_path: str, rpc: str = NEOFS_ENDPOINT
Returns:
(str): the path to the generated session token file
"""
session_token = f"{os.getcwd()}/{ASSETS_DIR}/{uuid.uuid4()}"
session_token = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = (
f"{NEOFS_CLI_EXEC} session create --address {owner} -w {wallet_path} "
f"--out {session_token} --rpc-endpoint {rpc}"
@ -99,7 +99,7 @@ def sign_session_token(session_token: str, wlt: str):
Returns:
(str): the path to the signed token
"""
signed_token = f"{os.getcwd()}/{ASSETS_DIR}/{uuid.uuid4()}"
signed_token = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = (
f"{NEOFS_CLI_EXEC} util sign session-token --from {session_token} "
f"-w {wlt} --to {signed_token} --config {WALLET_CONFIG}"