Shorten swift-internal:// to swift://

The internal/external distinction can be handled with meta-data
instead of encoding it within the url. So we can simply start using
swift://.

This patch keeps the swift-internal:// option around until we decide
it can simply be removed.

Change-Id: I5ea3d93319daf426539abc78ae826b6594035df9
Implements: blueprint swift-url-proto-cleanup
This commit is contained in:
Matthew Farrellee 2014-02-13 07:36:04 -05:00
parent 1d32744e7e
commit 8919808cc1
8 changed files with 36 additions and 18 deletions

View File

@ -578,7 +578,7 @@ This operation does not require a request body.
"password": "swordfish",
"user": "admin"
},
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"tenant_id": "11587919cc534bcbb1027a161c82cf58",
"created_at": "2013-10-15 14:25:04.970513",
"updated_at": null,
@ -624,7 +624,7 @@ This operation does not require a request body.
"password": "swordfish",
"user": "admin"
},
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"tenant_id": "11587919cc534bcbb1027a161c82cf58",
"created_at": "2013-10-15 14:25:04.970513",
"updated_at": null,
@ -654,7 +654,7 @@ This operation shows information about the created Job Binary.
.. sourcecode:: json
{
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"name": "jar-example.jar",
"description": "This is job binary",
"extra": {
@ -679,7 +679,7 @@ This operation shows information about the created Job Binary.
"password": "swordfish",
"user": "admin"
},
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"tenant_id": "11587919cc534bcbb1027a161c82cf58",
"created_at": "2013-10-15 14:49:20.106452",
"id": "07f86352-ee8a-4b08-b737-d705ded5ff9c",
@ -853,7 +853,7 @@ This operation does not require a request body.
"password": "swordfish",
"user": "admin"
},
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"tenant_id": "11587919cc534bcbb1027a161c82cf58",
"created_at": "2013-10-15 16:03:37.979630",
"updated_at": null,
@ -911,7 +911,7 @@ This operation does not require a request body.
"password": "swordfish",
"user": "admin"
},
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"tenant_id": "11587919cc534bcbb1027a161c82cf58",
"created_at": "2013-10-15 16:03:37.979630",
"updated_at": null,

View File

@ -1,9 +1,9 @@
{
"url": "swift-internal://container/jar-example.jar",
"url": "swift://container/jar-example.jar",
"name": "jar-example.jar",
"description": "This is job binary",
"extra": {
"password": "swordfish",
"user": "admin"
}
}
}

View File

@ -24,7 +24,9 @@ def get_raw_binary(job_binary):
if url.startswith("savanna-db://"):
res = db.get_raw_data(context.ctx(), job_binary)
if url.startswith(su.SWIFT_INTERNAL_PREFIX):
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
if url.startswith(su.SWIFT_INTERNAL_PREFIX) or (
url.startswith(su.OLD_SWIFT_INTERNAL_PREFIX)):
res = i_swift.get_raw_data(context.ctx(), job_binary)
return res

View File

@ -39,14 +39,16 @@ def get_raw_data(context, job_binary):
conn = _get_conn(user, password)
if not job_binary.url.startswith(su.SWIFT_INTERNAL_PREFIX):
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
if not (job_binary.url.startswith(su.SWIFT_INTERNAL_PREFIX) or
job_binary.url.startswith(su.OLD_SWIFT_INTERNAL_PREFIX)):
# This should have been guaranteed already,
# but we'll check just in case.
raise ex.BadJobBinaryException("Url for binary in internal swift "
"must start with %s"
% su.SWIFT_INTERNAL_PREFIX)
names = job_binary.url[len(su.SWIFT_INTERNAL_PREFIX):].split("/", 1)
names = job_binary.url[job_binary.url.index("://")+3:].split("/", 1)
if len(names) == 1:
# We are getting a whole container, return as a dictionary.
container = names[0]

View File

@ -51,7 +51,9 @@ JOB_BINARY_SCHEMA = {
def check_job_binary(data, **kwargs):
job_binary_location_type = data["url"]
extra = data.get("extra", {})
if job_binary_location_type.startswith(su.SWIFT_INTERNAL_PREFIX):
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
if job_binary_location_type.startswith(su.SWIFT_INTERNAL_PREFIX) or (
job_binary_location_type.startswith(su.OLD_SWIFT_INTERNAL_PREFIX)):
if not extra.get("user") or not extra.get("password"):
raise e.BadJobBinaryException()
if job_binary_location_type.startswith("savanna-db"):

View File

@ -23,10 +23,9 @@ from savanna.utils.openstack import base
CONF = cfg.CONF
SWIFT_INTERNAL_PREFIX = "swift-internal://"
#TODO(tmckay): support swift-external in a future version
# SWIFT_EXTERNAL_PREFIX = "swift-external://"
SWIFT_INTERNAL_PREFIX = "swift://"
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
OLD_SWIFT_INTERNAL_PREFIX = "swift-internal://"
def _get_service_address(service_type):

View File

@ -47,6 +47,17 @@ class TestJobBinaryValidation(u.ValidationTestCase):
"To work with JobBinary located in internal "
"swift add 'user' and 'password' to extra"))
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
def test_job_binary_create_swift_with_old_prefix(self):
self._assert_create_object_validation(
data={
"name": "j_o_w",
"url": su.OLD_SWIFT_INTERNAL_PREFIX+"o.savanna/k"
},
bad_req_i=(1, "BAD_JOB_BINARY",
"To work with JobBinary located in internal "
"swift add 'user' and 'password' to extra"))
def test_job_binary_create_internal(self):
self._assert_create_object_validation(
data={

View File

@ -48,8 +48,10 @@ def validate_name_format(entry):
def validate_job_location_format(entry):
if entry.startswith('savanna-db://'):
return uuidutils.is_uuid_like(entry[len("savanna-db://"):])
if entry.startswith(su.SWIFT_INTERNAL_PREFIX):
#TODO(tmckay):allow su.SWIFT_EXTERNAL_PREFIX in a future version
# TODO(mattf): remove support for OLD_SWIFT_INTERNAL_PREFIX
if entry.startswith(su.SWIFT_INTERNAL_PREFIX) or (
entry.startswith(su.OLD_SWIFT_INTERNAL_PREFIX)):
#TODO(nprivalova):add hostname validation
return True
return False