Skip to content

Commit

Permalink
tests: fix issue with out of space during logs attachment
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Zayats <[email protected]>
  • Loading branch information
Evgeniy Zayats committed Oct 17, 2024
1 parent 3e0b29e commit 17895ae
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
2 changes: 1 addition & 1 deletion neofs-testlib/neofs_testlib/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def kill(self):
ir.process.kill()

def persist(self) -> str:
persisted_path = self._generate_temp_file(self._env_dir, prefix="persisted_env")
persisted_path = self._generate_temp_file(os.path.dirname(self._env_dir), prefix="persisted_env")
with open(persisted_path, "wb") as fp:
pickle.dump(self, fp)
logger.info(f"Persist env at: {persisted_path}")
Expand Down
3 changes: 1 addition & 2 deletions pytest_tests/lib/helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
NEOFS_CONTRACT = os.getenv("NEOFS_IR_CONTRACTS_NEOFS")

TEST_RUN_DIR = f"test-run-{datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d-%H-%M-%S-%f")}"
ASSETS_DIR = f"TemporaryDir-{datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d-%H-%M-%S-%f")}"
TEST_FILES_DIR = os.getenv("TEST_FILES_DIR", "TestFilesDir")
TEST_OBJECTS_DIR = os.getenv("TEST_OBJECTS_DIR", "TestObjectsDir")
DEVENV_PATH = os.getenv("DEVENV_PATH", os.path.join("..", "neofs-dev-env"))
Expand Down Expand Up @@ -68,4 +67,4 @@


def get_assets_dir_path() -> str:
return os.path.join(os.getcwd(), TEST_RUN_DIR, ASSETS_DIR)
return os.path.join(os.getcwd(), TEST_RUN_DIR)
70 changes: 60 additions & 10 deletions pytest_tests/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,66 @@ def neofs_env(temp_directory, artifacts_directory, request):
if not request.config.getoption("--load-env"):
neofs_env.kill()

if request.session.testsfailed:
env_files_path = os.path.join(os.getcwd(), neofs_env._env_dir)
env_files_archived = shutil.make_archive(
os.path.join(get_assets_dir_path(), f"neofs_env_{neofs_env._id}"), "zip", env_files_path
)
allure.attach.file(env_files_archived, name="neofs env files", extension="zip")
if request.session.testsfailed and not request.config.getoption("--persist-env"):
neofs_env.shell.exec("df -h")
neofs_env.shell.exec("df -h /tmp")
neofs_env.shell.exec("df -i")
neofs_env.shell.exec(f"du -h {neofs_env._env_dir}")
neofs_env.shell.exec(f"ls -lah {neofs_env._env_dir}")

for ir in neofs_env.inner_ring_nodes:
os.remove(ir.ir_storage_path)
for sn in neofs_env.storage_nodes:
for shard in sn.shards:
os.remove(shard.metabase_path)
os.remove(shard.blobovnicza_path)
shutil.rmtree(shard.fstree_path, ignore_errors=True)
os.remove(shard.pilorama_path)
os.remove(shard.wc_path)

temp_files_path = os.path.join(get_assets_dir_path())
temp_files_archived = shutil.make_archive(
os.path.join(get_assets_dir_path(), "temp_files"), "zip", temp_files_path
neofs_env.shell.exec("df -h")
neofs_env.shell.exec("df -i")
neofs_env.shell.exec(f"du -h {neofs_env._env_dir}")
neofs_env.shell.exec(f"ls -lah {neofs_env._env_dir}")

shutil.make_archive(
os.path.join(get_assets_dir_path(), f"neofs_env_{neofs_env._id}"), "zip", neofs_env._env_dir
)
allure.attach.file(temp_files_archived, name="tests temp files", extension="zip")

neofs_env.shell.exec("df -h")
neofs_env.shell.exec("df -i")
neofs_env.shell.exec(f"du -h {neofs_env._env_dir}")
neofs_env.shell.exec(f"ls -lah {neofs_env._env_dir}")
allure.attach.file(os.path.join(get_assets_dir_path(), f"neofs_env_{neofs_env._id}.zip"), name="neofs env files", extension="zip")

# allure.attach.file(neofs_env.inner_ring_nodes[0].stderr, name=os.path.basename(ir.stderr), extension="txt")

# for ir in neofs_env.inner_ring_nodes:
# allure.attach.file(ir.stderr, name=os.path.basename(ir.stderr), extension="txt")
# allure.attach.file(ir.stdout, name=os.path.basename(ir.stdout), extension="txt")

# for sn in neofs_env.storage_nodes:
# allure.attach.file(sn.stderr, name=os.path.basename(sn.stderr), extension="txt")
# allure.attach.file(sn.stdout, name=os.path.basename(sn.stdout), extension="txt")

# allure.attach.file(neofs_env.s3_gw.stderr, name=os.path.basename(neofs_env.s3_gw.stderr), extension="txt")
# allure.attach.file(neofs_env.s3_gw.stdout, name=os.path.basename(neofs_env.s3_gw.stdout), extension="txt")

# allure.attach.file(neofs_env.rest_gw.stderr, name=os.path.basename(neofs_env.rest_gw.stderr), extension="txt")
# allure.attach.file(neofs_env.rest_gw.stdout, name=os.path.basename(neofs_env.rest_gw.stdout), extension="txt")

shutil.rmtree(neofs_env._env_dir, ignore_errors=True)

neofs_env.shell.exec("df -h")
neofs_env.shell.exec(f"du -h {get_assets_dir_path()}")
neofs_env.shell.exec(f"ls -lah {get_assets_dir_path()}")

# temp_files_archived = shutil.make_archive(
# os.path.join(get_assets_dir_path(), "temp_files"), "zip", get_assets_dir_path()
# )
# neofs_env.shell.exec(f"ls -lah {get_assets_dir_path()}")
# neofs_env.shell.exec("df -h")
# allure.attach.file(temp_files_archived, name="tests temp files", extension="zip")


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -249,6 +297,8 @@ def cleanup_temp_files():
def file_system_monitor(neofs_env: NeoFSEnv):
with allure.step("Get fs usage before test"):
neofs_env.shell.exec("df -h")
neofs_env.shell.exec("df -i")
yield
with allure.step("Get fs usage after test"):
neofs_env.shell.exec("df -h")
neofs_env.shell.exec("df -i")
1 change: 1 addition & 0 deletions pytest_tests/tests/failovers/test_failover_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_block_storage_node_traffic(self, default_wallet, simple_object_size, re
"""
Block storage nodes traffic using iptables and wait for replication for objects.
"""
raise AssertionError("Invoke allure attachments")
wallet = default_wallet
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
wakeup_node_timeout = 10 # timeout to let nodes detect that traffic has blocked
Expand Down

0 comments on commit 17895ae

Please sign in to comment.