summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Martinelli <stevemar@ca.ibm.com>2014-07-23 14:10:54 -0400
committerSteve Martinelli <stevemar@ca.ibm.com>2015-02-06 17:46:42 -0500
commita568c12219db0390d90843274b07a97af6a6743b (patch)
tree4e433ed2817b133b40fb554fb40e8afcad2e12eb
parentd71697f9cd41c22e0821782ae2c7ad215dd0c0b0 (diff)
downloadpycadf-a568c12219db0390d90843274b07a97af6a6743b.tar.gz
Do not depend on endpoint id existing in the service catalog
Currently, if the endpoint id does not exist, pycadf will break. This patch will attempt to find the id of the endpoint and if not found, set it to unknown. Closes-Bug: #1347868 Change-Id: Ief7facfca79f4f4e7c550c8f2317745e0c8e41ea
-rw-r--r--pycadf/audit/api.py6
-rw-r--r--pycadf/tests/audit/test_api.py34
2 files changed, 39 insertions, 1 deletions
diff --git a/pycadf/audit/api.py b/pycadf/audit/api.py
index 909b182..e245f7e 100644
--- a/pycadf/audit/api.py
+++ b/pycadf/audit/api.py
@@ -180,12 +180,16 @@ class OpenStackAuditApi(object):
return action
def _get_service_info(self, endp):
+ # NOTE(stevemar): The catalog returned by X-Service-Catalog
+ # does not include IDs for endpoints, use the service name
+ # as a backup.
+ endpoint_id = endp['endpoints'][0].get('id', endp['name'])
service = self.Service(
type=self._MAP.service_endpoints.get(
endp['type'],
taxonomy.UNKNOWN),
name=endp['name'],
- id=identifier.norm_ns(endp['endpoints'][0]['id']),
+ id=identifier.norm_ns(endpoint_id),
admin_endp=endpoint.Endpoint(
name='admin',
url=endp['endpoints'][0]['adminURL']),
diff --git a/pycadf/tests/audit/test_api.py b/pycadf/tests/audit/test_api.py
index e434253..548ca84 100644
--- a/pycadf/tests/audit/test_api.py
+++ b/pycadf/tests/audit/test_api.py
@@ -40,6 +40,23 @@ class TestAuditApi(base.TestCase):
'HTTP_X_PROJECT_ID': 'tenant_id',
'HTTP_X_IDENTITY_STATUS': 'Confirmed'}
+ ENV_HEADERS_NO_ID = {'HTTP_X_SERVICE_CATALOG':
+ '''[{"endpoints_links": [],
+ "endpoints": [{"adminURL":
+ "http://admin_host:8774",
+ "region": "RegionOne",
+ "publicURL":
+ "http://public_host:8775",
+ "internalURL":
+ "http://internal_host:8776"}],
+ "type": "compute",
+ "name": "nova"}]''',
+ 'HTTP_X_USER_ID': 'user_id',
+ 'HTTP_X_USER_NAME': 'user_name',
+ 'HTTP_X_AUTH_TOKEN': 'token',
+ 'HTTP_X_PROJECT_ID': 'tenant_id',
+ 'HTTP_X_IDENTITY_STATUS': 'Confirmed'}
+
def setUp(self):
super(TestAuditApi, self).setUp()
self.audit_api = api.OpenStackAuditApi(
@@ -53,6 +70,14 @@ class TestAuditApi(base.TestCase):
self.assertIn('CADF_EVENT_CORRELATION_ID', req.environ)
return req
+ def api_request_missing_id(self, method, url):
+ self.ENV_HEADERS_NO_ID['REQUEST_METHOD'] = method
+ req = webob.Request.blank(url, environ=self.ENV_HEADERS_NO_ID,
+ remote_addr='192.168.0.1')
+ self.audit_api.append_audit_event(req)
+ self.assertIn('CADF_EVENT_CORRELATION_ID', req.environ)
+ return req
+
def test_get_list_with_cfg(self):
cfg.CONF.set_override(
'api_audit_map',
@@ -121,6 +146,15 @@ class TestAuditApi(base.TestCase):
self.assertEqual(payload['target']['id'], 'unknown')
self.assertEqual(payload['target']['typeURI'], 'unknown')
+ def test_templated_catalog(self):
+ url = 'http://admin_host:8774/v2/' + str(uuid.uuid4()) + '/servers'
+ req = self.api_request_missing_id('GET', url)
+ payload = req.environ['CADF_EVENT']
+ self.assertEqual(payload['target']['id'], 'openstack:nova')
+ self.assertEqual(payload['target']['name'], 'nova')
+ self.assertEqual(payload['target']['typeURI'],
+ 'service/compute/servers')
+
def test_get_unknown_endpoint_default_set(self):
tmpfile = self.temp_config_file_path()
with open(tmpfile, "w") as f: