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

@ -19,7 +19,7 @@ def generate_file(size: int = SIMPLE_OBJ_SIZE) -> str:
Returns: Returns:
The path to the generated file. The path to the generated file.
""" """
file_path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
with open(file_path, "wb") as file: with open(file_path, "wb") as file:
file.write(os.urandom(size)) file.write(os.urandom(size))
logger.info(f"File with size {size} bytes has been generated: {file_path}") logger.info(f"File with size {size} bytes has been generated: {file_path}")
@ -48,7 +48,7 @@ def generate_file_with_content(
mode = "wb" mode = "wb"
if not file_path: if not file_path:
file_path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
else: else:
if not os.path.exists(os.path.dirname(file_path)): if not os.path.exists(os.path.dirname(file_path)):
os.makedirs(os.path.dirname(file_path)) os.makedirs(os.path.dirname(file_path))
@ -91,7 +91,7 @@ def concat_files(file_paths: list, resulting_file_path: Optional[str] = None) ->
Path to the resulting file. Path to the resulting file.
""" """
if not resulting_file_path: if not resulting_file_path:
resulting_file_path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" resulting_file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
with open(resulting_file_path, "wb") as f: with open(resulting_file_path, "wb") as f:
for file in file_paths: for file in file_paths:
with open(file, "rb") as part_file: with open(file, "rb") as part_file:

View file

@ -255,7 +255,7 @@ class AwsCliClient:
return self._to_json(output) return self._to_json(output)
def delete_objects(self, Bucket: str, Delete: dict) -> dict: def delete_objects(self, Bucket: str, Delete: dict) -> dict:
file_path = f"{os.getcwd()}/{ASSETS_DIR}/delete.json" file_path = os.path.join(os.getcwd(), ASSETS_DIR, "delete.json")
with open(file_path, "w") as out_file: with open(file_path, "w") as out_file:
out_file.write(json.dumps(Delete)) out_file.write(json.dumps(Delete))
logger.info(f"Input file for delete-objects: {json.dumps(Delete)}") logger.info(f"Input file for delete-objects: {json.dumps(Delete)}")
@ -448,7 +448,7 @@ class AwsCliClient:
def complete_multipart_upload( def complete_multipart_upload(
self, Bucket: str, Key: str, UploadId: str, MultipartUpload: dict self, Bucket: str, Key: str, UploadId: str, MultipartUpload: dict
) -> dict: ) -> dict:
file_path = f"{os.getcwd()}/{ASSETS_DIR}/parts.json" file_path = os.path.join(os.getcwd(), ASSETS_DIR, "parts.json")
with open(file_path, "w") as out_file: with open(file_path, "w") as out_file:
out_file.write(json.dumps(MultipartUpload)) out_file.write(json.dumps(MultipartUpload))
logger.info(f"Input file for complete-multipart-upload: {json.dumps(MultipartUpload)}") logger.info(f"Input file for complete-multipart-upload: {json.dumps(MultipartUpload)}")

View file

@ -1,5 +1,3 @@
#!/usr/bin/python3.9
import logging import logging
import os import os
import uuid import uuid
@ -243,7 +241,7 @@ def get_object_acl_s3(
def copy_object_s3( def copy_object_s3(
s3_client, bucket: str, object_key: str, bucket_dst: Optional[str] = None, **kwargs s3_client, bucket: str, object_key: str, bucket_dst: Optional[str] = None, **kwargs
) -> str: ) -> str:
filename = f"{os.getcwd()}/{uuid.uuid4()}" filename = os.path.join(os.getcwd(), str(uuid.uuid4()))
try: try:
params = { params = {
"Bucket": bucket_dst or bucket, "Bucket": bucket_dst or bucket,
@ -280,7 +278,7 @@ def get_object_s3(
range: Optional[list] = None, range: Optional[list] = None,
full_output: bool = False, full_output: bool = False,
): ):
filename = f"{ASSETS_DIR}/{uuid.uuid4()}" filename = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
try: try:
params = {"Bucket": bucket, "Key": object_key} params = {"Bucket": bucket, "Key": object_key}
if version_id: if version_id:

View file

@ -70,7 +70,7 @@ def check_binary_versions(request, hosting: Hosting, client_shell: Shell):
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@allure.title("Prepare tmp directory") @allure.title("Prepare tmp directory")
def prepare_tmp_dir(): def prepare_tmp_dir():
full_path = f"{os.getcwd()}/{ASSETS_DIR}" full_path = os.path.join(os.getcwd(), ASSETS_DIR)
shutil.rmtree(full_path, ignore_errors=True) shutil.rmtree(full_path, ignore_errors=True)
os.mkdir(full_path) os.mkdir(full_path)
yield full_path yield full_path

View file

@ -169,8 +169,8 @@ class TestS3Gate(TestS3GateBase):
""" """
Test checks sync directory with AWS CLI utility. Test checks sync directory with AWS CLI utility.
""" """
file_path_1 = f"{os.getcwd()}/{ASSETS_DIR}/test_sync/test_file_1" file_path_1 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_1")
file_path_2 = f"{os.getcwd()}/{ASSETS_DIR}/test_sync/test_file_2" file_path_2 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_2")
key_to_path = {"test_file_1": file_path_1, "test_file_2": file_path_2} key_to_path = {"test_file_1": file_path_1, "test_file_2": file_path_2}
if not isinstance(self.s3_client, AwsCliClient): if not isinstance(self.s3_client, AwsCliClient):

View file

@ -852,8 +852,8 @@ class TestS3GateObject(TestS3GateBase):
@allure.title("Test S3 Sync directory") @allure.title("Test S3 Sync directory")
@pytest.mark.parametrize("sync_type", ["sync", "cp"]) @pytest.mark.parametrize("sync_type", ["sync", "cp"])
def test_s3_sync_dir(self, sync_type): def test_s3_sync_dir(self, sync_type):
file_path_1 = f"{os.getcwd()}/{ASSETS_DIR}/test_sync/test_file_1" file_path_1 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_1")
file_path_2 = f"{os.getcwd()}/{ASSETS_DIR}/test_sync/test_file_2" file_path_2 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_2")
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"} object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
key_to_path = {"test_file_1": file_path_1, "test_file_2": file_path_2} key_to_path = {"test_file_1": file_path_1, "test_file_2": file_path_2}

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: 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 = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
cli.acl.extended_create(cid=cid, out=table_file_path, rule=rules_list) 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 with bearer token and writes to file
""" """
enc_cid = _encode_cid_for_eacl(cid) 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) eacl = get_eacl(wif, cid, shell=shell)
json_eacl = dict() json_eacl = dict()

View file

@ -1,5 +1,3 @@
#!/usr/bin/python3
import logging import logging
import os import os
import re import re
@ -39,10 +37,10 @@ def get_via_http_gate(cid: str, oid: str):
logger.info(f"Request: {request}") logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code) _attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_{oid}" file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}")
with open(filename, "wb") as get_file: with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, get_file) shutil.copyfileobj(resp.raw, file)
return filename return file_path
@allure.step("Get via Zip HTTP Gate") @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}") logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code) _attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_archive.zip" file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_archive.zip")
with open(filename, "wb") as get_file: with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, get_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) 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") @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}") logger.info(f"Request: {request}")
_attach_allure_step(request, resp.status_code) _attach_allure_step(request, resp.status_code)
filename = f"{ASSETS_DIR}/{cid}_{str(uuid.uuid4())}" file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{str(uuid.uuid4())}")
with open(filename, "wb") as get_file: with open(file_path, "wb") as file:
shutil.copyfileobj(resp.raw, get_file) shutil.copyfileobj(resp.raw, file)
return filename return file_path
@allure.step("Upload via HTTP Gate") @allure.step("Upload via HTTP Gate")
@ -165,12 +163,12 @@ def get_via_http_curl(cid: str, oid: str) -> str:
:param oid: object OID :param oid: object OID
""" """
request = f"{HTTP_GATE}/get/{cid}/{oid}" request = f"{HTTP_GATE}/get/{cid}/{oid}"
filename = f"{ASSETS_DIR}/{cid}_{oid}_{str(uuid.uuid4())}" file_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}_{str(uuid.uuid4())}")
cmd = f"curl {request} > {filename}"
cmd = f"curl {request} > {file_path}"
_cmd_run(cmd) _cmd_run(cmd)
return filename return file_path
def _attach_allure_step(request: str, status_code: int, req_type="GET"): 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 json
import logging import logging
import os
import random import random
import re import re
import uuid import uuid
@ -55,7 +50,7 @@ def get_object(
if not write_object: if not write_object:
write_object = str(uuid.uuid4()) write_object = str(uuid.uuid4())
file_path = f"{ASSETS_DIR}/{write_object}" file_path = os.path.join(ASSETS_DIR, write_object)
if not endpoint: if not endpoint:
endpoint = random.sample(NEOFS_NETMAP, 1)[0] endpoint = random.sample(NEOFS_NETMAP, 1)[0]
@ -254,7 +249,7 @@ def get_range(
Returns: Returns:
(str, bytes) - path to the file with range content and content of this file as bytes (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 = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
cli.object.range( cli.object.range(
@ -263,15 +258,15 @@ def get_range(
cid=cid, cid=cid,
oid=oid, oid=oid,
range=range_cut, range=range_cut,
file=range_file, file=range_file_path,
bearer=bearer, bearer=bearer,
xhdr=xhdr, xhdr=xhdr,
session=session, session=session,
) )
with open(range_file, "rb") as fout: with open(range_file_path, "rb") as file:
content = fout.read() content = file.read()
return range_file, content return range_file_path, content
@allure.step("Search object") @allure.step("Search object")

View file

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