Skip to content

Commit af9e68f

Browse files
CopilotsquirrelscLiliDeng
authored
Refactor exception variable names from 'identifier' to 'e' (#3816)
* Initial plan for issue * Refactor exception variable names from 'identifier' to 'e' Co-authored-by: squirrelsc <27178119+squirrelsc@users.noreply.github.com> * Fix Black formatting issues in 7 files Co-authored-by: squirrelsc <27178119+squirrelsc@users.noreply.github.com> * Fix redundant f-string in operating_system.py Co-authored-by: LiliDeng <10083705+LiliDeng@users.noreply.github.com> * Fix linting issues in operating_system.py Co-authored-by: LiliDeng <10083705+LiliDeng@users.noreply.github.com> * Fix multiline f-string in operating_system.py Co-authored-by: LiliDeng <10083705+LiliDeng@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: squirrelsc <27178119+squirrelsc@users.noreply.github.com> Co-authored-by: LiliDeng <10083705+LiliDeng@users.noreply.github.com>
1 parent 3d637f4 commit af9e68f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+266
-278
lines changed

lisa/base_tools/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ def _get_status(
277277
force_run=True,
278278
output_json=True,
279279
)
280-
except LisaException as identifier:
281-
if "Cannot find any service with service name" in str(identifier):
280+
except LisaException as e:
281+
if "Cannot find any service with service name" in str(e):
282282
if fail_on_error:
283283
raise LisaException(f"service '{name}' does not exist")
284284
return WindowsServiceStatus.NOT_FOUND
285-
raise identifier
285+
raise e
286286
return WindowsServiceStatus(int(service_status["Status"]))
287287

288288
def _wait_for_service(

lisa/commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def run(args: Namespace) -> int:
4242
runner = RootRunner(runbook_builder=builder)
4343
asyncio.run(runner.start())
4444
run_status = messages.TestRunStatus.SUCCESS
45-
except Exception as identifier:
46-
run_error_message = str(identifier)
47-
raise identifier
45+
except Exception as e:
46+
run_error_message = str(e)
47+
raise e
4848
finally:
4949
run_message.status = run_status
5050
run_message.elapsed = run_timer.elapsed()

lisa/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ def get_environment_information(self, environment: Environment) -> Dict[str, str
567567
node = environment.default_node
568568
try:
569569
information = node.get_information()
570-
except Exception as identifier:
570+
except Exception as e:
571571
environment.log.exception(
572-
"failed to get environment information", exc_info=identifier
572+
"failed to get environment information", exc_info=e
573573
)
574574

575575
return information

lisa/feature.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def reload_platform_features(
206206
settings_type = get_feature_settings_type_by_name(
207207
current_settings.type, platform_features
208208
)
209-
except NotMeetRequirementException as identifier:
210-
raise LisaException(f"platform doesn't support all features. {identifier}")
209+
except NotMeetRequirementException as e:
210+
raise LisaException(f"platform doesn't support all features. {e}")
211211
new_setting = schema.load_by_type(settings_type, current_settings)
212212
existing_setting = get_feature_settings_by_name(
213213
new_setting.type, new_settings, True

lisa/features/infiniband.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ def install_ofed(self) -> None:
400400
overwrite=False,
401401
sudo=True,
402402
)
403-
except LisaException as identifier:
404-
if "404: Not Found." in str(identifier):
403+
except LisaException as e:
404+
if "404: Not Found." in str(e):
405405
raise UnsupportedDistroException(
406406
node.os, f"{mlnx_ofed_download_url} doesn't exist."
407407
)

lisa/node.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ def capture_system_information(self, name: str = "") -> None:
364364
self.log.debug(f"capturing system information to {saved_path}.")
365365
try:
366366
self.os.capture_system_information(saved_path)
367-
except Exception as identifier:
367+
except Exception as e:
368368
# For some images like cisco, southrivertech1586314123192, they might raise
369369
# exception when calling copy_back. This should not block the test, so add
370370
# try-except.
371-
self.log.debug(f"error on capturing system information: {identifier}")
371+
self.log.debug(f"error on capturing system information: {e}")
372372

373373
def find_partition_with_freespace(
374374
self, size_in_gb: int, use_os_drive: bool = True, raise_error: bool = True
@@ -489,8 +489,8 @@ def test_connection(self) -> bool:
489489
try:
490490
self.execute("echo connected", timeout=10)
491491
return True
492-
except Exception as identifier:
493-
self.log.debug(f"cannot access VM {self.name}, error is {identifier}")
492+
except Exception as e:
493+
self.log.debug(f"cannot access VM {self.name}, error is {e}")
494494
return False
495495

496496
def check_kernel_panic(self) -> None:
@@ -795,8 +795,8 @@ def _reset_password(self) -> bool:
795795
password = generate_strong_password()
796796
try:
797797
password_extension.reset_password(username, str(password))
798-
except Exception as identifier:
799-
self.log.debug(f"reset password failed: {identifier}")
798+
except Exception as e:
799+
self.log.debug(f"reset password failed: {e}")
800800
return False
801801
add_secret(password)
802802
self._connection_info.password = password
@@ -1220,10 +1220,8 @@ def get_node_information(self, node: Node) -> Dict[str, str]:
12201220
information.update(information_dict)
12211221
information["distro_version"] = node.os.information.full_version
12221222
information["kernel_version"] = linux_information.kernel_version_raw
1223-
except Exception as identifier:
1224-
node.log.exception(
1225-
"failed to get node information", exc_info=identifier
1226-
)
1223+
except Exception as e:
1224+
node.log.exception("failed to get node information", exc_info=e)
12271225

12281226
return information
12291227

lisa/notifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@ def finalize() -> None:
139139
for notifier in _notifiers:
140140
try:
141141
notifier.finalize()
142-
except Exception as identifier:
143-
notifier._log.exception(identifier)
142+
except Exception as e:
143+
notifier._log.exception(e)

lisa/operating_system.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ def capture_system_information(self, saved_path: Path) -> None:
470470
boot_time = systemd_analyze_tool.get_boot_time()
471471
boot_time.information.update(self._node.get_information())
472472
notifier.notify(boot_time)
473-
except Exception as identifier:
474-
self._node.log.debug(f"error on get boot time: {identifier}")
473+
except Exception as e:
474+
self._node.log.debug(f"error on get boot time: {e}")
475475

476476
file_list = []
477477
if self._node.capture_azure_information:
@@ -500,11 +500,11 @@ def capture_system_information(self, saved_path: Path) -> None:
500500
)
501501
except FileNotFoundError:
502502
self._log.debug(f"File {file} doesn't exist.")
503-
except Exception as identifier:
503+
except Exception as e:
504504
# Some images have no /etc/os-release. e.g. osirium-ltd osirium_pem
505505
# image. It will have an exception (not FileNotFoundError).
506506
self._log.debug(
507-
f"Fail to copy back file {file}: {identifier}. "
507+
f"Fail to copy back file {file}: {e}. "
508508
"Please check if the file exists"
509509
)
510510

@@ -1293,10 +1293,9 @@ def replace_boot_kernel(self, kernel_version: str) -> None:
12931293
f"linux-headers-{kernel_version}-azure",
12941294
]
12951295
)
1296-
except Exception as identifier:
1296+
except Exception as e:
12971297
self._log.debug(
1298-
f"ignorable error on install packages after replaced kernel: "
1299-
f"{identifier}"
1298+
f"ignorable error on install packages after replaced kernel: {e}"
13001299
)
13011300

13021301
def wait_cloud_init_finish(self) -> None:

lisa/parameter_parser/runbook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ def _internal_resolve(
154154
variables = self.variables
155155
try:
156156
parsed_data = replace_variables(raw_data, variables)
157-
except Exception as identifier:
157+
except Exception as e:
158158
# log current data for troubleshooting.
159159
self._log.debug(f"parsed raw data: {raw_data}")
160-
raise identifier
160+
raise e
161161

162162
return parsed_data
163163

@@ -358,9 +358,9 @@ def _load_data(
358358
try:
359359
include: schema.Include
360360
include = schema.load_by_type(schema.Include, include_raw)
361-
except Exception as identifier:
361+
except Exception as e:
362362
raise LisaException(
363-
f"error on loading include node [{include_raw}]: {identifier}"
363+
f"error on loading include node [{include_raw}]: {e}"
364364
)
365365
if include.strategy:
366366
raise NotImplementedError(

lisa/platform_.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def get_environment_information(self, environment: Environment) -> Dict[str, str
121121
information.update(
122122
self._get_environment_information(environment=environment)
123123
)
124-
except Exception as identifier:
124+
except Exception as e:
125125
self._log.exception(
126-
"failed to get environment information on platform", exc_info=identifier
126+
"failed to get environment information on platform", exc_info=e
127127
)
128128

129129
return information
@@ -133,9 +133,9 @@ def get_node_information(self, node: Node) -> Dict[str, str]:
133133
information: Dict[str, str] = {}
134134
try:
135135
information.update(self._get_node_information(node=node))
136-
except Exception as identifier:
136+
except Exception as e:
137137
self._log.exception(
138-
"failed to get node information on platform", exc_info=identifier
138+
"failed to get node information on platform", exc_info=e
139139
)
140140

141141
return information
@@ -162,8 +162,8 @@ def prepare_environment(self, environment: Environment) -> Environment:
162162

163163
try:
164164
is_success = self._prepare_environment(environment, log)
165-
except NotMeetRequirementException as identifier:
166-
raise SkippedException(identifier)
165+
except NotMeetRequirementException as e:
166+
raise SkippedException(e)
167167

168168
if is_success:
169169
environment.status = EnvironmentStatus.Prepared

lisa/runner.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,10 @@ async def start(self) -> None:
248248
register_notifier(self._results_collector)
249249

250250
self._start_loop()
251-
except Exception as identifier:
252-
self._log.exception(
253-
"canceling runner due to exception", exc_info=identifier
254-
)
251+
except Exception as e:
252+
self._log.exception("canceling runner due to exception", exc_info=e)
255253
cancel()
256-
raise identifier
254+
raise e
257255
finally:
258256
self._cleanup()
259257

@@ -458,10 +456,10 @@ def _cleanup(self) -> None:
458456
try:
459457
for runner in self._runners:
460458
runner.close()
461-
except Exception as identifier:
462-
self._log.warn(f"error on close runner: {identifier}")
459+
except Exception as e:
460+
self._log.warn(f"error on close runner: {e}")
463461

464462
try:
465463
transformer.run(self._runbook_builder, constants.TRANSFORMER_PHASE_CLEANUP)
466-
except Exception as identifier:
467-
self._log.warn(f"error on run cleanup transformers: {identifier}")
464+
except Exception as e:
465+
self._log.warn(f"error on run cleanup transformers: {e}")

lisa/runners/lisa_runner.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,25 @@ def _deploy_environment_task(
296296
environment.status == EnvironmentStatus.Deployed
297297
), f"actual: {environment.status}"
298298
self._reset_awaitable_timer("deploy")
299-
except ResourceAwaitableException as identifier:
299+
except ResourceAwaitableException as e:
300300
if self._is_awaitable_timeout("deploy"):
301301
self._log.info(
302302
f"[{environment.name}] timeout on waiting for more resource: "
303-
f"{identifier}, skip assigning case."
303+
f"{e}, skip assigning case."
304304
)
305-
raise SkippedException(identifier)
305+
raise SkippedException(e)
306306
else:
307307
# rerun prepare to calculate resource again.
308308
environment.status = EnvironmentStatus.New
309-
except Exception as identifier:
309+
except Exception as e:
310310
if self._need_retry(environment):
311311
environment.status = EnvironmentStatus.New
312312
else:
313313
# Final attempt failed; handle the failure
314314
self._attach_failed_environment_to_result(
315315
environment=environment,
316316
result=test_result,
317-
exception=identifier,
317+
exception=e,
318318
)
319319
self._delete_environment_task(environment=environment, test_results=[])
320320
finally:
@@ -335,11 +335,11 @@ def _initialize_environment_task(
335335
phase=constants.TRANSFORMER_PHASE_ENVIRONMENT_CONNECTED,
336336
environment=environment,
337337
)
338-
except Exception as identifier:
338+
except Exception as e:
339339
self._attach_failed_environment_to_result(
340340
environment=environment,
341341
result=test_results[0],
342-
exception=identifier,
342+
exception=e,
343343
)
344344
self._delete_environment_task(environment=environment, test_results=[])
345345

@@ -398,13 +398,13 @@ def _run_test_task(
398398
try:
399399
# check panic when node(s) in bad status
400400
environment.nodes.check_kernel_panics()
401-
except KernelPanicException as identifier:
401+
except KernelPanicException as e:
402402
# not throw exception here, since it will cancel all tasks
403403
# just print log here and set test result status as failed
404-
test_result.set_status(TestStatus.FAILED, str(identifier))
404+
test_result.set_status(TestStatus.FAILED, str(e))
405405
self._log.debug(
406406
"found kernel panic from the node(s) of "
407-
f"'{environment.name}': {identifier}"
407+
f"'{environment.name}': {e}"
408408
)
409409
tested_environment.nodes.close()
410410

@@ -473,9 +473,9 @@ def _delete_environment_task(
473473
else:
474474
try:
475475
self.platform.delete_environment(environment)
476-
except Exception as identifier:
476+
except Exception as e:
477477
self._log.debug(
478-
f"error on deleting environment '{environment.name}': {identifier}"
478+
f"error on deleting environment '{environment.name}': {e}"
479479
)
480480

481481
def _prepare_environment(self, environment: Environment) -> bool:
@@ -484,23 +484,23 @@ def _prepare_environment(self, environment: Environment) -> bool:
484484
try:
485485
self.platform.prepare_environment(environment)
486486
self._reset_awaitable_timer("prepare")
487-
except ResourceAwaitableException as identifier:
487+
except ResourceAwaitableException as e:
488488
# if timed out, raise the exception and skip the test case. If
489489
# not, do nothing to keep env as new to try next time.
490490
if self._is_awaitable_timeout("prepare"):
491-
raise SkippedException(identifier)
492-
except Exception as identifier:
491+
raise SkippedException(e)
492+
except Exception as e:
493493
success = False
494494

495495
matched_result = self._match_failed_environment_with_result(
496496
environment=environment,
497497
candidate_results=self.test_results,
498-
exception=identifier,
498+
exception=e,
499499
)
500500
self._attach_failed_environment_to_result(
501501
environment=environment,
502502
result=matched_result,
503-
exception=identifier,
503+
exception=e,
504504
)
505505

506506
return success
@@ -654,13 +654,13 @@ def _get_runnable_test_results(
654654
or environment.is_new
655655
):
656656
runnable_results.append(result)
657-
except SkippedException as identifier:
657+
except SkippedException as e:
658658
if not result.environment:
659659
result.environment = environment
660660
# when check the environment, the test result may be marked
661661
# as skipped, due to the test result is assumed not to match
662662
# any environment.
663-
result.handle_exception(identifier, log=self._log, phase="check")
663+
result.handle_exception(e, log=self._log, phase="check")
664664
results = runnable_results
665665

666666
# only select one test case, which needs the new environment. Others
@@ -848,8 +848,8 @@ def _merge_test_requirements(
848848
node_requirement = original_node_requirement.intersect(
849849
platform_requirement
850850
)
851-
except NotMeetRequirementException as identifier:
852-
test_result.set_status(TestStatus.SKIPPED, str(identifier))
851+
except NotMeetRequirementException as e:
852+
test_result.set_status(TestStatus.SKIPPED, str(e))
853853
break
854854

855855
assert isinstance(platform_requirement.extended_schemas, dict)

0 commit comments

Comments
 (0)