Skip to content

Commit

Permalink
When api-server service unavialble,
Browse files Browse the repository at this point in the history
Retry to connect to api-server infinetly,while wait_for_connect is set to True by the clients.
Retries six times by default.

Change-Id: I1e00c843aca177cf775b1d1bdba58ad4f49a1089
Closes-Bug: 1445441
  • Loading branch information
cijohnson committed Apr 21, 2015
1 parent 182ebf7 commit c50fd34
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/api-lib/vnc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def __init__(self, username=None, password=None, tenant_name=None,
api_server_host='127.0.0.1', api_server_port='8082',
api_server_url=None, conf_file=None, user_info=None,
auth_token=None, auth_host=None, auth_port=None,
auth_protocol = None, auth_url=None, auth_type=None):
auth_protocol = None, auth_url=None, auth_type=None,
wait_for_connect=False):
# TODO allow for username/password to be present in creds file

super(VncApi, self).__init__(self._obj_serializer_diff)
Expand Down Expand Up @@ -201,15 +202,25 @@ def __init__(self, username=None, password=None, tenant_name=None,

self._create_api_server_session()

try:
homepage = self._request(rest.OP_GET, self._base_url,
retry_on_error=False)
self._cfg_root_url = self._parse_homepage(homepage)
except ServiceUnavailableError as e:
# Ignore http.code 503 here.
# _request_server will reconnect during requests
logger = logging.getLogger(__name__)
logger.warn("Exception: %s", str(e))
retry_count = 6
while retry_count:
try:
homepage = self._request(rest.OP_GET, self._base_url,
retry_on_error=False)
self._cfg_root_url = self._parse_homepage(homepage)
except ServiceUnavailableError as e:
logger = logging.getLogger(__name__)
logger.warn("Exception: %s", str(e))
if wait_for_connect:
# Retry connect infinitely when http retcode 503
continue
elif retry_count:
# Retry connect 60 times when http retcode 503
retry_count -= 1
time.sleep(1)
else:
# connected succesfully
break
#end __init__

def _obj_serializer_diff(self, obj):
Expand Down

0 comments on commit c50fd34

Please sign in to comment.