diff --git a/.azure-pipelines/impacted_area_testing/calculate_instance_number.py b/.azure-pipelines/impacted_area_testing/calculate_instance_number.py index 4aa14336c1..92489a6fc7 100644 --- a/.azure-pipelines/impacted_area_testing/calculate_instance_number.py +++ b/.azure-pipelines/impacted_area_testing/calculate_instance_number.py @@ -1,7 +1,6 @@ import os import argparse import math -import json from constant import PR_CHECKER_TOPOLOGY_NAME, MAX_INSTANCE_NUMBER, MAX_GET_TOKEN_RETRY_TIMES from azure.kusto.data import KustoConnectionStringBuilder, KustoClient from datetime import datetime, timezone @@ -41,12 +40,11 @@ def get_access_token(): # 1. Run az login with re-try az_login_cmd = f"az login --identity --username {managed_identity_id}" - print(az_login_cmd) az_login_attempts = 0 while az_login_attempts < MAX_GET_TOKEN_RETRY_TIMES: try: - os.popen(az_login_cmd) - # print(result.read()) + result = os.popen(az_login_cmd) + print(result.read()) print(f"Az login successfully. Login time: {datetime.now(timezone.utc)}") break except Exception as exception: @@ -61,25 +59,20 @@ def get_access_token(): raise Exception(f"Failed to az login after {MAX_GET_TOKEN_RETRY_TIMES} attempts.") # 2. Get access token with re-try - get_token_cmd = f"az login --identity --username {managed_identity_id} " \ - f"& az account get-access-token --resource https://api.kusto.windows.net --query accessToken -o tsv" + get_token_cmd = "az account get-access-token --resource https://api.kusto.windows.net --query accessToken -o tsv" print(get_token_cmd) get_token_attempts = 0 while get_token_attempts < MAX_GET_TOKEN_RETRY_TIMES: try: result = os.popen(get_token_cmd) # token = os.popen(get_token_cmd) - print(result.read()) - token = json.loads(result.read()) - access_token = token.get("accessToken", None) + access_token = result.read() + print(access_token) + # token = json.loads(result.read()) + # access_token = token.get("accessToken", None) if not access_token: raise Exception("Parse token from stdout failed, accessToken is None.") - # Parse token expires time from string - token_expires_on = token.get("expiresOn", "") - if token_expires_on: - print(f"Get token successfully. Token will expire on {token_expires_on}.") - return access_token except Exception as exception: