summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorNaveed Massjouni <naveedm9@gmail.com>2011-09-23 15:03:35 -0400
committerNaveed Massjouni <naveedm9@gmail.com>2011-09-23 15:06:37 -0400
commit4e94ec1a0a566b66f09b734e6ffe964b4b3b4bee (patch)
tree2cda3576e8a4af637809058b16eb8d843fb9fd68 /nova/api
parente15258def26bd3b4781486a7a85ca599cbdb07f6 (diff)
Adding xml schema validation for /versions resource.
Change-Id: I8e0b7695743844614b3e7c5a08bb88d3a7500b5d
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/schemas/v1.1/version.rng17
-rw-r--r--nova/api/openstack/schemas/v1.1/versions.rng11
-rw-r--r--nova/api/openstack/xmlutil.py5
3 files changed, 32 insertions, 1 deletions
diff --git a/nova/api/openstack/schemas/v1.1/version.rng b/nova/api/openstack/schemas/v1.1/version.rng
new file mode 100644
index 000000000..ae76270ba
--- /dev/null
+++ b/nova/api/openstack/schemas/v1.1/version.rng
@@ -0,0 +1,17 @@
+<element name="version" ns="http://docs.openstack.org/compute/api/v1.1"
+ xmlns="http://relaxng.org/ns/structure/1.0">
+ <attribute name="id"/>
+ <attribute name="status"/>
+ <attribute name="updated"/>
+ <element name="media-types">
+ <oneOrMore>
+ <element name="media-type">
+ <attribute name="base"/>
+ <attribute name="type"/>
+ </element>
+ </oneOrMore>
+ </element>
+ <zeroOrMore>
+ <externalRef href="../atom-link.rng"/>
+ </zeroOrMore>
+</element>
diff --git a/nova/api/openstack/schemas/v1.1/versions.rng b/nova/api/openstack/schemas/v1.1/versions.rng
new file mode 100644
index 000000000..8b2cc7f71
--- /dev/null
+++ b/nova/api/openstack/schemas/v1.1/versions.rng
@@ -0,0 +1,11 @@
+<element name="versions" xmlns="http://relaxng.org/ns/structure/1.0"
+ ns="http://docs.openstack.org/compute/api/v1.1">
+ <oneOrMore>
+ <element name="version">
+ <attribute name="id"/>
+ <attribute name="status"/>
+ <attribute name="updated"/>
+ <externalRef href="../atom-link.rng"/>
+ </element>
+ </oneOrMore>
+</element>
diff --git a/nova/api/openstack/xmlutil.py b/nova/api/openstack/xmlutil.py
index 97ad90ada..d5eb88a57 100644
--- a/nova/api/openstack/xmlutil.py
+++ b/nova/api/openstack/xmlutil.py
@@ -30,8 +30,11 @@ XMLNS_ATOM = 'http://www.w3.org/2005/Atom'
def validate_schema(xml, schema_name):
if type(xml) is str:
xml = etree.fromstring(xml)
+ base_path = 'nova/api/openstack/schemas/v1.1/'
+ if schema_name in ('atom', 'atom-link'):
+ base_path = 'nova/api/openstack/schemas/'
schema_path = os.path.join(utils.novadir(),
- 'nova/api/openstack/schemas/v1.1/%s.rng' % schema_name)
+ '%s%s.rng' % (base_path, schema_name))
schema_doc = etree.parse(schema_path)
relaxng = etree.RelaxNG(schema_doc)
relaxng.assertValid(xml)