2022-04-07 18:48:03 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
"""
|
2022-08-26 14:35:59 +00:00
|
|
|
This module contains functions which are used for Large Object assembling:
|
2022-04-07 18:48:03 +00:00
|
|
|
getting Last Object and split and getting Link Object. It is not enough to
|
|
|
|
simply perform a "raw" HEAD request, as noted in the issue:
|
|
|
|
https://github.com/nspcc-dev/neofs-node/issues/1304. Therefore, the reliable
|
2022-08-26 14:35:59 +00:00
|
|
|
retrieval of the aforementioned objects must be done this way: send direct
|
2022-04-07 18:48:03 +00:00
|
|
|
"raw" HEAD request to the every Storage Node and return the desired OID on
|
|
|
|
first non-null response.
|
|
|
|
"""
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import logging
|
2022-10-13 18:53:44 +00:00
|
|
|
from typing import Optional
|
2022-04-07 18:48:03 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-06-09 13:08:11 +00:00
|
|
|
import neofs_verbs
|
2022-09-20 15:03:52 +00:00
|
|
|
from common import NEOFS_NETMAP, WALLET_CONFIG
|
2022-10-13 18:53:44 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
2022-06-09 13:08:11 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-04-07 18:48:03 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Link Object")
|
|
|
|
def get_link_object(
|
2022-10-13 18:53:44 +00:00
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
shell: Shell,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: str = "",
|
2022-10-13 18:53:44 +00:00
|
|
|
wallet_config: str = WALLET_CONFIG,
|
2022-09-20 15:03:52 +00:00
|
|
|
):
|
2022-04-07 18:48:03 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
Args:
|
|
|
|
wallet (str): path to the wallet on whose behalf the Storage Nodes
|
|
|
|
are requested
|
|
|
|
cid (str): Container ID which stores the Large Object
|
|
|
|
oid (str): Large Object ID
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer (optional, str): path to Bearer token file
|
2022-09-20 15:03:52 +00:00
|
|
|
wallet_config (optional, str): path to the neofs-cli config file
|
|
|
|
Returns:
|
|
|
|
(str): Link Object ID
|
|
|
|
When no Link Object ID is found after all Storage Nodes polling,
|
2022-09-23 11:09:41 +00:00
|
|
|
the function throws an error.
|
2022-04-07 18:48:03 +00:00
|
|
|
"""
|
|
|
|
for node in NEOFS_NETMAP:
|
|
|
|
try:
|
2022-09-20 15:03:52 +00:00
|
|
|
resp = neofs_verbs.head_object(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-09-20 15:03:52 +00:00
|
|
|
endpoint=node,
|
|
|
|
is_raw=True,
|
|
|
|
is_direct=True,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-09-20 15:03:52 +00:00
|
|
|
wallet_config=wallet_config,
|
|
|
|
)
|
|
|
|
if resp["link"]:
|
|
|
|
return resp["link"]
|
2022-04-07 18:48:03 +00:00
|
|
|
except Exception:
|
|
|
|
logger.info(f"No Link Object found on {node}; continue")
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.error(f"No Link Object for {cid}/{oid} found among all Storage Nodes")
|
2022-04-07 18:48:03 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Last Object")
|
2022-10-13 18:53:44 +00:00
|
|
|
def get_last_object(wallet: str, cid: str, oid: str, shell: Shell) -> Optional[str]:
|
2022-04-07 18:48:03 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
Args:
|
|
|
|
wallet (str): path to the wallet on whose behalf the Storage Nodes
|
|
|
|
are requested
|
|
|
|
cid (str): Container ID which stores the Large Object
|
|
|
|
oid (str): Large Object ID
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-09-20 15:03:52 +00:00
|
|
|
Returns:
|
|
|
|
(str): Last Object ID
|
|
|
|
When no Last Object ID is found after all Storage Nodes polling,
|
2022-09-23 11:09:41 +00:00
|
|
|
the function throws an error.
|
2022-04-07 18:48:03 +00:00
|
|
|
"""
|
|
|
|
for node in NEOFS_NETMAP:
|
|
|
|
try:
|
2022-09-20 15:03:52 +00:00
|
|
|
resp = neofs_verbs.head_object(
|
2022-10-13 18:53:44 +00:00
|
|
|
wallet, cid, oid, shell=shell, endpoint=node, is_raw=True, is_direct=True
|
2022-09-20 15:03:52 +00:00
|
|
|
)
|
|
|
|
if resp["lastPart"]:
|
|
|
|
return resp["lastPart"]
|
2022-04-07 18:48:03 +00:00
|
|
|
except Exception:
|
|
|
|
logger.info(f"No Last Object found on {node}; continue")
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.error(f"No Last Object for {cid}/{oid} found among all Storage Nodes")
|
2022-04-07 18:48:03 +00:00
|
|
|
return None
|