Remove @safe_connect from put_allocations

The only user of put_allocations of the report client is
heal_allocations. It is easy to remove the @safe_connect decorator
from put_allocations as heal_allocations already handles
PlacementAPIConnectFailure exception.

This patch changes heal_allocations to raise
PlacementAPIConnectFailure instead of relying on @safe_connect.

Change-Id: I6b3f61525883a019703cf564e693516b3b61febc
This commit is contained in:
Balazs Gibizer 2019-10-04 13:54:03 +02:00
parent bf37bec80b
commit 15c71ccf8e
2 changed files with 15 additions and 5 deletions

View File

@ -1913,8 +1913,6 @@ class SchedulerReportClient(object):
'text': r.text})
return r.status_code == 204
# TODO(gibi): kill safe_connect
@safe_connect
@retries
def put_allocations(self, context, consumer_uuid, payload):
"""Creates allocation records for the supplied consumer UUID based on
@ -1926,12 +1924,18 @@ class SchedulerReportClient(object):
PUT /allocations/{consumer_uuid} API
:returns: True if the allocations were created, False otherwise.
:raises: Retry if the operation should be retried due to a concurrent
resource provider update.
resource provider update.
:raises: AllocationUpdateFailed if placement returns a consumer
generation conflict
generation conflict
:raises: PlacementAPIConnectFailure on failure to communicate with the
placement API
"""
r = self._put_allocations(context, consumer_uuid, payload)
try:
r = self._put_allocations(context, consumer_uuid, payload)
except ks_exc.ClientException:
raise exception.PlacementAPIConnectFailure()
if r.status_code != 204:
err = r.json()['errors'][0]
# NOTE(jaypipes): Yes, it sucks doing string comparison like this

View File

@ -309,6 +309,12 @@ class TestPutAllocations(SchedulerReportClientTestCase):
log_msg = mock_warn.call_args[0][0]
self.assertIn("Failed to save allocation for", log_msg)
def test_put_allocations_fail_connection_error(self):
self.ks_adap_mock.put.side_effect = ks_exc.EndpointNotFound()
self.assertRaises(
exception.PlacementAPIConnectFailure, self.client.put_allocations,
self.context, mock.sentinel.consumer, mock.sentinel.payload)
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.put')
def test_put_allocations_fail_due_to_consumer_generation_conflict(
self, mock_put):