Return None from get_server_by_id on 404

The interface for get_server_by_id SHOULD be None if not found
like the rest of the cloud layer. At some point in the past that
got broken. Fix it.

Change-Id: Ibd4fdc22418679c3562faaabe8fe3d307e8e8283
This commit is contained in:
Monty Taylor 2019-04-16 13:36:00 +00:00
parent 2e7a093893
commit e8e99af4d3
2 changed files with 22 additions and 4 deletions

View File

@ -27,6 +27,7 @@ from openstack.cloud import exc
from openstack.cloud import meta
from openstack.cloud import _normalize
from openstack.cloud import _utils
from openstack import exceptions
from openstack import proxy
from openstack import utils
@ -568,10 +569,20 @@ class ComputeCloudMixin(_normalize.Normalizer):
return meta.add_server_interfaces(self, server)
def get_server_by_id(self, id):
data = proxy._json_response(
self.compute.get('/servers/{id}'.format(id=id)))
server = self._get_and_munchify('server', data)
return meta.add_server_interfaces(self, self._normalize_server(server))
"""Get a server by ID.
:param id: ID of the server.
:returns: A server dict or None if no matching server is found.
"""
try:
data = proxy._json_response(
self.compute.get('/servers/{id}'.format(id=id)))
server = self._get_and_munchify('server', data)
return meta.add_server_interfaces(
self, self._normalize_server(server))
except exceptions.ResourceNotFound:
return None
def get_server_group(self, name_or_id=None, filters=None):
"""Get a server group by name or ID.

View File

@ -0,0 +1,7 @@
---
fixes:
- |
The ``get_server_by_id`` method is supposed to return ``None`` if the
server in question can't be found, but a regression was introduced
causing it to raise ``ResourceNotFound`` instead. This has been corrected
and ``get_server_by_id`` returns ``None`` correctly again.