|
4 | 4 | import logging
|
5 | 5 | import re
|
6 | 6 | import time
|
7 |
| -from requests.exceptions import HTTPError |
| 7 | +from requests.exceptions import HTTPError, JSONDecodeError |
8 | 8 |
|
9 | 9 | from netfoundry.exceptions import UnknownResourceType, NetworkBoundaryViolation
|
10 | 10 |
|
@@ -1951,25 +1951,29 @@ def delete_resource(self, type: str, id: str = None, wait: int = 0, sleep: int =
|
1951 | 1951 | if response_code not in expected_responses:
|
1952 | 1952 | raise RuntimeError(f"got unexpected HTTP code {STATUS_CODES._codes[response_code][0].upper()} ({response_code}) and response {response.text}")
|
1953 | 1953 | 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}") |
1967 | 1958 | 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) |
1973 | 1977 |
|
1974 | 1978 |
|
1975 | 1979 | class Networks:
|
|
0 commit comments