diff --git a/watcher_dashboard/api/watcher.py b/watcher_dashboard/api/watcher.py index d29b787..01c6782 100644 --- a/watcher_dashboard/api/watcher.py +++ b/watcher_dashboard/api/watcher.py @@ -64,7 +64,7 @@ class Audit(base.APIDictWrapper): self._request = request @classmethod - def create(cls, request, audit_template_uuid, + def create(cls, request, name, audit_template_uuid, audit_type, auto_trigger=False, interval=None): """Create an audit in Watcher @@ -91,11 +91,11 @@ class Audit(base.APIDictWrapper): if interval: return watcherclient(request).audit.create( audit_template_uuid=audit_template_uuid, audit_type=audit_type, - auto_trigger=auto_trigger, interval=interval) + auto_trigger=auto_trigger, interval=interval, name=name) else: return watcherclient(request).audit.create( audit_template_uuid=audit_template_uuid, audit_type=audit_type, - auto_trigger=auto_trigger) + auto_trigger=auto_trigger, name=name) @classmethod def list(cls, request, **filters): diff --git a/watcher_dashboard/content/audits/forms.py b/watcher_dashboard/content/audits/forms.py index 60438e8..1417711 100644 --- a/watcher_dashboard/content/audits/forms.py +++ b/watcher_dashboard/content/audits/forms.py @@ -100,8 +100,8 @@ class CreateForm(forms.SelfHandlingForm): messages.success(request, message) return audit except Exception as exc: - if exc.http_status == 409: - msg = _('Quota exceeded for resource audit.') + if getattr(exc, 'http_status', None) == 409: + msg = _('Error: Audit name already exists.') else: msg = _('Failed to create audit.') LOG.info(exc) diff --git a/watcher_dashboard/test/api_tests/watcher_tests.py b/watcher_dashboard/test/api_tests/watcher_tests.py index 669fdf0..04fc75f 100644 --- a/watcher_dashboard/test/api_tests/watcher_tests.py +++ b/watcher_dashboard/test/api_tests/watcher_tests.py @@ -214,6 +214,7 @@ class WatcherAPITests(test.APITestCase): audit_template_id = self.api_audit_templates.first()['uuid'] audit_type = self.api_audits.first()['audit_type'] + audit_name = self.api_audits.first()['name'] audit_template_uuid = audit_template_id watcherclient = self.stub_watcherclient() @@ -221,17 +222,18 @@ class WatcherAPITests(test.APITestCase): return_value=audit) ret_val = api.watcher.Audit.create( - self.request, audit_template_uuid, audit_type) + self.request, audit_name, audit_template_uuid, audit_type) self.assertIsInstance(ret_val, dict) watcherclient.audit.create.assert_called_with( audit_template_uuid=audit_template_uuid, - audit_type=audit_type, auto_trigger=False) + audit_type=audit_type, auto_trigger=False, name=audit_name) def test_audit_create_with_interval(self): audit = self.api_audits.list()[1] audit_template_id = self.api_audit_templates.first()['uuid'] audit_type = self.api_audits.first()['audit_type'] + audit_name = self.api_audits.first()['name'] interval = audit['interval'] audit_template_uuid = audit_template_id @@ -240,19 +242,22 @@ class WatcherAPITests(test.APITestCase): return_value=audit) ret_val = api.watcher.Audit.create( - self.request, audit_template_uuid, audit_type, False, interval) + self.request, audit_name, audit_template_uuid, audit_type, + False, interval) self.assertIsInstance(ret_val, dict) watcherclient.audit.create.assert_called_with( audit_template_uuid=audit_template_uuid, audit_type=audit_type, auto_trigger=False, - interval=interval) + interval=interval, + name=audit_name) def test_audit_create_with_auto_trigger(self): audit = self.api_audits.list()[1] audit_template_id = self.api_audit_templates.first()['uuid'] audit_type = self.api_audits.first()['audit_type'] + audit_name = self.api_audits.first()['name'] audit_template_uuid = audit_template_id watcherclient = self.stub_watcherclient() @@ -260,12 +265,13 @@ class WatcherAPITests(test.APITestCase): return_value=audit) ret_val = api.watcher.Audit.create( - self.request, audit_template_uuid, audit_type, True) + self.request, audit_name, audit_template_uuid, audit_type, True) self.assertIsInstance(ret_val, dict) watcherclient.audit.create.assert_called_with( audit_template_uuid=audit_template_uuid, audit_type=audit_type, - auto_trigger=True) + auto_trigger=True, + name=audit_name) def test_audit_delete(self): audit_id = self.api_audits.first()['uuid'] diff --git a/watcher_dashboard/test/test_data/watcher_data.py b/watcher_dashboard/test/test_data/watcher_data.py index c715e56..e7284f4 100644 --- a/watcher_dashboard/test/test_data/watcher_data.py +++ b/watcher_dashboard/test/test_data/watcher_data.py @@ -123,12 +123,14 @@ def data(TEST): audit_dict = { 'uuid': '22222222-2222-2222-2222-222222222222', 'audit_type': 'ONESHOT', + 'name': 'Audit 1', 'audit_template_uuid': '11111111-1111-1111-1111-111111111111', 'interval': None, } audit_dict2 = { 'uuid': '33333333-3333-3333-3333-333333333333', 'audit_type': 'CONTINUOUS', + 'name': 'Audit 2', 'audit_template_uuid': '11111111-1111-1111-1111-111111111111', 'interval': 60, }