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

[th/validate-args] testConfig: improve validation of {ConfServer,ConfClient}.args #172

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
36 changes: 20 additions & 16 deletions testConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ def _parse(

def _construct_args(pctx2: StructParseParseContext) -> tuple[str, ...]:
if isinstance(pctx2.arg, str):
return tuple(shlex.split(pctx2.arg))
try:
lst = shlex.split(pctx2.arg)
except Exception:
raise pctx2.value_error(
f"cannot parse command line {repr(pctx2.arg)}"
)
return tuple(lst)
if isinstance(pctx2.arg, list):
if not all(isinstance(x, str) for x in pctx2.arg):
raise pctx2.value_error(
Expand Down Expand Up @@ -145,6 +151,14 @@ def _construct_args(pctx2: StructParseParseContext) -> tuple[str, ...]:

return typing.cast("T2", result)

def _validate(self, test_type: TestType) -> None:
if self.args is not None:
if test_type not in (TestType.SIMPLE,):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only support SIMPLE test type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this parameter was added especially for "simple", to tweak what the script does. The script is mainly intended for manually hacking it for some ad-hoc testing, so passing additional parameters to it may make sense.

passing args to iperf or netperf tools probably would make sense. But it's not implemented yet, hence it's currently rejected.

raise self.value_error(
f"not supported with test type {repr(test_type.name)}",
key="args",
)


@strict_dataclass
@dataclass(frozen=True, kw_only=True)
Expand Down Expand Up @@ -319,21 +333,11 @@ def parse(
"currently only one client entry is supported", key="client"
)

for idx, s in enumerate(server):
if s.args is not None:
if test_type not in (TestType.SIMPLE,):
raise pctx.value_error(
f"args are not supported for test type {test_type}",
subpath=f".server[{idx}].args",
)

for idx, c in enumerate(client):
if c.args is not None:
if test_type not in (TestType.SIMPLE,):
raise pctx.value_error(
f"args are not supported for test type {test_type}",
subpath=f".client[{idx}].args",
)
for s in server:
s._validate(test_type)

for c in client:
c._validate(test_type)

return ConfConnection(
yamlidx=pctx.yamlidx,
Expand Down
Loading