Merge "Add name for audit: check if audit_name already exists"
This commit is contained in:
commit
74b06fd025
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue