Browse Source

Merge "Compatible with old scope format" into stable/ussuri

stable/ussuri
Zuul 3 weeks ago
committed by Gerrit Code Review
parent
commit
ec62bbe5bd
2 changed files with 23 additions and 0 deletions
  1. +3
    -0
      watcher/api/controllers/v1/audit_template.py
  2. +20
    -0
      watcher/tests/api/v1/test_audit_templates.py

+ 3
- 0
watcher/api/controllers/v1/audit_template.py View File

@@ -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)


+ 20
- 0
watcher/tests/api/v1/test_audit_templates.py View File

@@ -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):



Loading…
Cancel
Save