Better error handling of QP errors

Quick property URIs could sometimes not embed a response.  This is
generally an API issue and changes have gone into pypowervm for it.
However, nova-powervm should also be more tolerant of this.

This change supports better toleration in the event that the error
raised from the REST API does not have a proper response.

Change-Id: I490731a342a3045887a47c1051448e9cd2eabb15
Closes-Bug: 1635385
This commit is contained in:
Drew Thorstensen 2016-10-20 16:17:52 -04:00
parent 368977c164
commit af3aebdd8d
2 changed files with 12 additions and 8 deletions

View File

@ -300,8 +300,8 @@ class TestVM(test.TestCase):
self.assertEqual(inst_info.cpu_time_ns, 0)
# Check that we raise an exception if the instance is gone.
exc = pvm_exc.Error('Not found', response=FakeAdapterResponse(404))
self.apt.read.side_effect = exc
self.apt.read.side_effect = pvm_exc.HttpError(
mock.MagicMock(status=404))
self.assertRaises(exception.InstanceNotFound,
inst_info.__getattribute__, 'state')
@ -615,13 +615,16 @@ class TestVM(test.TestCase):
resp = mock.MagicMock()
resp.status = 404
self.apt.read.side_effect = pvm_exc.Error('message', response=resp)
self.apt.read.side_effect = pvm_exc.HttpError(resp)
self.assertRaises(exception.InstanceNotFound, vm.get_vm_qp, self.apt,
'lpar_uuid', log_errors=False)
resp.status = 500
self.apt.read.side_effect = pvm_exc.Error("message", response=None)
self.assertRaises(pvm_exc.Error, vm.get_vm_qp, self.apt,
'lpar_uuid', log_errors=False)
self.apt.read.side_effect = pvm_exc.Error('message', response=resp)
resp.status = 500
self.apt.read.side_effect = pvm_exc.Error("message", response=resp)
self.assertRaises(pvm_exc.Error, vm.get_vm_qp, self.apt,
'lpar_uuid', log_errors=False)

View File

@ -529,11 +529,12 @@ def get_vm_qp(adapter, lpar_uuid, qprop=None, log_errors=True):
pass
kwds['helpers'] = helpers
resp = adapter.read(pvm_lpar.LPAR.schema_type, **kwds)
except pvm_exc.Error as e:
if e.response.status == 404:
except pvm_exc.HttpError as e:
# 404 error indicates the LPAR has been deleted (or moved to a
# different host)
if e.response and e.response.status == 404:
raise exception.InstanceNotFound(instance_id=lpar_uuid)
else:
LOG.exception(e)
raise
return jsonutils.loads(resp.body)