diff --git a/azimuth_schedule_operator/operator.py b/azimuth_schedule_operator/operator.py index 82bac1a..83f25e6 100644 --- a/azimuth_schedule_operator/operator.py +++ b/azimuth_schedule_operator/operator.py @@ -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): diff --git a/azimuth_schedule_operator/tests/test_lease.py b/azimuth_schedule_operator/tests/test_lease.py index 37422b0..68a2c66 100644 --- a/azimuth_schedule_operator/tests/test_lease.py +++ b/azimuth_schedule_operator/tests/test_lease.py @@ -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(