Fallback to the old /lookup endpoint on 401

Prior to this patch the ironic-python-agent service would only fallback
to use the old endpoints for /lookup and /heartbeat on a 404 error but,
since Ironic will check auth (if enabled) before it routes the requests
a 401 (Unauthorized) was returned.

Closes-Bug: #1612696
Change-Id: Idba5fed587e77aaa683d2c2b2126a520214712ce
This commit is contained in:
Lucas Alvares Gomes 2016-08-12 16:37:57 +01:00
parent 5f146d465d
commit 09d5d0c377
2 changed files with 11 additions and 3 deletions

View File

@ -122,7 +122,8 @@ class APIClient(object):
response = self._request('GET', self.lookup_api,
headers=self.ramdisk_api_headers,
params=params)
if response.status_code == requests.codes.NOT_FOUND:
if response.status_code in (requests.codes.NOT_FOUND,
requests.codes.UNAUTHORIZED):
# Assume that new API is not available and retry
LOG.warning('New API is not available, falling back to old '
'agent vendor passthru')

View File

@ -17,6 +17,7 @@ import json
import mock
from oslo_service import loopingcall
from oslotest import base as test_base
import requests
from ironic_python_agent import errors
from ironic_python_agent import hardware
@ -259,8 +260,8 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
self.assertFalse(error)
def test_do_lookup_fallback(self):
response0 = FakeResponse(status_code=404)
def _test_do_lookup_fallback(self, error_code):
response0 = FakeResponse(status_code=error_code)
response = FakeResponse(status_code=200, content={
'node': {
'uuid': 'deadbeef-dabb-ad00-b105-f00d00bab10c'
@ -346,3 +347,9 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
},
}, content['inventory'])
self.assertFalse(self.api_client.use_ramdisk_api)
def test_do_lookup_fallback_not_found(self):
self._test_do_lookup_fallback(error_code=requests.codes.NOT_FOUND)
def test_do_lookup_fallback_unauthorized(self):
self._test_do_lookup_fallback(error_code=requests.codes.UNAUTHORIZED)