Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: replace configobj with dotenv, fixes #568 #648

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions pytest_tests/testsuites/shard/test_control_shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading