summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-11-17 15:59:24 -0800
committerBrian Waldon <brian.waldon@rackspace.com>2011-11-17 16:46:20 -0800
commit6749f31604d9787d48b2bc1a02b5b5e5f23eefa8 (patch)
tree7d894b7fdd129bd6e2d1ab4f2be5cb25e4741328 /nova/api
parent15f32f22215ffe0c8939dc05aaeb2eb9d3f52e74 (diff)
Converting tests to use v2
- Convert all OpenStack API tests to use v1.1 instead of v2 - Keeps v1.1 as an alternate endpoint, but it is functionally equivalent to v2 Change-Id: I9b6796dc4507c3d5c1432266daa5b5f1dcf540c3
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py24
-rw-r--r--nova/api/openstack/v2/auth.py8
-rw-r--r--nova/api/openstack/v2/versions.py18
-rw-r--r--nova/api/openstack/v2/views/versions.py8
4 files changed, 27 insertions, 31 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 1a6800ac0..5def03f78 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -20,7 +20,6 @@ import os
import re
import urlparse
-from lxml import etree
import webob
from xml.dom import minidom
@@ -28,11 +27,9 @@ from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.compute import vm_states
from nova.compute import task_states
-from nova import exception
from nova import flags
from nova import ipv6
from nova import log as logging
-import nova.network
from nova import quota
@@ -226,8 +223,14 @@ def remove_version_from_href(href):
"""
parsed_url = urlparse.urlsplit(href)
- new_path = re.sub(r'^/v[0-9]+\.[0-9]+(/|$)', r'\1', parsed_url.path,
- count=1)
+ url_parts = parsed_url.path.split('/', 2)
+
+ # NOTE: this should match vX.X or vX
+ expression = re.compile(r'^v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)')
+ if expression.match(url_parts[1]):
+ del url_parts[1]
+
+ new_path = '/'.join(url_parts)
if new_path == parsed_url.path:
msg = _('href %s does not contain version') % href
@@ -253,15 +256,10 @@ def get_version_from_href(href):
"""
try:
- #finds the first instance that matches /v#.#/
- version = re.findall(r'[/][v][0-9]+\.[0-9]+[/]', href)
- #if no version was found, try finding /v#.# at the end of the string
- if not version:
- version = re.findall(r'[/][v][0-9]+\.[0-9]+$', href)
- version = re.findall(r'[0-9]+\.[0-9]', version[0])[0]
+ expression = r'/v([0-9]+|[0-9]+\.[0-9]+)(/|$)'
+ return re.findall(expression, href)[0][0]
except IndexError:
- version = '1.0'
- return version
+ return '2'
def check_img_metadata_quota_limit(context, metadata):
diff --git a/nova/api/openstack/v2/auth.py b/nova/api/openstack/v2/auth.py
index c0ea30671..ba5fb603f 100644
--- a/nova/api/openstack/v2/auth.py
+++ b/nova/api/openstack/v2/auth.py
@@ -103,12 +103,12 @@ class AuthMiddleware(base_wsgi.Middleware):
path_parts = req.path.split('/')
# TODO(wwolf): this v1.1 check will be temporary as
# keystone should be taking this over at some point
- if len(path_parts) > 1 and path_parts[1] == 'v1.1':
+ if len(path_parts) > 1 and path_parts[1] in ('v1.1', 'v2'):
project_id = path_parts[2]
# Check that the project for project_id exists, and that user
# is authorized to use it
try:
- project = self.auth.get_project(project_id)
+ self.auth.get_project(project_id)
except exception.ProjectNotFound:
return wsgi.Fault(webob.exc.HTTPUnauthorized())
if project_id not in [p.id for p in projects]:
@@ -153,7 +153,7 @@ class AuthMiddleware(base_wsgi.Middleware):
path_info = req.path_info
if len(path_info) > 1:
msg = _("Authentication requests must be made against a version "
- "root (e.g. /v1.0 or /v1.1).")
+ "root (e.g. /v2).")
LOG.warn(msg)
return wsgi.Fault(webob.exc.HTTPUnauthorized(explanation=msg))
@@ -243,7 +243,7 @@ class AuthMiddleware(base_wsgi.Middleware):
os_url = req.url
token_dict['server_management_url'] = os_url.strip('/')
version = common.get_version_from_href(os_url)
- if version == '1.1':
+ if version in ('1.1', '2'):
token_dict['server_management_url'] += '/' + project_id
token_dict['storage_url'] = ''
token_dict['user_id'] = user.id
diff --git a/nova/api/openstack/v2/versions.py b/nova/api/openstack/v2/versions.py
index 3c3d4068c..4f5dcc0b0 100644
--- a/nova/api/openstack/v2/versions.py
+++ b/nova/api/openstack/v2/versions.py
@@ -18,8 +18,6 @@
from datetime import datetime
from lxml import etree
-import webob
-import webob.dec
from nova.api.openstack.v2.views import versions as views_versions
from nova.api.openstack import wsgi
@@ -27,8 +25,8 @@ from nova.api.openstack import xmlutil
VERSIONS = {
- "v1.1": {
- "id": "v1.1",
+ "v2.0": {
+ "id": "v2.0",
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"links": [
@@ -48,14 +46,14 @@ VERSIONS = {
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute+xml;version=1.1",
+ "type": "application/vnd.openstack.compute+xml;version=2",
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute+json;version=1.1",
+ "type": "application/vnd.openstack.compute+json;version=2",
}
],
- },
+ }
}
@@ -94,10 +92,10 @@ class Versions(wsgi.Resource):
return builder.build_choices(VERSIONS, request)
-class VersionV11(object):
+class VersionV2(object):
def show(self, req):
builder = views_versions.get_view_builder(req)
- return builder.build_version(VERSIONS['v1.1'])
+ return builder.build_version(VERSIONS['v2.0'])
class VersionsRequestDeserializer(wsgi.RequestDeserializer):
@@ -257,5 +255,5 @@ def create_resource():
deserializer = wsgi.RequestDeserializer()
- return wsgi.Resource(VersionV11(), serializer=serializer,
+ return wsgi.Resource(VersionV2(), serializer=serializer,
deserializer=deserializer)
diff --git a/nova/api/openstack/v2/views/versions.py b/nova/api/openstack/v2/views/versions.py
index 1ac398706..cb2fd9f4a 100644
--- a/nova/api/openstack/v2/views/versions.py
+++ b/nova/api/openstack/v2/views/versions.py
@@ -42,7 +42,7 @@ class ViewBuilder(object):
"links": [
{
"rel": "self",
- "href": self.generate_href(version['id'], req.path),
+ "href": self.generate_href(req.path),
},
],
"media-types": version['media-types'],
@@ -73,7 +73,7 @@ class ViewBuilder(object):
def _build_links(self, version_data):
"""Generate a container of links that refer to the provided version."""
- href = self.generate_href(version_data["id"])
+ href = self.generate_href()
links = [
{
@@ -84,9 +84,9 @@ class ViewBuilder(object):
return links
- def generate_href(self, version_number, path=None):
+ def generate_href(self, path=None):
"""Create an url that refers to a specific version_number."""
- version_number = version_number.strip('/')
+ version_number = 'v2'
if path:
path = path.strip('/')
return os.path.join(self.base_url, version_number, path)