From c48248887da3d2842e233da1540b1d56e4e1b239 Mon Sep 17 00:00:00 2001 From: Evgeniy Zayats Date: Sat, 23 Sep 2023 15:46:24 -0400 Subject: [PATCH] tests: replace configobj with dotenv, fixes #568 Signed-off-by: Evgeniy Zayats --- .../testsuites/shard/test_control_shard.py | 24 ++++++++++++------- requirements.txt | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pytest_tests/testsuites/shard/test_control_shard.py b/pytest_tests/testsuites/shard/test_control_shard.py index b669658c6..6ea4ee07b 100644 --- a/pytest_tests/testsuites/shard/test_control_shard.py +++ b/pytest_tests/testsuites/shard/test_control_shard.py @@ -9,7 +9,7 @@ import yaml from cluster import Cluster, StorageNode from common import WALLET_CONFIG -from configobj import ConfigObj +from dotenv import dotenv_values from neofs_testlib.cli import NeofsCli SHARD_PREFIX = "NEOFS_STORAGE_SHARD_" @@ -30,9 +30,9 @@ def __hash__(self): return hash((self.path, self.path_type)) @staticmethod - def from_config_object(section: ConfigObj, shard_id: str, blobstor_id: str): + def from_config_object(section: dict, shard_id: str, blobstor_id: str): var_prefix = f"{SHARD_PREFIX}{shard_id}{BLOBSTOR_PREFIX}{blobstor_id}" - return Blobstor(section.get(f"{var_prefix}_PATH"), section.get(f"{var_prefix}_TYPE")) + return Blobstor(section[f"{var_prefix}_PATH"], section[f"{var_prefix}_TYPE"]) @dataclass @@ -54,13 +54,13 @@ def __hash__(self): return hash((self.metabase, self.writecache)) @staticmethod - def _get_blobstor_count_from_section(config_object: ConfigObj, shard_id: int): + def _get_blobstor_count_from_section(config_object: dict, shard_id: int): pattern = f"{SHARD_PREFIX}{shard_id}{BLOBSTOR_PREFIX}" blobstors = {key[: len(pattern) + 2] for key in config_object.keys() if pattern in key} return len(blobstors) @staticmethod - def from_config_object(config_object: ConfigObj, shard_id: int): + def from_config_object(config_object: dict, shard_id: int): var_prefix = f"{SHARD_PREFIX}{shard_id}" blobstor_count = Shard._get_blobstor_count_from_section(config_object, shard_id) @@ -69,12 +69,18 @@ def from_config_object(config_object: ConfigObj, shard_id: int): for blobstor_id in range(blobstor_count) ] - write_cache_enabled = config_object.as_bool(f"{var_prefix}_WRITECACHE_ENABLED") + write_cache_enabled = config_object[f"{var_prefix}_WRITECACHE_ENABLED"].lower() in ( + "true", + "1", + "yes", + "y", + "on", + ) return Shard( blobstors, - config_object.get(f"{var_prefix}_METABASE_PATH"), - config_object.get(f"{var_prefix}_WRITECACHE_PATH") if write_cache_enabled else "", + config_object[f"{var_prefix}_METABASE_PATH"], + config_object[f"{var_prefix}_WRITECACHE_PATH"] if write_cache_enabled else "", ) @staticmethod @@ -103,7 +109,7 @@ def shards_from_yaml(contents: str) -> list[Shard]: def shards_from_env(contents: str) -> list[Shard]: - configObj = ConfigObj(StringIO(contents)) + configObj = dotenv_values(stream=StringIO(contents)) pattern = f"{SHARD_PREFIX}\d*" num_shards = len(set(re.findall(pattern, contents))) diff --git a/requirements.txt b/requirements.txt index 28803e1fa..5b8576cc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,6 @@ cffi==1.15.0 chardet==4.0.0 charset-normalizer==2.0.12 coverage==6.3.3 -configobj==5.0.8 docker==6.1.3 docutils==0.17.1 Events==0.5 @@ -47,6 +46,7 @@ pyrsistent==0.18.1 pytest==7.3.1 pytest-lazy-fixture==0.6.3 python-dateutil==2.8.2 +python-dotenv==1.0.0 pyyaml==6.0 requests==2.31.0 robotframework==4.1.2