Revision 59573532
b/snf-cyclades-app/synnefo/plankton/backend.py | ||
---|---|---|
97 | 97 |
def split_url(url): |
98 | 98 |
"""Returns (accout, container, object) from a url string""" |
99 | 99 |
t = url.split('/', 4) |
100 |
assert t[0] == "pithos:", "Invalid url" |
|
100 | 101 |
assert len(t) == 5, "Invalid url" |
101 | 102 |
return t[2:5] |
102 | 103 |
|
b/snf-cyclades-app/synnefo/plankton/tests.py | ||
---|---|---|
213 | 213 |
|
214 | 214 |
@assert_backend_closed |
215 | 215 |
def test_add_image(self, backend): |
216 |
location = "pithos://uuid/container/name/" |
|
216 | 217 |
response = self.post("/plankton/images/", |
217 | 218 |
json.dumps({}), |
218 | 219 |
'json', |
219 | 220 |
HTTP_X_IMAGE_META_NAME='dummy_name', |
220 | 221 |
HTTP_X_IMAGE_META_OWNER='dummy_owner', |
221 |
HTTP_X_IMAGE_META_LOCATION='dummy_location')
|
|
222 |
HTTP_X_IMAGE_META_LOCATION=location)
|
|
222 | 223 |
self.assertSuccess(response) |
223 | 224 |
backend.return_value.register.assert_called_once_with('dummy_name', |
224 |
'dummy_location',
|
|
225 |
location,
|
|
225 | 226 |
{'owner': 'dummy_owner'}) |
226 | 227 |
|
227 | 228 |
@assert_backend_closed |
b/snf-cyclades-app/synnefo/plankton/views.py | ||
---|---|---|
43 | 43 |
from snf_django.lib import api |
44 | 44 |
from snf_django.lib.api import faults |
45 | 45 |
from synnefo.plankton.utils import image_backend |
46 |
from synnefo.plankton.backend import split_url |
|
46 | 47 |
|
47 | 48 |
|
48 | 49 |
FILTERS = ('name', 'container_format', 'disk_format', 'status', 'size_min', |
... | ... | |
143 | 144 |
|
144 | 145 |
name = params.pop('name') |
145 | 146 |
location = params.pop('location', None) |
147 |
try: |
|
148 |
split_url(location) |
|
149 |
except AssertionError: |
|
150 |
raise faults.BadRequest("Invalid location '%s'" % location) |
|
146 | 151 |
|
147 | 152 |
if location: |
148 | 153 |
with image_backend(request.user_uniq) as backend: |
Also available in: Unified diff