Skip to content

Commit

Permalink
Adapt http and s3 tests to new dynamic env (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Jan 25, 2024
2 parents 9460496 + b9368d6 commit bc32093
Show file tree
Hide file tree
Showing 22 changed files with 2,813 additions and 43 deletions.
43 changes: 17 additions & 26 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,21 @@ jobs:
file: 'neofs-node-amd64'
target: 'neofs-testcases/neofs-node'

- name: Checkout neofs-s3-gw repository
uses: actions/checkout@v4
- name: Download latest stable neofs-s3-gw
uses: dsaltares/[email protected]
with:
repo: 'nspcc-dev/neofs-s3-gw'
version: 'tags/v0.29.0'
file: 'neofs-s3-gw-linux-amd64'
target: 'neofs-testcases/neofs-s3-gw'

- name: Download latest stable neofs-s3-gw-authmate
uses: dsaltares/[email protected]
with:
repository: nspcc-dev/neofs-s3-gw
ref: '014a5bf493d00b8cce478e2c96c84ad9de8fe617'
path: neofs-s3-gw
repo: 'nspcc-dev/neofs-s3-gw'
version: 'tags/v0.29.0'
file: 'neofs-s3-authmate-linux-amd64'
target: 'neofs-testcases/neofs-s3-authmate'

- name: Download latest stable neofs-rest-gw
uses: dsaltares/[email protected]
Expand Down Expand Up @@ -123,15 +132,10 @@ jobs:
sudo chmod a+x neofs-rest-gw
sudo chmod a+x neofs-http-gw
sudo chmod a+x neo-go
sudo chmod a+x neofs-s3-authmate
sudo chmod a+x neofs-s3-gw
working-directory: neofs-testcases

- name: Set up Go
uses: actions/setup-go@v4
with:
cache: true
go-version: '1.20'
- run: go version

- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -162,24 +166,11 @@ jobs:
sudo python ./tools/src/openssl_config_fix.py
working-directory: neofs-testcases

- name: Build neofs-s3-gw
timeout-minutes: 5
run: |
make all
echo "$(pwd)/bin" >> $GITHUB_PATH
working-directory: neofs-s3-gw

- name: Copy binaries to testcases directory
timeout-minutes: 30
run: |
cp ${GITHUB_WORKSPACE}/neofs-s3-gw/bin/* .
echo "$(pwd)" >> $GITHUB_PATH
working-directory: neofs-testcases

- name: Prepare venv
timeout-minutes: 30
run: |
make venv.no-dev-env-pytest
echo "$(pwd)" >> $GITHUB_PATH
working-directory: neofs-testcases

- name: Log environment
Expand Down
25 changes: 25 additions & 0 deletions dynamic_env_pytest_tests/lib/helpers/storage_object_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dataclasses import dataclass
from typing import Optional


@dataclass
class ObjectRef:
cid: str
oid: str


@dataclass
class LockObjectInfo(ObjectRef):
lifetime: Optional[int] = None
expire_at: Optional[int] = None


@dataclass
class StorageObjectInfo(ObjectRef):
size: Optional[int] = None
wallet_file_path: Optional[str] = None
file_path: Optional[str] = None
file_hash: Optional[str] = None
attributes: Optional[list[dict[str, str]]] = None
tombstone: Optional[str] = None
locks: Optional[list[LockObjectInfo]] = None
78 changes: 78 additions & 0 deletions dynamic_env_pytest_tests/lib/http_gw/http_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import random

import allure
import neofs_verbs
from grpc_responses import OBJECT_NOT_FOUND, error_matches_status
from neofs_testlib.env.env import StorageNode
from neofs_testlib.shell import Shell
from python_keywords.http_gate import assert_hashes_are_equal, get_via_http_gate
from python_keywords.neofs_verbs import get_object


def get_object_and_verify_hashes(
oid: str,
file_name: str,
wallet: str,
cid: str,
shell: Shell,
nodes: list[StorageNode],
endpoint: str,
object_getter=None,
) -> None:
nodes_list = get_nodes_without_object(
wallet=wallet,
cid=cid,
oid=oid,
shell=shell,
nodes=nodes,
)
# for some reason we can face with case when nodes_list is empty due to object resides in all nodes
if nodes_list:
random_node = random.choice(nodes_list)
else:
random_node = random.choice(nodes)

object_getter = object_getter or get_via_http_gate

got_file_path = get_object(
wallet=wallet,
cid=cid,
oid=oid,
shell=shell,
endpoint=random_node.endpoint,
)
got_file_path_http = object_getter(cid=cid, oid=oid, endpoint=endpoint)

assert_hashes_are_equal(file_name, got_file_path, got_file_path_http)


@allure.step("Get Nodes Without Object")
def get_nodes_without_object(
wallet: str, cid: str, oid: str, shell: Shell, nodes: list[StorageNode]
) -> list[StorageNode]:
"""
The function returns list of nodes which do not store
the given object.
Args:
wallet (str): the path to the wallet on whose behalf
we request the nodes
cid (str): ID of the container which store the object
oid (str): object ID
shell: executor for cli command
Returns:
(list): nodes which do not store the object
"""
nodes_list = []
for node in nodes:
try:
res = neofs_verbs.head_object(
wallet, cid, oid, shell=shell, endpoint=node.endpoint, is_direct=True
)
if res is None:
nodes_list.append(node)
except Exception as err:
if error_matches_status(err, OBJECT_NOT_FOUND):
nodes_list.append(node)
else:
raise Exception(f"Got error {err} on head object command") from err
return nodes_list
41 changes: 41 additions & 0 deletions dynamic_env_pytest_tests/lib/s3/s3_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging

import allure
import neofs_verbs
from neofs_testlib.env.env import StorageNode
from neofs_testlib.shell import Shell

logger = logging.getLogger("NeoLogger")


@allure.step("Get Simple Object Copies")
def get_simple_object_copies(
wallet: str, cid: str, oid: str, shell: Shell, nodes: list[StorageNode]
) -> int:
"""
To figure out the number of a simple object copies, only direct
HEAD requests should be made to the every node of the container.
We consider non-empty HEAD response as a stored object copy.
Args:
wallet (str): the path to the wallet on whose behalf the
copies are got
cid (str): ID of the container
oid (str): ID of the Object
shell: executor for cli command
nodes: nodes to search on
Returns:
(int): the number of object copies in the container
"""
copies = 0
for node in nodes:
try:
response = neofs_verbs.head_object(
wallet, cid, oid, shell=shell, endpoint=node.endpoint, is_direct=True
)
if response:
logger.info(f"Found object {oid} on node {node}")
copies += 1
except Exception:
logger.info(f"No {oid} object copy found on {node}, continue")
continue
return copies
4 changes: 2 additions & 2 deletions dynamic_env_pytest_tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[pytest]
log_cli = 1
log_cli_level = debug
log_cli_format = %(asctime)s [%(levelname)4s] %(message)s
log_format = %(asctime)s [%(levelname)4s] %(message)s
log_cli_format = [%(threadName)s] %(asctime)s [%(levelname)4s] %(message)s
log_format = [%(threadName)s] %(asctime)s [%(levelname)4s] %(message)s [%(threadName)s]
log_cli_date_format = %Y-%m-%d %H:%M:%S
log_date_format = %H:%M:%S
markers =
Expand Down
17 changes: 16 additions & 1 deletion dynamic_env_pytest_tests/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import uuid
import time
from typing import Optional

import allure
Expand Down Expand Up @@ -36,8 +37,9 @@ def neofs_env(request):
neofs_env.neofs_adm().morph.set_config(
rpc_endpoint=f"http://{neofs_env.morph_rpc}",
alphabet_wallets=neofs_env.alphabet_wallets_dir,
post_data=f"ContainerFee=0 ContainerAliasFee=0",
post_data=f"ContainerFee=0 ContainerAliasFee=0 MaxObjectSize=524288",
)
time.sleep(30)

yield neofs_env

Expand All @@ -46,6 +48,19 @@ def neofs_env(request):
else:
if not request.config.getoption("--load-env"):
neofs_env.kill()

logs_path = os.path.join(os.getcwd(), ASSETS_DIR, "logs")
os.makedirs(logs_path, exist_ok=True)

shutil.copyfile(neofs_env.s3_gw.stderr, f"{logs_path}/s3_gw_log.txt")
shutil.copyfile(neofs_env.http_gw.stderr, f"{logs_path}/http_gw_log.txt")
for idx, ir in enumerate(neofs_env.inner_ring_nodes):
shutil.copyfile(ir.stderr, f"{logs_path}/ir_{idx}_log.txt")
for idx, sn in enumerate(neofs_env.storage_nodes):
shutil.copyfile(sn.stderr, f"{logs_path}/sn_{idx}_log.txt")

logs_zip_file_path = shutil.make_archive("neofs_logs", "zip", logs_path)
allure.attach.file(logs_zip_file_path, name="neofs logs", extension="zip")


@pytest.fixture(scope="session")
Expand Down
Loading

0 comments on commit bc32093

Please sign in to comment.