Fix DEFAULT_SCHEMA to validate host_aggreates

Audit scope JSON schema should restrict key of host_aggregates
to "id" or "name", but that is not working now.
This patch fixes DEFAULT_SCHEMA to validate host_aggregates.

Change-Id: Iea42da41d61435780e247736599a56c026f47914
Closes-Bug: #1714448
This commit is contained in:
Hidekazu Nakamura
2017-09-01 18:12:57 +09:00
parent 50935af15f
commit 4c3c84dee9
2 changed files with 44 additions and 16 deletions

View File

@@ -36,12 +36,10 @@ class DefaultScope(base.BaseScope):
"host_aggregates": {
"type": "array",
"items": {
"type": "object",
"properties": {
"anyOf": [
{"type": ["string", "number"]}
]
},
"anyOf": [
{"$ref": "#/host_aggregates/id"},
{"$ref": "#/host_aggregates/name"},
]
}
},
"availability_zones": {
@@ -69,7 +67,8 @@ class DefaultScope(base.BaseScope):
"uuid": {
"type": "string"
}
}
},
"additionalProperties": False
}
},
"compute_nodes": {
@@ -80,18 +79,17 @@ class DefaultScope(base.BaseScope):
"name": {
"type": "string"
}
}
},
"additionalProperties": False
}
},
"host_aggregates": {
"type": "array",
"items": {
"type": "object",
"properties": {
"anyOf": [
{"type": ["string", "number"]}
]
},
"anyOf": [
{"$ref": "#/host_aggregates/id"},
{"$ref": "#/host_aggregates/name"},
]
}
},
"instance_metadata": {
@@ -106,7 +104,29 @@ class DefaultScope(base.BaseScope):
}
},
"additionalProperties": False
}
},
"host_aggregates": {
"id": {
"properties": {
"id": {
"oneOf": [
{"type": "integer"},
{"enum": ["*"]}
]
}
},
"additionalProperties": False
},
"name": {
"properties": {
"name": {
"type": "string"
}
},
"additionalProperties": False
}
},
"additionalProperties": False
}
def __init__(self, scope, config, osc=None):

View File

@@ -511,7 +511,7 @@ class TestPost(FunctionalTestWithSetup):
response.json['created_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_created_at)
def test_create_audit_template_vlidation_with_aggregates(self):
def test_create_audit_template_validation_with_aggregates(self):
scope = [{'host_aggregates': [{'id': '*'}]},
{'availability_zones': [{'name': 'AZ1'},
{'name': 'AZ2'}]},
@@ -532,6 +532,14 @@ class TestPost(FunctionalTestWithSetup):
"be included and excluded together"):
self.post_json('/audit_templates', audit_template_dict)
scope = [{'host_aggregates': [{'id1': '*'}]}]
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, expect_errors=True)
self.assertEqual(500, response.status_int)
def test_create_audit_template_does_autogenerate_id(self):
audit_template_dict = post_get_test_audit_template(
goal=self.fake_goal1.uuid, strategy=None)