Supporting parameters as part of lp create
Change-Id: I61f46324f414c0d00d4813e7ecb7d99697a9a526 Closes-Bug: #1580347
This commit is contained in:
parent
95c7567627
commit
3d538ac7d3
|
@ -14,6 +14,7 @@
|
|||
|
||||
import string
|
||||
|
||||
import six
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
|
||||
|
@ -141,6 +142,16 @@ class LanguagePack(api_types.Base):
|
|||
lp_metadata = wtypes.text
|
||||
"""The languagepack meta data."""
|
||||
|
||||
"""Parameters that can be used as part of lp building process."""
|
||||
lp_params = wtypes.DictType(
|
||||
wtypes.text,
|
||||
wtypes.DictType(wtypes.text,
|
||||
api_types.MultiType(
|
||||
wtypes.text,
|
||||
six.integer_types,
|
||||
bool,
|
||||
float)))
|
||||
|
||||
@classmethod
|
||||
def from_image(cls, image, host_url):
|
||||
as_dict = {}
|
||||
|
|
|
@ -91,7 +91,7 @@ class LanguagePacksController(rest.RestController):
|
|||
|
||||
return language_pack.LanguagePack.from_db_model(
|
||||
handler.create(data.as_dict(objects.registry.Image),
|
||||
data.lp_metadata), host_url)
|
||||
data.lp_metadata, data.lp_params), host_url)
|
||||
|
||||
@exception.wrap_pecan_controller_exception
|
||||
@wsme_pecan.wsexpose([language_pack.LanguagePack])
|
||||
|
|
|
@ -95,7 +95,7 @@ class LanguagePackHandler(handler.Handler):
|
|||
"""Return all languagepacks."""
|
||||
return objects.registry.Image.get_all_languagepacks(self.context)
|
||||
|
||||
def create(self, data, lp_metadata):
|
||||
def create(self, data, lp_metadata, lp_params):
|
||||
"""Create a new languagepack."""
|
||||
|
||||
self._check_if_limit_of_lps_reached(self.context)
|
||||
|
@ -119,7 +119,7 @@ class LanguagePackHandler(handler.Handler):
|
|||
db_obj.tags.append(lp_metadata)
|
||||
|
||||
db_obj.create(self.context)
|
||||
self._start_build(db_obj)
|
||||
self._start_build(db_obj, lp_params)
|
||||
return db_obj
|
||||
else:
|
||||
raise exc.ResourceExists(name=data['name'])
|
||||
|
@ -159,7 +159,7 @@ class LanguagePackHandler(handler.Handler):
|
|||
|
||||
return db_obj.destroy(self.context)
|
||||
|
||||
def _start_build(self, image):
|
||||
def _start_build(self, image, lp_params):
|
||||
git_info = {
|
||||
'source_url': image.source_uri,
|
||||
}
|
||||
|
@ -169,4 +169,5 @@ class LanguagePackHandler(handler.Handler):
|
|||
name=image.name,
|
||||
source_format=image.source_format,
|
||||
image_format=image.image_format,
|
||||
artifact_type=image.artifact_type)
|
||||
artifact_type=image.artifact_type,
|
||||
lp_params=lp_params)
|
||||
|
|
|
@ -88,14 +88,15 @@ class TestLanguagePacksController(base.BaseTestCase):
|
|||
request_mock):
|
||||
json_create = {'name': 'foo',
|
||||
'source_uri': 'git@github.com/sample/a.git',
|
||||
'lp_metadata': 'some metadata'}
|
||||
'lp_metadata': 'some metadata', 'lp_params': {}}
|
||||
request_mock.body = json.dumps(json_create)
|
||||
request_mock.content_type = 'application/json'
|
||||
hand_create = LanguagePackHandler.return_value.create
|
||||
hand_create.return_value = fakes.FakeImage()
|
||||
language_pack.LanguagePacksController().post()
|
||||
del json_create['lp_metadata']
|
||||
hand_create.assert_called_with(json_create, 'some metadata')
|
||||
del json_create['lp_params']
|
||||
hand_create.assert_called_with(json_create, 'some metadata', {})
|
||||
self.assertEqual(201, resp_mock.status)
|
||||
|
||||
def test_language_packs_post_nodata(self, LanguagePackHandler, resp_mock,
|
||||
|
|
|
@ -57,8 +57,8 @@ class TestLanguagePackHandler(base.BaseTestCase):
|
|||
mock_img.get_lp_by_name_or_uuid.side_effect = exc.ResourceNotFound()
|
||||
mock_img.return_value = fi
|
||||
handler = language_pack_handler.LanguagePackHandler(self.ctx)
|
||||
res = handler.create(data, lp_metadata=None)
|
||||
mock_lp_build.assert_called_once_with(res)
|
||||
res = handler.create(data, lp_metadata=None, lp_params=None)
|
||||
mock_lp_build.assert_called_once_with(res, None)
|
||||
fi.update.assert_called_once_with(data)
|
||||
fi.create.assert_called_once_with(self.ctx)
|
||||
|
||||
|
@ -76,7 +76,7 @@ class TestLanguagePackHandler(base.BaseTestCase):
|
|||
handler = language_pack_handler.LanguagePackHandler(self.ctx)
|
||||
|
||||
self.assertRaises(exc.ResourceLimitExceeded, handler.create,
|
||||
data, lp_metadata=None)
|
||||
data, lp_metadata=None, lp_params=None)
|
||||
|
||||
def test_lp_create_bad_git_url(self, mock_img):
|
||||
|
||||
|
@ -99,7 +99,7 @@ class TestLanguagePackHandler(base.BaseTestCase):
|
|||
handler = language_pack_handler.LanguagePackHandler(self.ctx)
|
||||
|
||||
self.assertRaises(exc.BadRequest, handler.create, data,
|
||||
lp_metadata=None)
|
||||
lp_metadata=None, lp_params=None)
|
||||
|
||||
@mock.patch('solum.common.solum_swiftclient.SwiftClient.delete_object')
|
||||
@mock.patch('solum.api.handlers.userlog_handler.UserlogHandler')
|
||||
|
|
|
@ -782,7 +782,8 @@ class TestLanguagePackBuildCommand(base.BaseTestCase):
|
|||
git_info = mock_git_info()
|
||||
handler.build_lp(self.ctx, image_id=5, git_info=git_info,
|
||||
name='lp_name', source_format='heroku',
|
||||
image_format='docker', artifact_type='language_pack')
|
||||
image_format='docker', artifact_type='language_pack',
|
||||
lp_params='')
|
||||
|
||||
proj_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||
'..', '..', '..', '..'))
|
||||
|
|
|
@ -36,7 +36,7 @@ class API(service.API):
|
|||
test_cmd=test_cmd, run_cmd=run_cmd, du_id=du_id)
|
||||
|
||||
def build_lp(self, image_id, git_info, name, source_format, image_format,
|
||||
artifact_type):
|
||||
artifact_type, lp_params=None):
|
||||
self._cast('build_lp', image_id=image_id, git_info=git_info, name=name,
|
||||
source_format=source_format, image_format=image_format,
|
||||
artifact_type=artifact_type)
|
||||
artifact_type=artifact_type, lp_params=lp_params)
|
||||
|
|
|
@ -640,7 +640,8 @@ class Handler(object):
|
|||
return source_private_key
|
||||
|
||||
def build_lp(self, ctxt, image_id, git_info, name, source_format,
|
||||
image_format, artifact_type):
|
||||
image_format, artifact_type, lp_params):
|
||||
|
||||
update_lp_status(ctxt, image_id, IMAGE_STATES.BUILDING)
|
||||
|
||||
solum.TLS.trace.clear()
|
||||
|
|
Loading…
Reference in New Issue