parsing: check for categories instead of kinds
We should check for kinds and actions when parsing and validating the data, since POSTing an action is needed when we are triggering an action on a resource.
This commit is contained in:
parent
2c34553176
commit
ec12099382
|
@ -71,7 +71,7 @@ class Controller(ooi.api.base.Controller):
|
|||
tenant_id = req.environ["keystone.token_auth"].user.project_id
|
||||
parser = req.get_parser()(req.headers, req.body)
|
||||
scheme = {
|
||||
"kind": compute.ComputeResource.kind,
|
||||
"category": compute.ComputeResource.kind,
|
||||
"mixins": [
|
||||
templates.OpenStackOSTemplate,
|
||||
templates.OpenStackResourceTemplate,
|
||||
|
|
|
@ -24,14 +24,16 @@ class Validator(object):
|
|||
def __init__(self, obj):
|
||||
self.parsed_obj = obj
|
||||
|
||||
def _validate_kind(self, kind):
|
||||
def _validate_category(self, category):
|
||||
try:
|
||||
if kind.type_id != self.parsed_obj["kind"]:
|
||||
if category.type_id != self.parsed_obj["category"]:
|
||||
raise exception.OCCISchemaMismatch(
|
||||
expected=kind.type_id, found=self.parsed_obj["kind"])
|
||||
expected=category.type_id,
|
||||
found=self.parsed_obj["category"]
|
||||
)
|
||||
except KeyError:
|
||||
raise exception.OCCIMissingType(
|
||||
type_id=kind.type_id)
|
||||
type_id=category.type_id)
|
||||
|
||||
def _compare_schemes(self, expected_type, actual):
|
||||
actual_scheme, actual_term = helpers.decompose_type(actual)
|
||||
|
@ -64,8 +66,8 @@ class Validator(object):
|
|||
return unmatched
|
||||
|
||||
def validate(self, schema):
|
||||
if "kind" in schema:
|
||||
self._validate_kind(schema["kind"])
|
||||
if "category" in schema:
|
||||
self._validate_category(schema["category"])
|
||||
unmatched = copy.copy(self.parsed_obj["mixins"])
|
||||
unmatched = self._validate_mandatory_mixins(
|
||||
schema.get("mixins", []), unmatched)
|
||||
|
|
|
@ -29,7 +29,7 @@ class TestTextParser(base.TestCase):
|
|||
'class="kind"')
|
||||
parser = parsers.TextParser({}, body)
|
||||
res = parser.parse()
|
||||
self.assertEqual("http://example.com/scheme#foo", res["kind"])
|
||||
self.assertEqual("http://example.com/scheme#foo", res["category"])
|
||||
self.assertItemsEqual(["foo"],
|
||||
res["schemes"]["http://example.com/scheme#"])
|
||||
self.assertEqual({}, res["mixins"])
|
||||
|
@ -91,7 +91,7 @@ class TestHeaderParser(base.TestCase):
|
|||
}
|
||||
parser = parsers.HeaderParser(headers, None)
|
||||
res = parser.parse()
|
||||
self.assertEqual("http://example.com/scheme#foo", res["kind"])
|
||||
self.assertEqual("http://example.com/scheme#foo", res["category"])
|
||||
self.assertItemsEqual(["foo"],
|
||||
res["schemes"]["http://example.com/scheme#"])
|
||||
self.assertEqual({}, res["mixins"])
|
||||
|
@ -142,9 +142,9 @@ class TestHeaderParser(base.TestCase):
|
|||
'Category': ('foo; '
|
||||
'scheme="http://example.com/scheme#"; '
|
||||
'class="kind"'),
|
||||
'X-OCCI-Attribute': ('foo="bar", baz=1234'),
|
||||
'X-OCCI-Attribute': 'foo="bar", baz=1234, bazonk="foo=123"',
|
||||
}
|
||||
parser = parsers.HeaderParser(headers, None)
|
||||
res = parser.parse()
|
||||
expected_attrs = {"foo": "bar", "baz": "1234"}
|
||||
expected_attrs = {"foo": "bar", "baz": "1234", "bazonk": "foo=123"}
|
||||
self.assertEqual(expected_attrs, res["attributes"])
|
||||
|
|
|
@ -52,7 +52,7 @@ def _lexise_header(s):
|
|||
|
||||
class TextParser(BaseParser):
|
||||
def parse_categories(self, headers):
|
||||
kind = None
|
||||
kind = action = None
|
||||
mixins = collections.Counter()
|
||||
schemes = collections.defaultdict(list)
|
||||
try:
|
||||
|
@ -69,11 +69,17 @@ class TextParser(BaseParser):
|
|||
if kind is not None:
|
||||
raise exception.OCCIInvalidSchema("Duplicated Kind")
|
||||
kind = ctg_type
|
||||
elif ctg_class == "action":
|
||||
if action is not None:
|
||||
raise exception.OCCIInvalidSchema("Duplicated action")
|
||||
action = ctg_type
|
||||
elif ctg_class == "mixin":
|
||||
mixins[ctg_type] += 1
|
||||
schemes[d["scheme"]].append(d["term"])
|
||||
if action and kind:
|
||||
raise exception.OCCIInvalidSchema("Action and kind together?")
|
||||
return {
|
||||
"kind": kind,
|
||||
"category": kind or action,
|
||||
"mixins": mixins,
|
||||
"schemes": schemes,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue