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
|
||||
def create(cls, request, audit_template_uuid,
|
||||
audit_type, interval=None):
|
||||
audit_type, auto_trigger=False, interval=None):
|
||||
|
||||
"""Create an audit in Watcher
|
||||
|
||||
@ -88,10 +88,11 @@ class Audit(base.APIDictWrapper):
|
||||
if interval:
|
||||
return watcherclient(request).audit.create(
|
||||
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
||||
interval=interval)
|
||||
auto_trigger=auto_trigger, interval=interval)
|
||||
else:
|
||||
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
|
||||
def list(cls, request, **filters):
|
||||
|
@ -69,6 +69,7 @@ class LaunchAudit(horizon.tables.BatchAction):
|
||||
def action(self, request, obj_id):
|
||||
params = {'audit_template_uuid': obj_id}
|
||||
params['audit_type'] = 'ONESHOT'
|
||||
params['auto_trigger'] = False
|
||||
watcher.Audit.create(request, **params)
|
||||
|
||||
|
||||
|
@ -53,6 +53,8 @@ class CreateForm(forms.SelfHandlingForm):
|
||||
_("Interval (format hh:mm:ss)")}),
|
||||
required=True)
|
||||
failure_url = 'horizon:admin:audits:index'
|
||||
auto_trigger = forms.BooleanField(label=_("Auto Trigger"),
|
||||
required=False)
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(CreateForm, self).__init__(request, *args, **kwargs)
|
||||
@ -85,6 +87,7 @@ class CreateForm(forms.SelfHandlingForm):
|
||||
try:
|
||||
params = {'audit_template_uuid': data['audit_template']}
|
||||
params['audit_type'] = data['audit_type'].upper()
|
||||
params['auto_trigger'] = data['auto_trigger']
|
||||
if data['audit_type'] == 'continuous':
|
||||
params['interval'] = int(data['interval'].total_seconds())
|
||||
else:
|
||||
|
@ -122,6 +122,9 @@ class AuditsTable(horizon.tables.DataTable):
|
||||
audit_type = horizon.tables.Column(
|
||||
'audit_type',
|
||||
verbose_name=_('Audit Type'))
|
||||
auto_trigger = horizon.tables.Column(
|
||||
'auto_trigger',
|
||||
verbose_name=_('Auto Trigger'))
|
||||
status = horizon.tables.Column(
|
||||
'state',
|
||||
verbose_name=_('State'),
|
||||
|
@ -4,4 +4,5 @@
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<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 %}
|
||||
|
@ -19,6 +19,8 @@
|
||||
<dd>{{ audit.strategy_name|default:"—" }}</dd>
|
||||
<dt>{% trans "Type" %}</dt>
|
||||
<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 %}
|
||||
<dt>{% trans "State" %}</dt>
|
||||
<dd>{{ audit.state|default:"—" }}</dd>
|
||||
|
@ -217,7 +217,7 @@ class WatcherAPITests(test.APITestCase):
|
||||
watcherclient.audit = self.mox.CreateMockAnything()
|
||||
watcherclient.audit.create(
|
||||
audit_template_uuid=audit_template_uuid,
|
||||
audit_type=audit_type).AndReturn(audit)
|
||||
audit_type=audit_type, auto_trigger=False).AndReturn(audit)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
ret_val = api.watcher.Audit.create(
|
||||
@ -237,11 +237,31 @@ class WatcherAPITests(test.APITestCase):
|
||||
watcherclient.audit.create(
|
||||
audit_template_uuid=audit_template_uuid,
|
||||
audit_type=audit_type,
|
||||
auto_trigger=False,
|
||||
interval=interval).AndReturn(audit)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
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)
|
||||
|
||||
def test_audit_delete(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user