summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-29 11:03:08 +0000
committerGerrit Code Review <review@openstack.org>2013-06-29 11:03:08 +0000
commit98a481aa4a121ef2a2e5fe338c4b9ab4f242cc29 (patch)
tree4de6dec361fd15d82043003c867f51c132e605a4
parent815f0faffe085895febcd80dde8d2eacdffceb60 (diff)
parent643cf2d3c67a6c9728fd5c766a9cee3a09d67022 (diff)
downloadnova-98a481aa4a121ef2a2e5fe338c4b9ab4f242cc29.tar.gz
nova-98a481aa4a121ef2a2e5fe338c4b9ab4f242cc29.tar.xz
nova-98a481aa4a121ef2a2e5fe338c4b9ab4f242cc29.zip
Merge "Merged flavor_swap extension into core API"
-rw-r--r--nova/api/openstack/compute/plugins/v3/flavors.py2
-rw-r--r--nova/api/openstack/compute/schemas/v3/flavor.rng12
-rw-r--r--nova/api/openstack/compute/schemas/v3/flavors.rng6
-rw-r--r--nova/api/openstack/xmlutil.py8
-rw-r--r--nova/tests/api/openstack/compute/plugins/v3/test_flavors.py148
5 files changed, 50 insertions, 126 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/flavors.py b/nova/api/openstack/compute/plugins/v3/flavors.py
index 733ff3750..31c0fa8b7 100644
--- a/nova/api/openstack/compute/plugins/v3/flavors.py
+++ b/nova/api/openstack/compute/plugins/v3/flavors.py
@@ -34,6 +34,8 @@ def make_flavor(elem, detailed=False):
elem.set('ram')
elem.set('disk')
elem.set('vcpus', xmlutil.EmptyStringSelector('vcpus'))
+ # NOTE(vish): this was originally added without a namespace
+ elem.set('swap', xmlutil.EmptyStringSelector('swap'))
xmlutil.make_links(elem, 'links')
diff --git a/nova/api/openstack/compute/schemas/v3/flavor.rng b/nova/api/openstack/compute/schemas/v3/flavor.rng
new file mode 100644
index 000000000..4b6b74001
--- /dev/null
+++ b/nova/api/openstack/compute/schemas/v3/flavor.rng
@@ -0,0 +1,12 @@
+<element name="flavor" ns="http://docs.openstack.org/compute/api/v1.1"
+ xmlns="http://relaxng.org/ns/structure/1.0">
+ <attribute name="name"> <text/> </attribute>
+ <attribute name="id"> <text/> </attribute>
+ <attribute name="ram"> <text/> </attribute>
+ <attribute name="disk"> <text/> </attribute>
+ <attribute name="vcpus"> <text/> </attribute>
+ <attribute name="swap"> <text/> </attribute>
+ <zeroOrMore>
+ <externalRef href="../atom-link.rng"/>
+ </zeroOrMore>
+</element>
diff --git a/nova/api/openstack/compute/schemas/v3/flavors.rng b/nova/api/openstack/compute/schemas/v3/flavors.rng
new file mode 100644
index 000000000..b7a3acc01
--- /dev/null
+++ b/nova/api/openstack/compute/schemas/v3/flavors.rng
@@ -0,0 +1,6 @@
+<element name="flavors" xmlns="http://relaxng.org/ns/structure/1.0"
+ ns="http://docs.openstack.org/compute/api/v1.1">
+ <zeroOrMore>
+ <externalRef href="flavor.rng"/>
+ </zeroOrMore>
+</element>
diff --git a/nova/api/openstack/xmlutil.py b/nova/api/openstack/xmlutil.py
index 04f5e28e3..37766b3e3 100644
--- a/nova/api/openstack/xmlutil.py
+++ b/nova/api/openstack/xmlutil.py
@@ -33,12 +33,12 @@ XMLNS_COMMON_V10 = 'http://docs.openstack.org/common/api/v1.0'
XMLNS_ATOM = 'http://www.w3.org/2005/Atom'
-def validate_schema(xml, schema_name):
+def validate_schema(xml, schema_name, version='v1.1'):
if isinstance(xml, str):
xml = etree.fromstring(xml)
- base_path = 'nova/api/openstack/compute/schemas/v1.1/'
- if schema_name in ('atom', 'atom-link'):
- base_path = 'nova/api/openstack/compute/schemas/'
+ base_path = 'nova/api/openstack/compute/schemas/'
+ if schema_name not in ('atom', 'atom-link'):
+ base_path += '%s/' % version
schema_path = os.path.join(utils.novadir(),
'%s%s.rng' % (base_path, schema_name))
schema_doc = etree.parse(schema_path)
diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_flavors.py b/nova/tests/api/openstack/compute/plugins/v3/test_flavors.py
index 6680460de..d204af11f 100644
--- a/nova/tests/api/openstack/compute/plugins/v3/test_flavors.py
+++ b/nova/tests/api/openstack/compute/plugins/v3/test_flavors.py
@@ -437,30 +437,36 @@ class FlavorsTest(test.TestCase):
class FlavorsXMLSerializationTest(test.TestCase):
-
- def test_xml_declaration(self):
- serializer = flavors.FlavorTemplate()
-
- fixture = {
- "flavor": {
- "id": "12",
+ def _create_flavor(self):
+ id = 0
+ while True:
+ id += 1
+ yield {
+ "id": str(id),
"name": "asdf",
"ram": "256",
"disk": "10",
"vcpus": "",
+ "swap": "512",
"links": [
{
"rel": "self",
- "href": "http://localhost/v3/flavors/12",
+ "href": "http://localhost/v3/flavors/%s" % id,
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/12",
+ "href": "http://localhost/flavors/%s" % id,
},
],
- },
- }
+ }
+
+ def setUp(self):
+ super(FlavorsXMLSerializationTest, self).setUp()
+ self.flavors = self._create_flavor()
+ def test_xml_declaration(self):
+ serializer = flavors.FlavorTemplate()
+ fixture = {'flavor': next(self.flavors)}
output = serializer.serialize(fixture)
has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
self.assertTrue(has_dec)
@@ -468,29 +474,10 @@ class FlavorsXMLSerializationTest(test.TestCase):
def test_show(self):
serializer = flavors.FlavorTemplate()
- fixture = {
- "flavor": {
- "id": "12",
- "name": "asdf",
- "ram": "256",
- "disk": "10",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/12",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/12",
- },
- ],
- },
- }
-
+ fixture = {'flavor': next(self.flavors)}
output = serializer.serialize(fixture)
root = etree.XML(output)
- xmlutil.validate_schema(root, 'flavor')
+ xmlutil.validate_schema(root, 'flavor', version='v3')
flavor_dict = fixture['flavor']
for key in ['name', 'id', 'ram', 'disk']:
@@ -505,29 +492,10 @@ class FlavorsXMLSerializationTest(test.TestCase):
def test_show_handles_integers(self):
serializer = flavors.FlavorTemplate()
- fixture = {
- "flavor": {
- "id": 12,
- "name": "asdf",
- "ram": 256,
- "disk": 10,
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/12",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/12",
- },
- ],
- },
- }
-
+ fixture = {'flavor': next(self.flavors)}
output = serializer.serialize(fixture)
root = etree.XML(output)
- xmlutil.validate_schema(root, 'flavor')
+ xmlutil.validate_schema(root, 'flavor', version='v3')
flavor_dict = fixture['flavor']
for key in ['name', 'id', 'ram', 'disk']:
@@ -544,46 +512,14 @@ class FlavorsXMLSerializationTest(test.TestCase):
fixture = {
"flavors": [
- {
- "id": "23",
- "name": "flavor 23",
- "ram": "512",
- "disk": "20",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/23",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/23",
- },
- ],
- },
- {
- "id": "13",
- "name": "flavor 13",
- "ram": "256",
- "disk": "10",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/13",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/13",
- },
- ],
- },
+ next(self.flavors),
+ next(self.flavors),
],
}
output = serializer.serialize(fixture)
root = etree.XML(output)
- xmlutil.validate_schema(root, 'flavors')
+ xmlutil.validate_schema(root, 'flavors', version='v3')
flavor_elems = root.findall('{0}flavor'.format(NS))
self.assertEqual(len(flavor_elems), 2)
for i, flavor_elem in enumerate(flavor_elems):
@@ -603,40 +539,8 @@ class FlavorsXMLSerializationTest(test.TestCase):
fixture = {
"flavors": [
- {
- "id": "23",
- "name": "flavor 23",
- "ram": "512",
- "disk": "20",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/23",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/23",
- },
- ],
- },
- {
- "id": "13",
- "name": "flavor 13",
- "ram": "256",
- "disk": "10",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v3/flavors/13",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/flavors/13",
- },
- ],
- },
+ next(self.flavors),
+ next(self.flavors),
],
}