@@ -181,8 +181,11 @@ def _get_conditions():
181181def make_bcrypt_htpasswd_file_with_users (users : list [tuple [str , str ]]) -> Path :
182182 """
183183 Create a single htpasswd file (-B bcrypt) containing multiple users.
184- `users` is a list of (username, password) tuples.
184+ `users` is a list of (username, password) tuples.The returned file path must be deleted.
185185 """
186+ if not users :
187+ raise ValueError ("users list cannot be empty" )
188+
186189 with tempfile .NamedTemporaryFile (mode = "w+" , delete = False ) as temp_file :
187190 htpasswd_path = Path (temp_file .name ).resolve ()
188191
@@ -209,10 +212,7 @@ def login_with_retry(
209212 wait_timeout : int = 60 ,
210213 sleep : float = 2.0 ,
211214) -> None :
212- """
213- Login helper that retries a few times in case the cluster is not ready.
214- This avoids test failures caused by temporary login errors.
215- """
215+
216216 last_exc : Exception | None = None
217217
218218 def _attempt_login () -> bool :
@@ -227,21 +227,21 @@ def _attempt_login() -> bool:
227227 LOGGER .warning ("MaaS RBAC: login returned False for %s; will retry" , user )
228228 return False
229229 return True
230- except Exception as login_error : # noqa: BLE001 (broad exception is intentional here)
230+ except Exception as login_error :
231231 last_exc = login_error
232232 error_text = str (login_error ) or "<no error message>"
233233 LOGGER .warning ("MaaS RBAC: login failed for %s (%s); will retry" , user , error_text )
234234 return False
235- sampler = TimeoutSampler (
236- wait_timeout = wait_timeout ,
237- sleep = sleep ,
238- func = _attempt_login ,
239- )
240235
241- for ok in sampler :
242- if ok :
243- LOGGER .info (f"MaaS RBAC: login succeeded for { user } " )
244- return
236+ sampler = TimeoutSampler (
237+ wait_timeout = wait_timeout ,
238+ sleep = sleep ,
239+ func = _attempt_login ,
240+ )
241+
242+ for ok in sampler :
243+ if ok :
244+ LOGGER .info (f"MaaS RBAC: login succeeded for { user } " )
245+ return
245246
246- # If we exit the loop without success, timeout was hit
247- raise last_exc if last_exc else RuntimeError (f"Login failed for user { user } " )
247+ raise last_exc if last_exc else RuntimeError (f"Login failed for user { user } " )
0 commit comments