Merge "Add auto_trigger option in Audit creation form"
This commit is contained in:
commit
51b0d8be95
@ -65,7 +65,7 @@ class Audit(base.APIDictWrapper):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, request, audit_template_uuid,
|
def create(cls, request, audit_template_uuid,
|
||||||
audit_type, interval=None):
|
audit_type, auto_trigger=False, interval=None):
|
||||||
|
|
||||||
"""Create an audit in Watcher
|
"""Create an audit in Watcher
|
||||||
|
|
||||||
@ -88,10 +88,11 @@ class Audit(base.APIDictWrapper):
|
|||||||
if interval:
|
if interval:
|
||||||
return watcherclient(request).audit.create(
|
return watcherclient(request).audit.create(
|
||||||
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
||||||
interval=interval)
|
auto_trigger=auto_trigger, interval=interval)
|
||||||
else:
|
else:
|
||||||
return watcherclient(request).audit.create(
|
return watcherclient(request).audit.create(
|
||||||
audit_template_uuid=audit_template_uuid, audit_type=audit_type)
|
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
||||||
|
auto_trigger=auto_trigger)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def list(cls, request, **filters):
|
def list(cls, request, **filters):
|
||||||
|
@ -69,6 +69,7 @@ class LaunchAudit(horizon.tables.BatchAction):
|
|||||||
def action(self, request, obj_id):
|
def action(self, request, obj_id):
|
||||||
params = {'audit_template_uuid': obj_id}
|
params = {'audit_template_uuid': obj_id}
|
||||||
params['audit_type'] = 'ONESHOT'
|
params['audit_type'] = 'ONESHOT'
|
||||||
|
params['auto_trigger'] = False
|
||||||
watcher.Audit.create(request, **params)
|
watcher.Audit.create(request, **params)
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ class CreateForm(forms.SelfHandlingForm):
|
|||||||
_("Interval (format hh:mm:ss)")}),
|
_("Interval (format hh:mm:ss)")}),
|
||||||
required=True)
|
required=True)
|
||||||
failure_url = 'horizon:admin:audits:index'
|
failure_url = 'horizon:admin:audits:index'
|
||||||
|
auto_trigger = forms.BooleanField(label=_("Auto Trigger"),
|
||||||
|
required=False)
|
||||||
|
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
super(CreateForm, self).__init__(request, *args, **kwargs)
|
super(CreateForm, self).__init__(request, *args, **kwargs)
|
||||||
@ -85,6 +87,7 @@ class CreateForm(forms.SelfHandlingForm):
|
|||||||
try:
|
try:
|
||||||
params = {'audit_template_uuid': data['audit_template']}
|
params = {'audit_template_uuid': data['audit_template']}
|
||||||
params['audit_type'] = data['audit_type'].upper()
|
params['audit_type'] = data['audit_type'].upper()
|
||||||
|
params['auto_trigger'] = data['auto_trigger']
|
||||||
if data['audit_type'] == 'continuous':
|
if data['audit_type'] == 'continuous':
|
||||||
params['interval'] = int(data['interval'].total_seconds())
|
params['interval'] = int(data['interval'].total_seconds())
|
||||||
else:
|
else:
|
||||||
|
@ -122,6 +122,9 @@ class AuditsTable(horizon.tables.DataTable):
|
|||||||
audit_type = horizon.tables.Column(
|
audit_type = horizon.tables.Column(
|
||||||
'audit_type',
|
'audit_type',
|
||||||
verbose_name=_('Audit Type'))
|
verbose_name=_('Audit Type'))
|
||||||
|
auto_trigger = horizon.tables.Column(
|
||||||
|
'auto_trigger',
|
||||||
|
verbose_name=_('Auto Trigger'))
|
||||||
status = horizon.tables.Column(
|
status = horizon.tables.Column(
|
||||||
'state',
|
'state',
|
||||||
verbose_name=_('State'),
|
verbose_name=_('State'),
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
{% block modal-body-right %}
|
{% block modal-body-right %}
|
||||||
<h3>{% trans "Description:" %}</h3>
|
<h3>{% trans "Description:" %}</h3>
|
||||||
<p>{% trans "Creates a audit with specified parameters." %}</p>
|
<p>{% trans "Creates a audit with specified parameters." %}</p>
|
||||||
|
<p>{% trans "If you check 'Auto Trigger' option, the action plan, recommended by the audit, will be automatically started." %}</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
<dd>{{ audit.strategy_name|default:"—" }}</dd>
|
<dd>{{ audit.strategy_name|default:"—" }}</dd>
|
||||||
<dt>{% trans "Type" %}</dt>
|
<dt>{% trans "Type" %}</dt>
|
||||||
<dd>{{ audit.audit_type|default:"—" }}</dd>
|
<dd>{{ audit.audit_type|default:"—" }}</dd>
|
||||||
|
<dt>{% trans "Auto Trigger" %}</dt>
|
||||||
|
<dd>{{ audit.auto_trigger }}</dd>
|
||||||
{% url 'horizon:admin:audit_templates:detail' audit.audit_template_uuid as audit_template_url %}
|
{% url 'horizon:admin:audit_templates:detail' audit.audit_template_uuid as audit_template_url %}
|
||||||
<dt>{% trans "State" %}</dt>
|
<dt>{% trans "State" %}</dt>
|
||||||
<dd>{{ audit.state|default:"—" }}</dd>
|
<dd>{{ audit.state|default:"—" }}</dd>
|
||||||
|
@ -217,7 +217,7 @@ class WatcherAPITests(test.APITestCase):
|
|||||||
watcherclient.audit = self.mox.CreateMockAnything()
|
watcherclient.audit = self.mox.CreateMockAnything()
|
||||||
watcherclient.audit.create(
|
watcherclient.audit.create(
|
||||||
audit_template_uuid=audit_template_uuid,
|
audit_template_uuid=audit_template_uuid,
|
||||||
audit_type=audit_type).AndReturn(audit)
|
audit_type=audit_type, auto_trigger=False).AndReturn(audit)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
ret_val = api.watcher.Audit.create(
|
ret_val = api.watcher.Audit.create(
|
||||||
@ -237,11 +237,31 @@ class WatcherAPITests(test.APITestCase):
|
|||||||
watcherclient.audit.create(
|
watcherclient.audit.create(
|
||||||
audit_template_uuid=audit_template_uuid,
|
audit_template_uuid=audit_template_uuid,
|
||||||
audit_type=audit_type,
|
audit_type=audit_type,
|
||||||
|
auto_trigger=False,
|
||||||
interval=interval).AndReturn(audit)
|
interval=interval).AndReturn(audit)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
ret_val = api.watcher.Audit.create(
|
ret_val = api.watcher.Audit.create(
|
||||||
self.request, audit_template_uuid, audit_type, interval)
|
self.request, audit_template_uuid, audit_type, False, interval)
|
||||||
|
self.assertIsInstance(ret_val, dict)
|
||||||
|
|
||||||
|
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_template_uuid = audit_template_id
|
||||||
|
|
||||||
|
watcherclient = self.stub_watcherclient()
|
||||||
|
watcherclient.audit = self.mox.CreateMockAnything()
|
||||||
|
watcherclient.audit.create(
|
||||||
|
audit_template_uuid=audit_template_uuid,
|
||||||
|
audit_type=audit_type,
|
||||||
|
auto_trigger=True).AndReturn(audit)
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
ret_val = api.watcher.Audit.create(
|
||||||
|
self.request, audit_template_uuid, audit_type, True)
|
||||||
self.assertIsInstance(ret_val, dict)
|
self.assertIsInstance(ret_val, dict)
|
||||||
|
|
||||||
def test_audit_delete(self):
|
def test_audit_delete(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user