Fix trains-agent init (max two verification retries, then print error)

This commit is contained in:
allegroai 2020-06-11 15:39:38 +03:00
parent ff6272f48f
commit 473a8de8bb
2 changed files with 8 additions and 5 deletions
trains_agent
backend_api/session
commands

View File

@ -85,6 +85,7 @@ class Session(TokenManager):
initialize_logging=True, initialize_logging=True,
client=None, client=None,
config=None, config=None,
http_retries_config=None,
**kwargs **kwargs
): ):
# add backward compatibility support for old environment variables # add backward compatibility support for old environment variables
@ -129,7 +130,7 @@ class Session(TokenManager):
raise ValueError("host is required in init or config") raise ValueError("host is required in init or config")
self.__host = host.strip("/") self.__host = host.strip("/")
http_retries_config = self.config.get( http_retries_config = http_retries_config or self.config.get(
"api.http.retries", ConfigTree() "api.http.retries", ConfigTree()
).as_plain_ordered_dict() ).as_plain_ordered_dict()
http_retries_config["status_forcelist"] = self._retry_codes http_retries_config["status_forcelist"] = self._retry_codes

View File

@ -233,7 +233,8 @@ def verify_credentials(api_host, credentials):
try: try:
print('Verifying credentials ...') print('Verifying credentials ...')
if api_host: if api_host:
Session(api_key=credentials['access_key'], secret_key=credentials['secret_key'], host=api_host) Session(api_key=credentials['access_key'], secret_key=credentials['secret_key'], host=api_host,
http_retries_config={"total": 2})
print('Credentials verified!') print('Credentials verified!')
return True return True
else: else:
@ -275,7 +276,7 @@ def read_manual_credentials():
def input_url(host_type, host=None): def input_url(host_type, host=None):
while True: while True:
print('{} configured to: [{}] '.format(host_type, host), end='') print('{} configured to: {}'.format(host_type, '[{}] '.format(host) if host else ''), end='')
parse_input = input() parse_input = input()
if host and (not parse_input or parse_input.lower() == 'yes' or parse_input.lower() == 'y'): if host and (not parse_input or parse_input.lower() == 'yes' or parse_input.lower() == 'y'):
break break
@ -289,11 +290,12 @@ def input_url(host_type, host=None):
def input_host_port(host_type, parsed_host): def input_host_port(host_type, parsed_host):
print('Enter port for {} host '.format(host_type), end='') print('Enter port for {} host '.format(host_type), end='')
replace_port = input().lower() replace_port = input().lower()
return parsed_host.scheme + "://" + parsed_host.netloc + (':{}'.format(replace_port) if replace_port else '') + \ return parsed_host.scheme + "://" + parsed_host.netloc + (
parsed_host.path ':{}'.format(replace_port) if replace_port else '') + parsed_host.path
def verify_url(parse_input): def verify_url(parse_input):
# noinspection PyBroadException
try: try:
if not parse_input.startswith('http://') and not parse_input.startswith('https://'): if not parse_input.startswith('http://') and not parse_input.startswith('https://'):
# if we have a specific port, use http prefix, otherwise assume https # if we have a specific port, use http prefix, otherwise assume https