Function versioning API: list

- List function versions
- Add 'latest_version' to get function response

Story: #2001829
Task: #14330
Change-Id: I40f1848872fc7d713d87f657ec891b48c579fee4
This commit is contained in:
Lingxian Kong 2018-04-18 16:39:06 +12:00
parent 12d2ee6f26
commit 9005ceadae
3 changed files with 36 additions and 1 deletions

View File

@ -121,3 +121,19 @@ class FunctionVersionsController(rest.RestController):
**values)
return resources.FunctionVersion.from_dict(version.to_dict())
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.FunctionVersions, types.uuid)
def get_all(self, function_id):
acl.enforce('function_version:get_all', context.get_ctx())
LOG.info("Getting function versions for function %s.", function_id)
# Getting function and versions needs to happen in a db transaction
with db_api.transaction():
func_db = db_api.get_function(function_id)
db_versions = func_db.versions
versions = [resources.FunctionVersion.from_dict(v.to_dict())
for v in db_versions]
return resources.FunctionVersions(function_versions=versions)

View File

@ -170,6 +170,7 @@ class Function(Resource):
code = types.jsontype
entry = wtypes.text
count = wsme.wsattr(int, readonly=True)
latest_version = wsme.wsattr(int, readonly=True)
project_id = wsme.wsattr(wtypes.text, readonly=True)
created_at = wtypes.text
updated_at = wtypes.text
@ -186,6 +187,7 @@ class Function(Resource):
code={'zip': True},
entry='main',
count=10,
latest_version=0,
project_id='default',
created_at='1970-01-01T00:00:00.000000',
updated_at='1970-01-01T00:00:00.000000'
@ -417,7 +419,7 @@ class Webhooks(ResourceList):
class FunctionVersion(Resource):
id = types.uuid
description = wtypes.text
function_version = wsme.wsattr(int, readonly=True)
version_number = wsme.wsattr(int, readonly=True)
project_id = wsme.wsattr(wtypes.text, readonly=True)
created_at = wsme.wsattr(wtypes.text, readonly=True)
updated_at = wsme.wsattr(wtypes.text, readonly=True)

View File

@ -62,6 +62,12 @@ class TestFunctionVersionController(base.APITest):
func_db = db_api.get_function(self.func_id)
self.assertEqual(1, len(func_db.versions))
# Verify the latest function version by calling API
resp = self.app.get('/v1/functions/%s' % self.func_id)
self.assertEqual(200, resp.status_int)
self.assertEqual(1, resp.json.get('latest_version'))
@mock.patch('qinling.storage.file_system.FileSystemStorage.changed_since')
@mock.patch('qinling.utils.etcd_util.get_function_version_lock')
def test_post_not_change(self, mock_etcd_lock, mock_changed):
@ -91,3 +97,14 @@ class TestFunctionVersionController(base.APITest):
expect_errors=True)
self.assertEqual(403, resp.status_int)
def test_get_all(self):
db_api.increase_function_version(self.func_id, 0,
description="version 1")
resp = self.app.get('/v1/functions/%s/versions' % self.func_id)
self.assertEqual(200, resp.status_int)
actual = self._assert_single_item(resp.json['function_versions'],
version_number=1)
self.assertEqual("version 1", actual.get('description'))