Let cluster action_*** load the right schema.
apischema.py defind some schema to validate the request. Current code under cluster schema has some item like "create","add_shard", "grow" etc. Call "create" method pass the action "create", but call method like "add_shard" atcually pass the action "action". https://github.com/openstack/trove/blob/master/trove/common/api.py#L157 And this will lead to method get_schema will return "{}". https://github.com/openstack/trove/blob/master/trove/cluster/service.py#L54 And then lead to method vallidate_request actually do nothing. https://github.com/openstack/trove/blob/master/trove/common/wsgi.py#L402 Change-Id: I5dc9a6639445ce37c8b2213717cf17c3a64d1716
This commit is contained in:
parent
6efc8465a8
commit
28291f4e5a
|
@ -259,71 +259,73 @@ cluster = {
|
|||
}
|
||||
}
|
||||
},
|
||||
"add_shard": {
|
||||
"type": "object",
|
||||
"required": ["add_shard"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"add_shard": {
|
||||
"type": "object"
|
||||
"action": {
|
||||
"add_shard": {
|
||||
"type": "object",
|
||||
"required": ["add_shard"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"add_shard": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"grow": {
|
||||
"type": "object",
|
||||
"required": ["grow"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"grow": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["flavorRef"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"name": non_empty_string,
|
||||
"flavorRef": flavorref,
|
||||
"volume": volume,
|
||||
"nics": nics,
|
||||
"availability_zone": non_empty_string,
|
||||
"modules": module_list,
|
||||
"related_to": non_empty_string,
|
||||
"type": non_empty_string,
|
||||
"region_name": non_empty_string
|
||||
},
|
||||
"grow": {
|
||||
"type": "object",
|
||||
"required": ["grow"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"grow": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["flavorRef"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"name": non_empty_string,
|
||||
"flavorRef": flavorref,
|
||||
"volume": volume,
|
||||
"nics": nics,
|
||||
"availability_zone": non_empty_string,
|
||||
"modules": module_list,
|
||||
"related_to": non_empty_string,
|
||||
"type": non_empty_string,
|
||||
"region_name": non_empty_string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"shrink": {
|
||||
"type": "object",
|
||||
"required": ["shrink"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"shrink": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["id"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"id": uuid
|
||||
},
|
||||
"shrink": {
|
||||
"type": "object",
|
||||
"required": ["shrink"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"shrink": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["id"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"id": uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"upgrade": {
|
||||
"type": "object",
|
||||
"required": ["upgrade"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"upgrade": {
|
||||
"type": "object",
|
||||
"required": ["datastore_version"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"datastore_version": non_empty_string
|
||||
},
|
||||
"upgrade": {
|
||||
"type": "object",
|
||||
"required": ["upgrade"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"upgrade": {
|
||||
"type": "object",
|
||||
"required": ["datastore_version"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"datastore_version": non_empty_string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,21 @@ class TestClusterController(trove_testtools.TestCase):
|
|||
self.add_shard = {
|
||||
"add_shard": {}
|
||||
}
|
||||
self.grow = {
|
||||
"grow": [
|
||||
{"flavorRef": "7"},
|
||||
]
|
||||
}
|
||||
self.shrink = {
|
||||
"shrink": [
|
||||
{"id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"},
|
||||
]
|
||||
}
|
||||
self.upgrade = {
|
||||
"upgrade": {
|
||||
"datastore_version": "2.4.10"
|
||||
}
|
||||
}
|
||||
|
||||
def test_get_schema_create(self):
|
||||
schema = self.controller.get_schema('create', self.cluster)
|
||||
|
@ -73,10 +88,30 @@ class TestClusterController(trove_testtools.TestCase):
|
|||
self.assertTrue('cluster')
|
||||
|
||||
def test_get_schema_action_add_shard(self):
|
||||
schema = self.controller.get_schema('add_shard', self.add_shard)
|
||||
schema = self.controller.get_schema('action', self.add_shard)
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertIn('add_shard', schema['properties'])
|
||||
|
||||
def test_get_schema_action_grow(self):
|
||||
schema = self.controller.get_schema('action', self.grow)
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertIn('grow', schema['properties'])
|
||||
|
||||
def test_get_schema_action_shrink(self):
|
||||
schema = self.controller.get_schema('action', self.shrink)
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertIn('shrink', schema['properties'])
|
||||
|
||||
def test_get_schema_action_upgrade(self):
|
||||
schema = self.controller.get_schema('action', self.upgrade)
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertIn('upgrade', schema['properties'])
|
||||
|
||||
def test_get_schema_action_invalid(self):
|
||||
schema = self.controller.get_schema('action', {'wow': {}})
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertThat(len(schema.keys()), Is(0))
|
||||
|
||||
def test_validate_create(self):
|
||||
body = self.cluster
|
||||
schema = self.controller.get_schema('create', body)
|
||||
|
@ -85,7 +120,25 @@ class TestClusterController(trove_testtools.TestCase):
|
|||
|
||||
def test_validate_add_shard(self):
|
||||
body = self.add_shard
|
||||
schema = self.controller.get_schema('add_shard', body)
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
def test_validate_grow(self):
|
||||
body = self.grow
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
def test_validate_shrink(self):
|
||||
body = self.shrink
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
def test_validate_upgrade(self):
|
||||
body = self.upgrade
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
|
@ -128,11 +181,8 @@ class TestClusterController(trove_testtools.TestCase):
|
|||
error_messages)
|
||||
self.assertIn("locality", error_paths)
|
||||
|
||||
@patch.object(Cluster, 'create')
|
||||
@patch.object(datastore_models, 'get_datastore_version')
|
||||
def test_create_clusters_disabled(self,
|
||||
mock_get_datastore_version,
|
||||
mock_cluster_create):
|
||||
def test_create_clusters_disabled(self, mock_get_datastore_version):
|
||||
body = self.cluster
|
||||
tenant_id = Mock()
|
||||
context = trove_testtools.TroveTestContext(self)
|
||||
|
|
Loading…
Reference in New Issue