Add auto_trigger support
This patch set adds support of auto-triggering for action plans. You can use it by adding new attribute '--auto-trigger' to watcher audit create command. Change-Id: I2e4ee53f9f639cb3248c0e4dcc7b9716ff1fc352 Partially-Implements: blueprint automatic-triggering-audit Depends-On: I36b7dff8eab5f6ebb18f6f4e752cf4b263456293
This commit is contained in:

committed by
David TARDIVEL

parent
0584350663
commit
6e291f0f13
@@ -69,6 +69,7 @@ AUDIT_1 = {
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
'scope': '',
|
||||
'auto_trigger': False,
|
||||
}
|
||||
|
||||
AUDIT_2 = {
|
||||
@@ -85,6 +86,7 @@ AUDIT_2 = {
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
'scope': '',
|
||||
'auto_trigger': False,
|
||||
}
|
||||
|
||||
AUDIT_3 = {
|
||||
@@ -101,6 +103,7 @@ AUDIT_3 = {
|
||||
'parameters': None,
|
||||
'interval': 3600,
|
||||
'scope': '',
|
||||
'auto_trigger': True,
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +287,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
audit_type='ONESHOT')
|
||||
audit_type='ONESHOT', auto_trigger=False)
|
||||
|
||||
def test_do_audit_create_with_audit_template_name(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
@@ -300,6 +303,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
auto_trigger=False,
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_goal(self):
|
||||
@@ -315,6 +319,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
auto_trigger=False,
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
@@ -333,6 +338,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
strategy='2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
auto_trigger=False,
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
@@ -349,7 +355,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT')
|
||||
auto_trigger=False, audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_parameter(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
@@ -366,6 +372,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT',
|
||||
auto_trigger=False,
|
||||
parameters={'para1': 10, 'para2': 20})
|
||||
|
||||
def test_do_audit_create_with_type_continuous(self):
|
||||
@@ -383,4 +390,5 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='CONTINUOUS',
|
||||
auto_trigger=False,
|
||||
interval='3600')
|
||||
|
@@ -20,7 +20,7 @@ from watcherclient import exceptions as exc
|
||||
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'audit_type', 'interval',
|
||||
'parameters', 'goal', 'strategy']
|
||||
'parameters', 'goal', 'strategy', 'auto_trigger']
|
||||
|
||||
|
||||
class Audit(base.Resource):
|
||||
|
@@ -162,13 +162,20 @@ class CreateAudit(command.ShowOne):
|
||||
dest='audit_template_uuid',
|
||||
metavar='<audit_template>',
|
||||
help=_('Audit template used for this audit (name or uuid).'))
|
||||
parser.add_argument(
|
||||
'--auto-trigger',
|
||||
dest='auto_trigger',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_('Trigger automatically action plan '
|
||||
'once audit is succeeded.'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'audit_type', 'parameters',
|
||||
'interval', 'goal', 'strategy']
|
||||
'interval', 'goal', 'strategy', 'auto_trigger']
|
||||
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
|
@@ -33,17 +33,18 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'state', 'audit_type', 'parameters', 'interval', 'goal_name',
|
||||
'strategy_name', 'scope']
|
||||
'strategy_name', 'scope', 'auto_trigger']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'State', 'Audit Type', 'Parameters', 'Interval', 'Goal',
|
||||
'Strategy', 'Audit Scope']
|
||||
'Strategy', 'Audit Scope', 'Auto Trigger']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'audit_type',
|
||||
'state', 'goal_name', 'strategy_name']
|
||||
'state', 'goal_name', 'strategy_name',
|
||||
'auto_trigger']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit Type', 'State', 'Goal',
|
||||
'Strategy']
|
||||
'Strategy', 'Auto Trigger']
|
||||
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
|
Reference in New Issue
Block a user