diff --git a/watcher/api/controllers/v1/audit_template.py b/watcher/api/controllers/v1/audit_template.py index b493270a8..933b4e8a5 100644 --- a/watcher/api/controllers/v1/audit_template.py +++ b/watcher/api/controllers/v1/audit_template.py @@ -138,6 +138,9 @@ class AuditTemplatePostType(wtypes.Base): raise exception.InvalidGoal(goal=audit_template.goal) if audit_template.scope: + keys = [list(s)[0] for s in audit_template.scope] + if keys[0] not in ('compute', 'storage'): + audit_template.scope = [dict(compute=audit_template.scope)] common_utils.Draft4Validator( AuditTemplatePostType._build_schema() ).validate(audit_template.scope) diff --git a/watcher/tests/api/v1/test_audit_templates.py b/watcher/tests/api/v1/test_audit_templates.py index dc990e4d2..44fa33148 100644 --- a/watcher/tests/api/v1/test_audit_templates.py +++ b/watcher/tests/api/v1/test_audit_templates.py @@ -663,6 +663,26 @@ class TestPost(FunctionalTestWithSetup): self.assertEqual(400, response.status_int) assert not cn_mock.called + def test_create_audit_template_with_old_scope(self): + scope = [{'host_aggregates': [{'id': '*'}]}, + {'availability_zones': [{'name': 'AZ1'}, + {'name': 'AZ2'}]}, + {'exclude': [ + {'instances': [ + {'uuid': 'INSTANCE_1'}, + {'uuid': 'INSTANCE_2'}]}, + {'compute_nodes': [ + {'name': 'Node_1'}, + {'name': 'Node_2'}]}, + ]} + ] + audit_template_dict = post_get_test_audit_template( + goal=self.fake_goal1.uuid, + strategy=self.fake_strategy1.uuid, scope=scope) + response = self.post_json('/audit_templates', + audit_template_dict) + self.assertEqual(201, response.status_int) + class TestDelete(api_base.FunctionalTest):