From 3ef254e80c150130dcd104cefa807a2e6fd1e8ce Mon Sep 17 00:00:00 2001 From: Szymon Basan <116343782+sbasan@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:59:20 +0200 Subject: [PATCH] Fix: admintech wait (#17) * version check and model update for user * admin tech - wait for file ready * get token * correct logic * Add default None values to the Tier model (#16) --------- Co-authored-by: Nikhil Co-authored-by: PrzeG <86780353+PrzeG@users.noreply.github.com> --- catalystwan/api/admin_tech_api.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/catalystwan/api/admin_tech_api.py b/catalystwan/api/admin_tech_api.py index 06e95c9f..088251f2 100644 --- a/catalystwan/api/admin_tech_api.py +++ b/catalystwan/api/admin_tech_api.py @@ -10,8 +10,8 @@ from pathlib import Path from typing import TYPE_CHECKING, List, Optional -from requests import Response -from requests.exceptions import HTTPError +from requests import Response # type: ignore +from requests.exceptions import HTTPError # type: ignore from catalystwan.dataclasses import AdminTech, DeviceAdminTech from catalystwan.exceptions import CatalystwanException @@ -131,11 +131,15 @@ def generate( polling_timer -= polling_interval raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}") - def _get_token_id(self, filename: str) -> str: - admin_techs = self.get_all() - for admin_tech in admin_techs: - if filename == admin_tech.filename: - return admin_tech.token_id + def _get_token_id(self, filename: str, timeout: int = 3600, interval: int = 30) -> str: + # Wait for the file to be ready and obtain the token_id + end_time = time.time() + timeout + while time.time() < end_time: + admin_techs = self.get_all() + for admin_tech in admin_techs: + if filename == admin_tech.filename and admin_tech.state == "done": + return admin_tech.token_id + time.sleep(interval) raise RequestTokenIdNotFound( f"requestTokenId of admin tech generation request not found for file name: {filename}" )