diff --git a/watcherclient/tests/functional/v1/base.py b/watcherclient/tests/functional/v1/base.py index 229a16d..dbdd72d 100644 --- a/watcherclient/tests/functional/v1/base.py +++ b/watcherclient/tests/functional/v1/base.py @@ -140,5 +140,9 @@ class TestCase(testtools.TestCase): @classmethod def has_audit_created(cls, audit_uuid): - return cls.parse_show_as_object( - cls.watcher('audit show %s' % audit_uuid))['State'] == 'SUCCEEDED' + audit = cls.parse_show_as_object( + cls.watcher('audit show %s' % audit_uuid)) + if audit['Audit Type'] == 'ONESHOT': + return audit['State'] == 'SUCCEEDED' + else: + return audit['State'] == 'ONGOING' diff --git a/watcherclient/tests/functional/v1/test_audit.py b/watcherclient/tests/functional/v1/test_audit.py index ee74da7..25200fa 100644 --- a/watcherclient/tests/functional/v1/test_audit.py +++ b/watcherclient/tests/functional/v1/test_audit.py @@ -114,13 +114,13 @@ class AuditActiveTests(base.TestCase): self.watcher('actionplan delete %s' % action_plan_uuid) self.watcher('audit delete %s' % audit_uuid) - def test_create_audit(self): + def test_create_oneshot_audit(self): audit = self.watcher('audit create -a %s' % self.audit_template_name) audit_uuid = self.parse_show_as_object(audit)['UUID'] self.assert_table_structure([audit], self.detailed_list_fields) self._delete_audit(audit_uuid) - def test_delete_audit(self): + def test_delete_oneshot_audit(self): audit_uuid = self._create_audit() self.assertTrue(test_utils.call_until_true( func=functools.partial( @@ -134,3 +134,26 @@ class AuditActiveTests(base.TestCase): self.watcher('actionplan list --audit %s' % audit_uuid)) action_plan_uuid = list(output[0])[0] self.watcher('actionplan delete %s' % action_plan_uuid) + + def test_continuous_audit(self): + audit = self.watcher('audit create -a %s -t CONTINUOUS -i 600' + % self.audit_template_name) + audit_uuid = self.parse_show_as_object(audit)['UUID'] + self.assert_table_structure([audit], self.detailed_list_fields) + self.assertTrue(test_utils.call_until_true( + func=functools.partial( + self.has_audit_created, audit_uuid), + duration=600, + sleep_for=2 + )) + audit_state = self.parse_show_as_object( + self.watcher('audit show %s' % audit_uuid))['State'] + if audit_state == 'ONGOING': + self.watcher('audit update %s replace state=CANCELLED' + % audit_uuid) + raw_output = self.watcher('audit delete %s' % audit_uuid) + self.assertOutput('', raw_output) + outputs = self.parse_listing( + self.watcher('actionplan list --audit %s' % audit_uuid)) + for actionplan in outputs: + self.watcher('actionplan delete %s' % actionplan['UUID'])