Use proper response parsing instead of raise_for
This commit is contained in:
parent
02425159ef
commit
28b8b3bb44
|
@ -3389,18 +3389,17 @@ def vm_worker_send_snapshot(
|
||||||
"snapshot": snapshot_name,
|
"snapshot": snapshot_name,
|
||||||
"source_snapshot": incremental_parent,
|
"source_snapshot": incremental_parent,
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
response = session.post(
|
response = session.post(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
params=send_params,
|
params=send_params,
|
||||||
json=vm_detail,
|
json=vm_detail,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send config: {e}",
|
f"Failed to send config: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -3548,17 +3547,16 @@ def vm_worker_send_snapshot(
|
||||||
buffer[i],
|
buffer[i],
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
response = session.put(
|
response = session.put(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
files=files,
|
files=files,
|
||||||
stream=True,
|
stream=True,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send diff batch ({e}): {response.json()['message']}",
|
f"Failed to send diff batch: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -3655,8 +3653,7 @@ def vm_worker_send_snapshot(
|
||||||
params=send_params,
|
params=send_params,
|
||||||
data=full_chunker(),
|
data=full_chunker(),
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send snapshot: {response.json()['message']}",
|
f"Failed to send snapshot: {response.json()['message']}",
|
||||||
|
@ -3677,8 +3674,7 @@ def vm_worker_send_snapshot(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
params=send_params,
|
params=send_params,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send snapshot: {response.json()['message']}",
|
f"Failed to send snapshot: {response.json()['message']}",
|
||||||
|
@ -3983,18 +3979,17 @@ def vm_worker_create_mirror(
|
||||||
"snapshot": snapshot_name,
|
"snapshot": snapshot_name,
|
||||||
"source_snapshot": incremental_parent,
|
"source_snapshot": incremental_parent,
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
response = session.post(
|
response = session.post(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
params=send_params,
|
params=send_params,
|
||||||
json=vm_detail,
|
json=vm_detail,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send config: {e}",
|
f"Failed to send config: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -4142,17 +4137,16 @@ def vm_worker_create_mirror(
|
||||||
buffer[i],
|
buffer[i],
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
response = session.put(
|
response = session.put(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
files=files,
|
files=files,
|
||||||
stream=True,
|
stream=True,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send diff batch ({e}): {response.json()['message']}",
|
f"Failed to send diff batch: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -4249,8 +4243,7 @@ def vm_worker_create_mirror(
|
||||||
params=send_params,
|
params=send_params,
|
||||||
data=full_chunker(),
|
data=full_chunker(),
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to create mirror: {response.json()['message']}",
|
f"Failed to create mirror: {response.json()['message']}",
|
||||||
|
@ -4271,8 +4264,7 @@ def vm_worker_create_mirror(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
params=send_params,
|
params=send_params,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to create mirror: {response.json()['message']}",
|
f"Failed to create mirror: {response.json()['message']}",
|
||||||
|
@ -4610,18 +4602,17 @@ def vm_worker_promote_mirror(
|
||||||
"snapshot": snapshot_name,
|
"snapshot": snapshot_name,
|
||||||
"source_snapshot": incremental_parent,
|
"source_snapshot": incremental_parent,
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
response = session.post(
|
response = session.post(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/config",
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
params=send_params,
|
params=send_params,
|
||||||
json=vm_detail,
|
json=vm_detail,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send config: {e}",
|
f"Failed to send config: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -4769,17 +4760,16 @@ def vm_worker_promote_mirror(
|
||||||
buffer[i],
|
buffer[i],
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
response = session.put(
|
response = session.put(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
files=files,
|
files=files,
|
||||||
stream=True,
|
stream=True,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception as e:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to send diff batch ({e}): {response.json()['message']}",
|
f"Failed to send diff batch: {response.json()['message']}",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -4876,8 +4866,7 @@ def vm_worker_promote_mirror(
|
||||||
params=send_params,
|
params=send_params,
|
||||||
data=full_chunker(),
|
data=full_chunker(),
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to promote mirror: {response.json()['message']}",
|
f"Failed to promote mirror: {response.json()['message']}",
|
||||||
|
@ -4898,8 +4887,7 @@ def vm_worker_promote_mirror(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
params=send_params,
|
params=send_params,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to promote mirror: {response.json()['message']}",
|
f"Failed to promote mirror: {response.json()['message']}",
|
||||||
|
@ -4929,14 +4917,12 @@ def vm_worker_promote_mirror(
|
||||||
total=total_stages,
|
total=total_stages,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
response = session.post(
|
response = session.post(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/state",
|
f"{destination_api_uri}/vm/{vm_name}/state",
|
||||||
headers={"Content-Type": "application/octet-stream"},
|
headers={"Content-Type": "application/octet-stream"},
|
||||||
params={"state": previous_vm_state, "wait": True, "force": True},
|
params={"state": previous_vm_state, "wait": True, "force": True},
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
if response.status_code != 200:
|
||||||
except Exception:
|
|
||||||
fail(
|
fail(
|
||||||
celery,
|
celery,
|
||||||
f"Failed to promote mirror: {response.json()['message']}",
|
f"Failed to promote mirror: {response.json()['message']}",
|
||||||
|
|
Loading…
Reference in New Issue