Skip to content

Commit

Permalink
Expect 500 and 400 errors from Blazar (#65)
Browse files Browse the repository at this point in the history
Ensure we report when the cloud is considered full.
  • Loading branch information
JohnGarbutt authored Sep 10, 2024
1 parent f4e3fdc commit 979fdbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azimuth_schedule_operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def create_blazar_lease(blazar_client, lease_name, lease):
}
)
except httpx.HTTPStatusError as exc:
if exc.response.status_code == 400:
if exc.response.status_code in [400, 500]:
try:
message = exc.response.json()["error_message"]
except (json.JSONDecodeError, TypeError, KeyError):
Expand Down
18 changes: 18 additions & 0 deletions azimuth_schedule_operator/tests/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ async def test_create_blazar_lease_error_json_message(self):
)
blazar_client.resources["leases"].create.assert_awaited_once()

async def test_create_blazar_lease_error_json_message_500(self):
blazar_client = util.mock_openstack_client()
blazar_client.resources["leases"].create.side_effect = util.httpx_status_error(
500, json={"error_message": "this is an error from blazar 2"}
)

lease = lease_crd.Lease.model_validate(fake_lease())
with self.assertRaises(operator.BlazarLeaseCreateError) as ctx:
_ = await operator.create_blazar_lease(
blazar_client, f"az-{lease.metadata.name}", lease
)

self.assertEqual(
str(ctx.exception),
"error creating blazar lease - this is an error from blazar 2",
)
blazar_client.resources["leases"].create.assert_awaited_once()

async def test_create_blazar_lease_error_not_valid_json(self):
blazar_client = util.mock_openstack_client()
blazar_client.resources["leases"].create.side_effect = util.httpx_status_error(
Expand Down

0 comments on commit 979fdbb

Please sign in to comment.