Merge "Kill @safe_connect in _get_provider_traits"

This commit is contained in:
Zuul 2019-01-25 14:06:00 +00:00 committed by Gerrit Code Review
commit f8c260864e
2 changed files with 16 additions and 3 deletions

View File

@ -447,7 +447,6 @@ class SchedulerReportClient(object):
LOG.error(msg, args)
raise exception.ResourceProviderAggregateRetrievalFailed(uuid=rp_uuid)
@safe_connect
def _get_provider_traits(self, context, rp_uuid):
"""Queries the placement API for a resource provider's traits.
@ -460,6 +459,8 @@ class SchedulerReportClient(object):
:raise: ResourceProviderTraitRetrievalFailed on errors. In particular,
we raise this exception (as opposed to returning None or the
empty set()) if the specified resource provider does not exist.
:raise: keystoneauth1.exceptions.ClientException if placement API
communication fails.
"""
resp = self.get("/resource_providers/%s/traits" % rp_uuid,
version='1.6', global_request_id=context.global_id)
@ -831,6 +832,8 @@ class SchedulerReportClient(object):
- ResourceProviderAggregateRetrievalFailed
- ResourceProviderTraitRetrievalFailed
- ResourceProviderRetrievalFailed
:raise: keystoneauth1.exceptions.ClientException if placement API
communication fails.
"""
if force or self._associations_stale(rp_uuid):
# Refresh aggregates
@ -849,8 +852,6 @@ class SchedulerReportClient(object):
# Refresh traits
trait_info = self._get_provider_traits(context, rp_uuid)
# If @safe_connect makes the above return None, this will raise
# TypeError. Good.
traits, generation = trait_info.traits, trait_info.generation
msg = ("Refreshing trait associations for resource provider %s, "
"traits: %s")

View File

@ -2685,6 +2685,18 @@ class TestTraits(SchedulerReportClientTestCase):
self.ks_adap_mock.get.reset_mock()
log_mock.reset_mock()
def test_get_provider_traits_placement_comm_error(self):
"""ksa ClientException raises through."""
uuid = uuids.compute_node
self.ks_adap_mock.get.side_effect = ks_exc.EndpointNotFound()
self.assertRaises(ks_exc.ClientException,
self.client._get_provider_traits, self.context, uuid)
expected_url = '/resource_providers/' + uuid + '/traits'
self.ks_adap_mock.get.assert_called_once_with(
expected_url,
headers={'X-Openstack-Request-Id': self.context.global_id},
**self.trait_api_kwargs)
def test_ensure_traits(self):
"""Successful paths, various permutations of traits existing or needing
to be created.