Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update share test, production manila audit map, add debug for tox #94

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions auditmiddleware/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ def _build_events(self, target_project, res_spec, res_id, res_parent_id,
path: URL path being parsed
cursor: current position in the path as it is parsed
"""
self._log.debug("_build_events: path=%(path)s, cursor=%(cursor)s, "
"res_spec=%(res_spec)s, res_id=%(res_id)s",
{'path': path, 'cursor': cursor,
'res_spec': res_spec, 'res_id': res_id})
# Check if the end of path is reached and event can be created finally
if cursor == -1:
# end of path reached, create the event
Expand Down Expand Up @@ -630,6 +634,10 @@ def _attach_payload(event, payload, res_spec):
def _create_target_resource(self, target_project, res_spec, res_id,
res_parent_id=None, payload=None, key=None):
"""Build the event's target element from the payload."""
self._log.debug("_create_target_resource: res_spec=%(res_spec)s, "
"res_id=%(res_id)s, res_parent_id=%(res_parent_id)s",
{'res_spec': res_spec, 'res_id': res_id,
'res_parent_id': res_parent_id})
project_id = target_project
rid = res_id
name = None
Expand Down Expand Up @@ -684,6 +692,9 @@ def _get_action_and_key(self, res_spec, res_id, request, suffix):
request: the request
suffix: the last path component (already known)
"""
self._log.debug("_get_action_and_key: res_spec=%(res_spec)s, "
"res_id=%(res_id)s, suffix=%(suffix)s",
{'res_spec': res_spec, 'res_id': res_id, 'suffix': suffix})
if suffix is None:
return self._get_action_from_method(request.method, res_spec,
res_id), None
Expand Down Expand Up @@ -731,9 +742,12 @@ def _get_action_and_key_from_path_suffix(self, path_suffix, method,
# action suppressed by intention
return None, None

# no action mapped to suffix => custom key
# no action mapped to suffix => custom key operation
action = self._get_action_from_method(method, res_spec, res_id)
action += _key_action_suffix_map[action]

if action in _key_action_suffix_map:
action += _key_action_suffix_map[action]

return action, path_suffix

def _get_action_from_payload(self, request, res_spec, res_id):
Expand Down
2 changes: 2 additions & 0 deletions auditmiddleware/tests/unit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import auditmiddleware
from auditmiddleware._api import _make_tags
from auditmiddleware.tests.unit import utils
import logging
from mock import mock
from oslo_config import fixture as cfg_fixture
from oslo_messaging import conffixture as msg_fixture
Expand All @@ -24,6 +25,7 @@
import webob
import webob.dec

logging.basicConfig(level=logging.DEBUG)

iso8601 = r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}[+-]\d\d:\d\d$'

Expand Down
8 changes: 4 additions & 4 deletions auditmiddleware/tests/unit/test_http_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_get_request(self):
event['requestPath'] = mock_request.path

self.check_event(mock_request, mock_response, event, 'read',
'compute/server',
'compute/server',
'00000000-0000-0000-0000-00000000007b',
None, 'success')
self.assertEqual(event['initiator']['id'], self.user_id)
Expand All @@ -69,7 +69,7 @@ def test_post_request(self):
mock_response = MagicMock()
mock_response.status_int = 202
mock_response.status_code = 202
mock_response.content_length = 100
mock_response.content_length = 100
mock_response.content_type = 'application/json'
mock_response.json = {'server': {'id': 'xyz'}}
mock_response.text = '{"server": {"id": "xyz"}}'
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_delete_request_with_no_content_length(self):
event['requestPath'] = mock_request.path

self.check_event(mock_request, mock_response, event, 'delete',
'compute/server',
'compute/server',
'00000000-0000-0000-0000-00000000007b',
None, 'success')
self.assertEqual(event['initiator']['id'], self.user_id)
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_update_request(self):
event['requestPath'] = mock_request.path

self.check_event(mock_request, mock_response, event, 'update',
'compute/server',
'compute/server',
'00000000-0000-0000-0000-00000000007b',
None, 'success')
self.assertEqual(event['initiator']['id'], self.user_id)
Expand Down
2 changes: 2 additions & 0 deletions auditmiddleware/tests/unit/test_logging_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def setUp(self):

def test_api_request_no_messaging(self):
"""Test that logging works and event_type is correct."""
self.cfg.config(use_oslo_messaging=False,
group='audit_middleware_notifications')
app = self.create_simple_app()

with mock.patch('auditmiddleware._LOG.info') as log:
Expand Down
13 changes: 5 additions & 8 deletions auditmiddleware/tests/unit/test_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,14 @@ def audit_map(self):
return self.audit_map_file_fixture

def test_get_list_shares(self):
"""Test listing resource instances.

This is just a arbitary smoke-test for Manila.
"""
url = self.build_url('shares', prefix='/v2/' + self.project_id)
"""Test a list action for Manila shares."""
url = self.build_url('shares', prefix='/v2')
request, response = self.build_api_call('GET', url)
event = self.build_event(request, response)

self.check_event(request, response, event, taxonomy.ACTION_LIST,
"storage/share/shares",
None, self.service_name)
self.check_event(request, response, event, 'read/list',
"storage/share/shares",
None, self.service_name)


class DesignateAuditMappingTest(base.BaseAuditMiddlewareTest):
Expand Down
5 changes: 4 additions & 1 deletion etc/manila_audit_map.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
service_type: 'storage/share'
service_name: 'manila'

prefix: '/v[0-9\.]*'
prefix: '/v[1-2]'

resources:
availability-zones:
Expand All @@ -19,6 +19,9 @@ resources:
pools:
security-services:
# model details listing a action
payloads:
exclude:
- password
custom_actions:
detail: read/list/details
services:
Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ deps =
-c{toxinidir}/lower-constraints.txt
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
setenv =
PYTHONWARNINGS = ignore
PYTHON_LOGGER_LEVEL = DEBUG

[testenv:lint]
deps =
flake8
commands =
flake8 {posargs}
Loading