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:
@@ -36,12 +36,10 @@ class DefaultScope(base.BaseScope):
|
|||||||
"host_aggregates": {
|
"host_aggregates": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "object",
|
"anyOf": [
|
||||||
"properties": {
|
{"$ref": "#/host_aggregates/id"},
|
||||||
"anyOf": [
|
{"$ref": "#/host_aggregates/name"},
|
||||||
{"type": ["string", "number"]}
|
]
|
||||||
]
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"availability_zones": {
|
"availability_zones": {
|
||||||
@@ -69,7 +67,8 @@ class DefaultScope(base.BaseScope):
|
|||||||
"uuid": {
|
"uuid": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compute_nodes": {
|
"compute_nodes": {
|
||||||
@@ -80,18 +79,17 @@ class DefaultScope(base.BaseScope):
|
|||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"host_aggregates": {
|
"host_aggregates": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "object",
|
"anyOf": [
|
||||||
"properties": {
|
{"$ref": "#/host_aggregates/id"},
|
||||||
"anyOf": [
|
{"$ref": "#/host_aggregates/name"},
|
||||||
{"type": ["string", "number"]}
|
]
|
||||||
]
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"instance_metadata": {
|
"instance_metadata": {
|
||||||
@@ -106,7 +104,29 @@ class DefaultScope(base.BaseScope):
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False
|
"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):
|
def __init__(self, scope, config, osc=None):
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ class TestPost(FunctionalTestWithSetup):
|
|||||||
response.json['created_at']).replace(tzinfo=None)
|
response.json['created_at']).replace(tzinfo=None)
|
||||||
self.assertEqual(test_time, return_created_at)
|
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': '*'}]},
|
scope = [{'host_aggregates': [{'id': '*'}]},
|
||||||
{'availability_zones': [{'name': 'AZ1'},
|
{'availability_zones': [{'name': 'AZ1'},
|
||||||
{'name': 'AZ2'}]},
|
{'name': 'AZ2'}]},
|
||||||
@@ -532,6 +532,14 @@ class TestPost(FunctionalTestWithSetup):
|
|||||||
"be included and excluded together"):
|
"be included and excluded together"):
|
||||||
self.post_json('/audit_templates', audit_template_dict)
|
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):
|
def test_create_audit_template_does_autogenerate_id(self):
|
||||||
audit_template_dict = post_get_test_audit_template(
|
audit_template_dict = post_get_test_audit_template(
|
||||||
goal=self.fake_goal1.uuid, strategy=None)
|
goal=self.fake_goal1.uuid, strategy=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user