Skip to content

Commit

Permalink
Merge pull request #1604 from zhaoqin-github/connection-aborted-3.0.11
Browse files Browse the repository at this point in the history
Handles ConnectionAborted errors (3.0.11)
  • Loading branch information
zhaoqin-github authored Sep 21, 2022
2 parents 70e1ec1 + 716e3d4 commit 9608262
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
94 changes: 80 additions & 14 deletions f5/bigip/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,19 @@ def _modify(self, **patch):
raise AttemptedMutationOfReadOnly(msg)

patch = self._prepare_request_json(patch)
response = session.patch(patch_uri, json=patch, **requests_params)

# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = session.patch(patch_uri, json=patch, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

self._local_update(response.json())

def modify(self, **patch):
Expand Down Expand Up @@ -574,7 +586,7 @@ def _update(self, **kwargs):
#
# @see https://github.com/F5Networks/f5-ansible/issues/317
# @see https://github.com/requests/requests/issues/2364
for _ in range(0, 30):
for i in range(0, 30):
try:
response = session.put(update_uri, json=data_dict, **requests_params)
self._meta_data = temp_meta
Expand All @@ -586,7 +598,7 @@ def _update(self, **kwargs):
self._local_update(response.json())
raise
except ConnectionError as ex:
if 'Connection aborted' in str(ex):
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
Expand Down Expand Up @@ -630,7 +642,18 @@ def _refresh(self, **kwargs):
else:
uri = self._meta_data['uri']

response = refresh_session.get(uri, **requests_params)
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = refresh_session.get(uri, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

self._local_update(response.json())

def refresh(self, **kwargs):
Expand Down Expand Up @@ -967,7 +990,17 @@ def _create(self, **kwargs):
kwargs = self._prepare_request_json(kwargs)

# Invoke the REST operation on the device.
response = session.post(_create_uri, json=kwargs, **requests_params)
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = session.post(_create_uri, json=kwargs, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

# Make new instance of self
result = self._produce_instance(response)
Expand Down Expand Up @@ -1036,7 +1069,19 @@ def _load(self, **kwargs):
for key1, key2 in self._meta_data['reduction_forcing_pairs']:
kwargs = self._reduce_boolean_pair(kwargs, key1, key2)
kwargs = self._check_for_python_keywords(kwargs)
response = refresh_session.get(base_uri, **kwargs)

# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = refresh_session.get(base_uri, **kwargs)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

# Make new instance of self
return self._produce_instance(response)

Expand Down Expand Up @@ -1076,7 +1121,18 @@ def _delete(self, **kwargs):
if not force:
self._check_generation()

response = session.delete(delete_uri, **requests_params)
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = session.delete(delete_uri, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

if response.status_code == 200:
self.__dict__ = {'deleted': True}

Expand Down Expand Up @@ -1138,13 +1194,23 @@ def _exists(self, **kwargs):
base_uri = self._meta_data['container']._meta_data['uri']
kwargs.update(requests_params)

try:
session.get(base_uri, **kwargs)
except HTTPError as err:
if err.response.status_code == 404:
return False
else:
raise
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
session.get(base_uri, **kwargs)
break
except HTTPError as err:
if err.response.status_code == 404:
return False
else:
raise
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
time.sleep(1)
continue
else:
raise

return True


Expand Down
2 changes: 1 addition & 1 deletion f5/bigip/tm/ltm/test/functional/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_delete(self, request, mgmt_root, NAT):
setup_loadable_nat_test(request, mgmt_root, NAT)
n1 = mgmt_root.tm.ltm.nats.nat.load(name='nat1', partition='Common')
n1.delete()
del(n1)
del n1
with pytest.raises(HTTPError) as err:
mgmt_root.tm.ltm.nats.nat.load(name='nat1', partition='Common')
assert err.response.status_code == 404
Expand Down

0 comments on commit 9608262

Please sign in to comment.