Skip to content

Commit 8b3335e

Browse files
linter fix 3
1 parent f226881 commit 8b3335e

File tree

4 files changed

+124
-39
lines changed

4 files changed

+124
-39
lines changed

tests/validation/Engine/csv_report.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def update_compliance_result(requirement_id: str, is_compliant: bool) -> None:
111111
global _compliance_results
112112

113113
_compliance_results[requirement_id] = is_compliant
114-
logger.info(f"Updated compliance for {requirement_id}: {'COMPLIANT' if is_compliant else 'NON-COMPLIANT'}")
114+
logger.info(
115+
f"Updated compliance for {requirement_id}: {'COMPLIANT' if is_compliant else 'NON-COMPLIANT'}"
116+
)
115117

116118

117119
def csv_write_report(log_dir: str = ".") -> None:
@@ -140,7 +142,9 @@ def csv_write_report(log_dir: str = ".") -> None:
140142
if _compliance_results:
141143
try:
142144
with open(compliance_path, "w", newline="") as csvfile:
143-
writer = csv.DictWriter(csvfile, fieldnames=["Requirement ID", "Status"])
145+
writer = csv.DictWriter(
146+
csvfile, fieldnames=["Requirement ID", "Status"]
147+
)
144148
writer.writeheader()
145149
for req_id, is_compliant in _compliance_results.items():
146150
writer.writerow(
@@ -169,7 +173,9 @@ def get_test_summary() -> Dict[str, int | str]:
169173
"total": total_count,
170174
"passed": pass_count,
171175
"failed": fail_count,
172-
"pass_rate": (f"{(pass_count / total_count * 100):.1f}%" if total_count > 0 else "N/A"),
176+
"pass_rate": (
177+
f"{(pass_count / total_count * 100):.1f}%" if total_count > 0 else "N/A"
178+
),
173179
}
174180

175181

@@ -197,7 +203,9 @@ def get_component_summary() -> Dict[str, Dict[str, int | str]]:
197203
for component in components:
198204
total = components[component]["total"]
199205
passed = components[component]["passed"]
200-
components[component]["pass_rate"] = f"{(passed / total * 100):.1f}%" if total > 0 else "N/A"
206+
components[component]["pass_rate"] = (
207+
f"{(passed / total * 100):.1f}%" if total > 0 else "N/A"
208+
)
201209

202210
return components
203211

@@ -217,5 +225,9 @@ def get_compliance_summary() -> Dict[str, int | str]:
217225
"total": total_count,
218226
"compliant": compliant_count,
219227
"non_compliant": non_compliant_count,
220-
"compliance_rate": (f"{(compliant_count / total_count * 100):.1f}%" if total_count > 0 else "N/A"),
228+
"compliance_rate": (
229+
f"{(compliant_count / total_count * 100):.1f}%"
230+
if total_count > 0
231+
else "N/A"
232+
),
221233
}

tests/validation/Engine/logging_utils.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def wrapper(*args, **kwargs) -> Any:
7777
return decorator
7878

7979

80-
def log_ffmpeg_test(test_name: str, test_description: str = "", error_message: str = "") -> Callable:
80+
def log_ffmpeg_test(
81+
test_name: str, test_description: str = "", error_message: str = ""
82+
) -> Callable:
8183
"""Decorator to log FFmpeg test results"""
8284
return log_test_result(
8385
component=COMPONENT_FFMPEG,
@@ -87,7 +89,9 @@ def log_ffmpeg_test(test_name: str, test_description: str = "", error_message: s
8789
)
8890

8991

90-
def log_media_proxy_test(test_name: str, test_description: str = "", error_message: str = "") -> Callable:
92+
def log_media_proxy_test(
93+
test_name: str, test_description: str = "", error_message: str = ""
94+
) -> Callable:
9195
"""Decorator to log Media Proxy test results"""
9296
return log_test_result(
9397
component=COMPONENT_MEDIA_PROXY,
@@ -97,7 +101,9 @@ def log_media_proxy_test(test_name: str, test_description: str = "", error_messa
97101
)
98102

99103

100-
def log_mesh_agent_test(test_name: str, test_description: str = "", error_message: str = "") -> Callable:
104+
def log_mesh_agent_test(
105+
test_name: str, test_description: str = "", error_message: str = ""
106+
) -> Callable:
101107
"""Decorator to log Mesh Agent test results"""
102108
return log_test_result(
103109
component=COMPONENT_MESH_AGENT,
@@ -107,7 +113,9 @@ def log_mesh_agent_test(test_name: str, test_description: str = "", error_messag
107113
)
108114

109115

110-
def log_rxtx_app_test(test_name: str, test_description: str = "", error_message: str = "") -> Callable:
116+
def log_rxtx_app_test(
117+
test_name: str, test_description: str = "", error_message: str = ""
118+
) -> Callable:
111119
"""Decorator to log RxTx App test results"""
112120
return log_test_result(
113121
component=COMPONENT_RXTX_APP,
@@ -135,7 +143,9 @@ def parse_output_for_errors(
135143
logger.warning(f"Unknown component: {component}, using generic error keywords")
136144
error_keywords = ["error", "failed", "exception", "fatal"]
137145
else:
138-
error_keywords = custom_error_keywords or COMPONENT_ERROR_KEYWORDS.get(component, [])
146+
error_keywords = custom_error_keywords or COMPONENT_ERROR_KEYWORDS.get(
147+
component, []
148+
)
139149

140150
errors = []
141151
for line in output.splitlines():

tests/validation/Engine/output_validator.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def validate_ffmpeg(
5454
Returns:
5555
Dictionary with is_pass and errors fields
5656
"""
57-
result = parse_output_for_errors(COMPONENT_FFMPEG, output, custom_error_keywords)
57+
result = parse_output_for_errors(
58+
COMPONENT_FFMPEG, output, custom_error_keywords
59+
)
5860

5961
error_message = "\n".join(result["errors"]) if result["errors"] else ""
6062

@@ -88,7 +90,9 @@ def validate_media_proxy(
8890
Returns:
8991
Dictionary with is_pass and errors fields
9092
"""
91-
result = parse_output_for_errors(COMPONENT_MEDIA_PROXY, output, custom_error_keywords)
93+
result = parse_output_for_errors(
94+
COMPONENT_MEDIA_PROXY, output, custom_error_keywords
95+
)
9296

9397
error_message = "\n".join(result["errors"]) if result["errors"] else ""
9498

@@ -122,7 +126,9 @@ def validate_mesh_agent(
122126
Returns:
123127
Dictionary with is_pass and errors fields
124128
"""
125-
result = parse_output_for_errors(COMPONENT_MESH_AGENT, output, custom_error_keywords)
129+
result = parse_output_for_errors(
130+
COMPONENT_MESH_AGENT, output, custom_error_keywords
131+
)
126132

127133
error_message = "\n".join(result["errors"]) if result["errors"] else ""
128134

@@ -156,7 +162,9 @@ def validate_rxtx_app(
156162
Returns:
157163
Dictionary with is_pass and errors fields
158164
"""
159-
result = parse_output_for_errors(COMPONENT_RXTX_APP, output, custom_error_keywords)
165+
result = parse_output_for_errors(
166+
COMPONENT_RXTX_APP, output, custom_error_keywords
167+
)
160168

161169
error_message = "\n".join(result["errors"]) if result["errors"] else ""
162170

@@ -203,16 +211,26 @@ def validate_from_log_file(
203211

204212
# Validate output based on component
205213
if component == COMPONENT_FFMPEG:
206-
return self.validate_ffmpeg(output, test_name, duration, custom_error_keywords)
214+
return self.validate_ffmpeg(
215+
output, test_name, duration, custom_error_keywords
216+
)
207217
elif component == COMPONENT_MEDIA_PROXY:
208-
return self.validate_media_proxy(output, test_name, duration, custom_error_keywords)
218+
return self.validate_media_proxy(
219+
output, test_name, duration, custom_error_keywords
220+
)
209221
elif component == COMPONENT_MESH_AGENT:
210-
return self.validate_mesh_agent(output, test_name, duration, custom_error_keywords)
222+
return self.validate_mesh_agent(
223+
output, test_name, duration, custom_error_keywords
224+
)
211225
elif component == COMPONENT_RXTX_APP:
212-
return self.validate_rxtx_app(output, test_name, duration, custom_error_keywords)
226+
return self.validate_rxtx_app(
227+
output, test_name, duration, custom_error_keywords
228+
)
213229
else:
214230
logger.warning(f"Unknown component: {component}")
215-
result = parse_output_for_errors(component, output, custom_error_keywords)
231+
result = parse_output_for_errors(
232+
component, output, custom_error_keywords
233+
)
216234

217235
error_message = "\n".join(result["errors"]) if result["errors"] else ""
218236

tests/validation/conftest.py

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ def mesh_agent(hosts, test_config, log_path):
145145
mesh_ip = test_config.get("mesh_ip", None)
146146

147147
if not mesh_ip:
148-
logger.error(f"Host '{mesh_agent_name}' not found in topology.yaml and no mesh_ip provided.")
148+
logger.error(
149+
f"Host '{mesh_agent_name}' not found in topology.yaml and no mesh_ip provided."
150+
)
149151
raise RuntimeError(
150152
f"No mesh-agent name '{mesh_agent_name}' found in hosts and no mesh_ip provided in test_config."
151153
)
152154
else:
153-
logger.info(f"Assumed that mesh agent is running, getting IP from topology config: {mesh_ip}")
155+
logger.info(
156+
f"Assumed that mesh agent is running, getting IP from topology config: {mesh_ip}"
157+
)
154158
mesh_agent.external = True
155159
mesh_agent.mesh_ip = mesh_ip
156160
mesh_agent.p = test_config.get("mesh_port", mesh_agent.p)
@@ -223,7 +227,9 @@ def media_config(hosts: dict) -> None:
223227
if host.topology.extra_info.media_proxy.get("st2110", False):
224228
pf_addr = host.network_interfaces[if_idx].pci_address.lspci
225229
vfs = nicctl.vfio_list(pf_addr)
226-
host.st2110_dev = host.topology.extra_info.media_proxy.get("st2110_dev", None)
230+
host.st2110_dev = host.topology.extra_info.media_proxy.get(
231+
"st2110_dev", None
232+
)
227233
if not host.st2110_dev and not vfs:
228234
nicctl.create_vfs(pf_addr)
229235
vfs = nicctl.vfio_list(pf_addr)
@@ -238,25 +244,44 @@ def media_config(hosts: dict) -> None:
238244
f"Still no VFs on interface {host.network_interfaces[if_idx].pci_address_lspci} even after creating VFs!"
239245
)
240246
host.vfs = vfs
241-
host.st2110_ip = host.topology.extra_info.media_proxy.get("st2110_ip", f"192.168.0.{last_oct}")
247+
host.st2110_ip = host.topology.extra_info.media_proxy.get(
248+
"st2110_ip", f"192.168.0.{last_oct}"
249+
)
242250
if_idx += 1
243251
if host.topology.extra_info.media_proxy.get("rdma", False):
244-
if int(host.network_interfaces[if_idx].virtualization.get_current_vfs()) > 0:
245-
nicctl.disable_vf(str(host.network_interfaces[if_idx].pci_address.lspci))
252+
if (
253+
int(
254+
host.network_interfaces[if_idx].virtualization.get_current_vfs()
255+
)
256+
> 0
257+
):
258+
nicctl.disable_vf(
259+
str(host.network_interfaces[if_idx].pci_address.lspci)
260+
)
246261
net_adap_ips = host.network_interfaces[if_idx].ip.get_ips().v4
247262
rdma_ip = host.topology.extra_info.media_proxy.get("rdma_ip", False)
248263
if rdma_ip:
249-
rdma_ip = IPv4Interface(f"{rdma_ip}" if "/" in rdma_ip else f"{rdma_ip}/24")
264+
rdma_ip = IPv4Interface(
265+
f"{rdma_ip}" if "/" in rdma_ip else f"{rdma_ip}/24"
266+
)
250267
elif net_adap_ips and not rdma_ip:
251268
rdma_ip = net_adap_ips[0]
252269
if not rdma_ip or (rdma_ip not in net_adap_ips):
253-
rdma_ip = IPv4Interface(f"192.168.1.{last_oct}/24") if not rdma_ip else rdma_ip
254-
logger.info(f"IP {rdma_ip} not found on RDMA network interface, setting: {rdma_ip}")
270+
rdma_ip = (
271+
IPv4Interface(f"192.168.1.{last_oct}/24")
272+
if not rdma_ip
273+
else rdma_ip
274+
)
275+
logger.info(
276+
f"IP {rdma_ip} not found on RDMA network interface, setting: {rdma_ip}"
277+
)
255278
host.network_interfaces[if_idx].ip.add_ip(rdma_ip)
256279
host.rdma_ip = str(rdma_ip.ip)
257280
logger.info(f"VFs on {host.name} are: {host.vfs}")
258281
except IndexError:
259-
raise IndexError(f"Not enough network adapters available for tests! Expected: {if_idx+1}")
282+
raise IndexError(
283+
f"Not enough network adapters available for tests! Expected: {if_idx+1}"
284+
)
260285
except AttributeError:
261286
logger.warning(
262287
f"Extra info media proxy in topology config for {host.name} is not set, skipping media config setup for this host."
@@ -282,10 +307,16 @@ def cleanup_processes(hosts: dict) -> None:
282307
try:
283308
connection = host.connection
284309
# connection.enable_sudo()
285-
connection.execute_command(f"pgrep -f '{pattern}'", stderr_to_stdout=True)
286-
connection.execute_command(f"pkill -9 -f '{pattern}'", stderr_to_stdout=True)
310+
connection.execute_command(
311+
f"pgrep -f '{pattern}'", stderr_to_stdout=True
312+
)
313+
connection.execute_command(
314+
f"pkill -9 -f '{pattern}'", stderr_to_stdout=True
315+
)
287316
except Exception as e:
288-
logger.warning(f"Failed to check/kill processes matching {pattern} on {host.name}: {e}")
317+
logger.warning(
318+
f"Failed to check/kill processes matching {pattern} on {host.name}: {e}"
319+
)
289320
logger.info("Cleanup of processes completed.")
290321

291322

@@ -311,15 +342,19 @@ def check_iommu(hosts: dict[str, Host]) -> None:
311342
iommu_not_enabled_hosts = []
312343
for host in hosts.values():
313344
try:
314-
output = host.connection.execute_command("ls -1 /sys/kernel/iommu_groups | wc -l", shell=True, timeout=10)
345+
output = host.connection.execute_command(
346+
"ls -1 /sys/kernel/iommu_groups | wc -l", shell=True, timeout=10
347+
)
315348
if int(output.stdout.strip()) == 0:
316349
logger.error(f"IOMMU is not enabled on host {host.name}.")
317350
iommu_not_enabled_hosts.append(host.name)
318351
except Exception as e:
319352
logger.exception(f"Failed to check IOMMU status on host {host.name}.")
320353
iommu_not_enabled_hosts.append(host.name)
321354
if iommu_not_enabled_hosts:
322-
pytest.exit(f"IOMMU is not enabled on hosts: {', '.join(iommu_not_enabled_hosts)}. Aborting test session.")
355+
pytest.exit(
356+
f"IOMMU is not enabled on hosts: {', '.join(iommu_not_enabled_hosts)}. Aborting test session."
357+
)
323358
else:
324359
logger.info("IOMMU is enabled on all hosts.")
325360

@@ -332,14 +367,20 @@ def enable_hugepages(hosts: dict[str, Host]) -> None:
332367
for host in hosts.values():
333368
if not _check_hugepages(host):
334369
try:
335-
host.connection.execute_command("sudo sysctl -w vm.nr_hugepages=2048", shell=True, timeout=10)
370+
host.connection.execute_command(
371+
"sudo sysctl -w vm.nr_hugepages=2048", shell=True, timeout=10
372+
)
336373
logger.info(f"Hugepages enabled on host {host.name}.")
337374
except (RemoteProcessTimeoutExpired, ConnectionCalledProcessError):
338375
logger.exception(f"Failed to enable hugepages on host {host.name}.")
339-
pytest.exit(f"Failed to enable hugepages on host {host.name}. Aborting test session.")
376+
pytest.exit(
377+
f"Failed to enable hugepages on host {host.name}. Aborting test session."
378+
)
340379
if not _check_hugepages(host):
341380
logger.error(f"Hugepages could not be enabled on host {host.name}.")
342-
pytest.exit(f"Hugepages could not be enabled on host {host.name}. Aborting test session.")
381+
pytest.exit(
382+
f"Hugepages could not be enabled on host {host.name}. Aborting test session."
383+
)
343384
else:
344385
logger.info(f"Hugepages are already enabled on host {host.name}.")
345386

@@ -349,7 +390,9 @@ def _check_hugepages(host: Host) -> bool:
349390
Check if hugepages are enabled on the host.
350391
"""
351392
try:
352-
output = host.connection.execute_command("cat /proc/sys/vm/nr_hugepages", shell=True, timeout=10)
393+
output = host.connection.execute_command(
394+
"cat /proc/sys/vm/nr_hugepages", shell=True, timeout=10
395+
)
353396
return int(output.stdout.strip()) > 0
354397
except (RemoteProcessTimeoutExpired, ConnectionCalledProcessError):
355398
logger.exception(f"Failed to check hugepages status on host {host.name}.")
@@ -395,7 +438,9 @@ def log_case(request, caplog: pytest.LogCaptureFixture):
395438
os.makedirs(os.path.join(LOG_FOLDER, "latest", case_folder), exist_ok=True)
396439
logfile = os.path.join(LOG_FOLDER, "latest", f"{case_id}.log")
397440
fh = logging.FileHandler(logfile)
398-
formatter = request.session.config.pluginmanager.get_plugin("logging-plugin").formatter
441+
formatter = request.session.config.pluginmanager.get_plugin(
442+
"logging-plugin"
443+
).formatter
399444
format = AmberLogFormatter(formatter)
400445
fh.setFormatter(format)
401446
fh.setLevel(logging.DEBUG)

0 commit comments

Comments
 (0)