Do not pass interval parameter for ONESHOT audit

If we create a ONESHOT audit, interval parameter must not be
set in watcherclient invocation.

Change-Id: Ic654c404efc58ffeeb970d2bef8948b3f5327c3e
This commit is contained in:
David TARDIVEL 2016-07-13 12:28:58 +02:00
parent 83d86fdccc
commit 6afb3b3dd1
3 changed files with 39 additions and 4 deletions

View File

@ -79,9 +79,15 @@ class Audit(base.APIDictWrapper):
:return: the created Audit object
:rtype: :py:class:`~.Audit`
"""
return watcherclient(request).audit.create(
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
deadline=deadline, interval=interval)
if interval:
return watcherclient(request).audit.create(
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
deadline=deadline, interval=interval)
else:
return watcherclient(request).audit.create(
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
deadline=deadline)
@classmethod
def list(cls, request, **filters):

View File

@ -215,6 +215,27 @@ class WatcherAPITests(test.APITestCase):
interval = audit['interval']
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,
deadline=deadline).AndReturn(audit)
self.mox.ReplayAll()
ret_val = api.watcher.Audit.create(
self.request, audit_template_uuid, audit_type, deadline, interval)
self.assertIsInstance(ret_val, dict)
def test_audit_create_with_interval(self):
audit = self.api_audits.list()[1]
audit_template_id = self.api_audit_templates.first()['uuid']
deadline = self.api_audits.first()['deadline']
audit_type = self.api_audits.first()['audit_type']
interval = audit['interval']
audit_template_uuid = audit_template_id
watcherclient = self.stub_watcherclient()
watcherclient.audit = self.mox.CreateMockAnything()
watcherclient.audit.create(

View File

@ -123,7 +123,15 @@ def data(TEST):
'audit_template_uuid': '11111111-1111-1111-1111-111111111111',
'interval': None,
}
audit_dict2 = {
'uuid': '33333333-3333-3333-3333-333333333333',
'deadline': None,
'audit_type': 'CONTINUOUS',
'audit_template_uuid': '11111111-1111-1111-1111-111111111111',
'interval': 60,
}
TEST.api_audits.add(audit_dict)
TEST.api_audits.add(audit_dict2)
_audit_dict = copy.deepcopy(audit_dict)
TEST.action_plans = utils.TestDataContainer()
@ -132,7 +140,7 @@ def data(TEST):
'uuid': '33333333-3333-3333-3333-333333333333',
'state': 'RECOMMENDED',
'first_action_uuid': '44444444-4444-4444-4444-111111111111',
'audit_uuid': '22222222-2222-2222-2222-222222222222'
'audit_uuid': '33333333-3333-3333-3333-333333333333'
}
TEST.api_action_plans.add(action_plan_dict)
_action_plan_dict = copy.deepcopy(action_plan_dict)