Skip to content

Commit df0331c

Browse files
committed
stop expecting a JSON body for DELETE requests
1 parent 31642be commit df0331c

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

netfoundry/network.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import re
66
import time
7-
from requests.exceptions import HTTPError
7+
from requests.exceptions import HTTPError, JSONDecodeError
88

99
from netfoundry.exceptions import UnknownResourceType, NetworkBoundaryViolation
1010

@@ -1951,25 +1951,29 @@ def delete_resource(self, type: str, id: str = None, wait: int = 0, sleep: int =
19511951
if response_code not in expected_responses:
19521952
raise RuntimeError(f"got unexpected HTTP code {STATUS_CODES._codes[response_code][0].upper()} ({response_code}) and response {response.text}")
19531953
else:
1954-
resource = response.json()
1955-
1956-
if resource.get('_links') and resource['_links'].get('process-executions'):
1957-
_links = resource['_links'].get('process-executions')
1958-
if isinstance(_links, list):
1959-
process_id = _links[0]['href'].split('/')[6]
1960-
else:
1961-
process_id = _links['href'].split('/')[6]
1962-
if wait:
1963-
self.wait_for_statuses(expected_statuses=RESOURCES["process-executions"].status_symbols['complete'], type="process-executions", id=process_id, wait=wait, sleep=sleep)
1964-
return(True)
1965-
else: # only wait for the process to start, not finish, or timeout
1966-
self.wait_for_statuses(expected_statuses=RESOURCES['process-executions'].status_symbols['progress'] + RESOURCES['process-executions'].status_symbols['complete'], type="process-executions", id=process_id, wait=9, sleep=2)
1954+
try:
1955+
resource = response.json()
1956+
except JSONDecodeError as e:
1957+
logging.debug("ignoring {e}")
19671958
return(True)
1968-
elif wait:
1969-
logging.warning("unable to wait for async complete because response did not provide a process execution id")
1970-
return(False)
1971-
else:
1972-
return(True)
1959+
else:
1960+
if resource.get('_links') and resource['_links'].get('process-executions'):
1961+
_links = resource['_links'].get('process-executions')
1962+
if isinstance(_links, list):
1963+
process_id = _links[0]['href'].split('/')[6]
1964+
else:
1965+
process_id = _links['href'].split('/')[6]
1966+
if wait:
1967+
self.wait_for_statuses(expected_statuses=RESOURCES["process-executions"].status_symbols['complete'], type="process-executions", id=process_id, wait=wait, sleep=sleep)
1968+
return(True)
1969+
else: # only wait for the process to start, not finish, or timeout
1970+
self.wait_for_statuses(expected_statuses=RESOURCES['process-executions'].status_symbols['progress'] + RESOURCES['process-executions'].status_symbols['complete'], type="process-executions", id=process_id, wait=9, sleep=2)
1971+
return(True)
1972+
elif wait:
1973+
logging.warning("unable to wait for async complete because response did not provide a process execution id")
1974+
return(False)
1975+
else:
1976+
return(True)
19731977

19741978

19751979
class Networks:

0 commit comments

Comments
 (0)