From 4c0ba5b2c0ed979706a532291c47320f4ce26e71 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Fri, 13 Nov 2026 09:00:43 +0100 Subject: [PATCH] refactor(accounts): the account step of add_service_account in a helper replaces= made add_service_account 55 lines long, over the quality ratchet's 50. Its account step -- none to take when the driver logs in as the account already, else the create or reopen -- moves to _accounts_service_account_step. Behaviour is unchanged; the tests of add_service_account cover both branches. --- napalm_device_types/local_accounts.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/napalm_device_types/local_accounts.py b/napalm_device_types/local_accounts.py index a5eae0c..bf20abf 100644 --- a/napalm_device_types/local_accounts.py +++ b/napalm_device_types/local_accounts.py @@ -520,21 +520,27 @@ class LocalAccountsMixin: check_public_key(public_key) old = [key for key in _checked_keys(replaces) if _key_blob(key) != _key_blob(public_key)] login, existing = self._accounts_service_target(name, uid) + first = self._accounts_service_account_step(name, login, existing, uid) + parts = [first] + if first["success"]: + parts += self._accounts_service_keys(name, public_key, old) + return self._accounts_result(name, parts) + + def _accounts_service_account_step( + self, name: str, login: str, existing: list[str] | None, uid: int | None + ) -> FixResultDict: + """The ``account`` step of netOrk's own account; nothing to do when the driver + logs in as *name* already.""" if name == login: step: FixStepDict = { "step": "account", "ok": True, "output": f"this driver logs in as {name} already", } - first: FixResultDict = _joined([step]) - else: - first = run_fix_steps( - [("account", lambda: self._accounts_service_account(name, existing, uid))] - ) - parts = [first] - if first["success"]: - parts += self._accounts_service_keys(name, public_key, old) - return self._accounts_result(name, parts) + return _joined([step]) + return run_fix_steps( + [("account", lambda: self._accounts_service_account(name, existing, uid))] + ) def _accounts_service_keys( self, name: str, public_key: str, old: list[str]