Merge "Rename image_create() to image_pull() at various locations"
This commit is contained in:
commit
a466ae755e
@ -20,7 +20,7 @@
|
|||||||
"container:kill": "rule:admin_or_user",
|
"container:kill": "rule:admin_or_user",
|
||||||
"container:run": "rule:default",
|
"container:run": "rule:default",
|
||||||
|
|
||||||
"image:create": "rule:default",
|
"image:pull": "rule:default",
|
||||||
"image:get_all": "rule:default",
|
"image:get_all": "rule:default",
|
||||||
|
|
||||||
"zun-service:get_all": "rule:admin_api"
|
"zun-service:get_all": "rule:admin_api"
|
||||||
|
@ -181,8 +181,8 @@ class ImagesController(rest.RestController):
|
|||||||
:param image: an image within the request body.
|
:param image: an image within the request body.
|
||||||
"""
|
"""
|
||||||
context = pecan.request.context
|
context = pecan.request.context
|
||||||
policy.enforce(context, "image:create",
|
policy.enforce(context, "image:pull",
|
||||||
action="image:create")
|
action="image:pull")
|
||||||
image_dict = Image(**image_dict).as_dict()
|
image_dict = Image(**image_dict).as_dict()
|
||||||
image_dict['project_id'] = context.project_id
|
image_dict['project_id'] = context.project_id
|
||||||
image_dict['user_id'] = context.user_id
|
image_dict['user_id'] = context.user_id
|
||||||
@ -190,8 +190,8 @@ class ImagesController(rest.RestController):
|
|||||||
image_dict['repo'], image_dict['tag'] = utils.parse_image_name(
|
image_dict['repo'], image_dict['tag'] = utils.parse_image_name(
|
||||||
repo_tag)
|
repo_tag)
|
||||||
new_image = objects.Image(context, **image_dict)
|
new_image = objects.Image(context, **image_dict)
|
||||||
new_image.create()
|
new_image.pull()
|
||||||
pecan.request.rpcapi.image_create(context, new_image)
|
pecan.request.rpcapi.image_pull(context, new_image)
|
||||||
# Set the HTTP Location Header
|
# Set the HTTP Location Header
|
||||||
pecan.response.location = link.build_url('images', new_image.uuid)
|
pecan.response.location = link.build_url('images', new_image.uuid)
|
||||||
pecan.response.status = 202
|
pecan.response.status = 202
|
||||||
|
@ -77,5 +77,5 @@ class API(rpc_service.API):
|
|||||||
def image_show(self, context, image):
|
def image_show(self, context, image):
|
||||||
return self._call('image_show', image=image)
|
return self._call('image_show', image=image)
|
||||||
|
|
||||||
def image_create(self, context, image):
|
def image_pull(self, context, image):
|
||||||
return self._cast('image_create', image=image)
|
return self._cast('image_pull', image=image)
|
||||||
|
@ -336,10 +336,10 @@ class Manager(object):
|
|||||||
six.text_type(e))
|
six.text_type(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def image_create(self, context, image):
|
def image_pull(self, context, image):
|
||||||
utils.spawn_n(self._do_image_create, context, image)
|
utils.spawn_n(self._do_image_pull, context, image)
|
||||||
|
|
||||||
def _do_image_create(self, context, image):
|
def _do_image_pull(self, context, image):
|
||||||
LOG.debug('Creating image...', context=context,
|
LOG.debug('Creating image...', context=context,
|
||||||
image=image)
|
image=image)
|
||||||
repo_tag = image.repo + ":" + image.tag
|
repo_tag = image.repo + ":" + image.tag
|
||||||
|
@ -220,7 +220,7 @@ class Connection(object):
|
|||||||
marker, sort_key, sort_dir)
|
marker, sort_key, sort_dir)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_image(cls, values):
|
def pull_image(cls, values):
|
||||||
"""Create a new image.
|
"""Create a new image.
|
||||||
|
|
||||||
:param values: A dict containing several items used to identify
|
:param values: A dict containing several items used to identify
|
||||||
@ -237,7 +237,7 @@ class Connection(object):
|
|||||||
:returns: An image.
|
:returns: An image.
|
||||||
"""
|
"""
|
||||||
dbdriver = get_instance()
|
dbdriver = get_instance()
|
||||||
return dbdriver.create_image(values)
|
return dbdriver.pull_image(values)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_image(self, image_id, values):
|
def update_image(self, image_id, values):
|
||||||
|
@ -293,7 +293,7 @@ class Connection(api.Connection):
|
|||||||
return _paginate_query(models.ZunService, limit, marker,
|
return _paginate_query(models.ZunService, limit, marker,
|
||||||
sort_key, sort_dir, query)
|
sort_key, sort_dir, query)
|
||||||
|
|
||||||
def create_image(self, values):
|
def pull_image(self, values):
|
||||||
# ensure defaults are present for new containers
|
# ensure defaults are present for new containers
|
||||||
if not values.get('uuid'):
|
if not values.get('uuid'):
|
||||||
values['uuid'] = uuidutils.generate_uuid()
|
values['uuid'] = uuidutils.generate_uuid()
|
||||||
|
@ -95,7 +95,7 @@ class Image(base.ZunPersistentObject, base.ZunObject,
|
|||||||
return Image._from_db_object_list(db_images, cls, context)
|
return Image._from_db_object_list(db_images, cls, context)
|
||||||
|
|
||||||
@base.remotable
|
@base.remotable
|
||||||
def create(self, context=None):
|
def pull(self, context=None):
|
||||||
"""Create an image record in the DB.
|
"""Create an image record in the DB.
|
||||||
|
|
||||||
:param context: Security context. NOTE: This should only
|
:param context: Security context. NOTE: This should only
|
||||||
@ -107,7 +107,7 @@ class Image(base.ZunPersistentObject, base.ZunObject,
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
values = self.obj_get_changes()
|
values = self.obj_get_changes()
|
||||||
db_image = dbapi.Connection.create_image(values)
|
db_image = dbapi.Connection.pull_image(values)
|
||||||
self._from_db_object(self, db_image)
|
self._from_db_object(self, db_image)
|
||||||
|
|
||||||
@base.remotable
|
@base.remotable
|
||||||
|
@ -22,9 +22,9 @@ from zun.tests.unit.db import utils
|
|||||||
|
|
||||||
|
|
||||||
class TestImageController(api_base.FunctionalTest):
|
class TestImageController(api_base.FunctionalTest):
|
||||||
@patch('zun.compute.api.API.image_create')
|
@patch('zun.compute.api.API.image_pull')
|
||||||
def test_image_create(self, mock_image_create):
|
def test_image_pull(self, mock_image_pull):
|
||||||
mock_image_create.side_effect = lambda x, y: y
|
mock_image_pull.side_effect = lambda x, y: y
|
||||||
|
|
||||||
params = ('{"repo": "hello-world"}')
|
params = ('{"repo": "hello-world"}')
|
||||||
response = self.app.post('/v1/images/',
|
response = self.app.post('/v1/images/',
|
||||||
@ -32,7 +32,7 @@ class TestImageController(api_base.FunctionalTest):
|
|||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(202, response.status_int)
|
||||||
self.assertTrue(mock_image_create.called)
|
self.assertTrue(mock_image_pull.called)
|
||||||
|
|
||||||
params = ('{"repo": "hello-world:test"}')
|
params = ('{"repo": "hello-world:test"}')
|
||||||
response = self.app.post('/v1/images/',
|
response = self.app.post('/v1/images/',
|
||||||
@ -40,20 +40,20 @@ class TestImageController(api_base.FunctionalTest):
|
|||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(202, response.status_int)
|
||||||
self.assertTrue(mock_image_create.called)
|
self.assertTrue(mock_image_pull.called)
|
||||||
|
|
||||||
@patch('zun.compute.api.API.image_create')
|
@patch('zun.compute.api.API.image_pull')
|
||||||
def test_image_create_with_no_repo(self, mock_image_create):
|
def test_image_pull_with_no_repo(self, mock_image_pull):
|
||||||
mock_image_create.side_effect = lambda x, y: y
|
mock_image_pull.side_effect = lambda x, y: y
|
||||||
|
|
||||||
self.assertRaises(AppError, self.app.post, '/v1/images/',
|
self.assertRaises(AppError, self.app.post, '/v1/images/',
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
self.assertTrue(mock_image_create.not_called)
|
self.assertTrue(mock_image_pull.not_called)
|
||||||
|
|
||||||
@patch('zun.compute.api.API.image_create')
|
@patch('zun.compute.api.API.image_pull')
|
||||||
def test_image_create_conflict(self, mock_image_create):
|
def test_image_pull_conflict(self, mock_image_pull):
|
||||||
mock_image_create.side_effect = lambda x, y: y
|
mock_image_pull.side_effect = lambda x, y: y
|
||||||
|
|
||||||
params = ('{"repo": "hello-world"}')
|
params = ('{"repo": "hello-world"}')
|
||||||
response = self.app.post('/v1/images/',
|
response = self.app.post('/v1/images/',
|
||||||
@ -61,28 +61,28 @@ class TestImageController(api_base.FunctionalTest):
|
|||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(202, response.status_int)
|
||||||
self.assertTrue(mock_image_create.called)
|
self.assertTrue(mock_image_pull.called)
|
||||||
self.assertRaises(AppError, self.app.post, '/v1/images/',
|
self.assertRaises(AppError, self.app.post, '/v1/images/',
|
||||||
params=params, content_type='application/json')
|
params=params, content_type='application/json')
|
||||||
self.assertTrue(mock_image_create.not_called)
|
self.assertTrue(mock_image_pull.not_called)
|
||||||
|
|
||||||
@patch('zun.compute.api.API.image_create')
|
@patch('zun.compute.api.API.image_pull')
|
||||||
def test_create_image_set_project_id_and_user_id(
|
def test_pull_image_set_project_id_and_user_id(
|
||||||
self, mock_image_create):
|
self, mock_image_pull):
|
||||||
def _create_side_effect(cnxt, image):
|
def _create_side_effect(cnxt, image):
|
||||||
self.assertEqual(self.context.project_id, image.project_id)
|
self.assertEqual(self.context.project_id, image.project_id)
|
||||||
self.assertEqual(self.context.user_id, image.user_id)
|
self.assertEqual(self.context.user_id, image.user_id)
|
||||||
return image
|
return image
|
||||||
mock_image_create.side_effect = _create_side_effect
|
mock_image_pull.side_effect = _create_side_effect
|
||||||
|
|
||||||
params = ('{"repo": "hello-world"}')
|
params = ('{"repo": "hello-world"}')
|
||||||
self.app.post('/v1/images/',
|
self.app.post('/v1/images/',
|
||||||
params=params,
|
params=params,
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
@patch('zun.compute.api.API.image_create')
|
@patch('zun.compute.api.API.image_pull')
|
||||||
def test_image_create_with_tag(self, mock_image_create):
|
def test_image_pull_with_tag(self, mock_image_pull):
|
||||||
mock_image_create.side_effect = lambda x, y: y
|
mock_image_pull.side_effect = lambda x, y: y
|
||||||
|
|
||||||
params = ('{"repo": "hello-world:latest"}')
|
params = ('{"repo": "hello-world:latest"}')
|
||||||
response = self.app.post('/v1/images/',
|
response = self.app.post('/v1/images/',
|
||||||
@ -90,7 +90,7 @@ class TestImageController(api_base.FunctionalTest):
|
|||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(202, response.status_int)
|
||||||
self.assertTrue(mock_image_create.called)
|
self.assertTrue(mock_image_pull.called)
|
||||||
|
|
||||||
@patch('zun.compute.api.API.image_show')
|
@patch('zun.compute.api.API.image_show')
|
||||||
@patch('zun.objects.Image.list')
|
@patch('zun.objects.Image.list')
|
||||||
@ -173,7 +173,7 @@ class TestImageEnforcement(api_base.FunctionalTest):
|
|||||||
def test_policy_disallow_create(self):
|
def test_policy_disallow_create(self):
|
||||||
params = ('{"repo": "foo"}')
|
params = ('{"repo": "foo"}')
|
||||||
self._common_policy_check(
|
self._common_policy_check(
|
||||||
'image:create', self.app.post, '/v1/images/',
|
'image:pull', self.app.post, '/v1/images/',
|
||||||
params=params,
|
params=params,
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
|
@ -21,18 +21,18 @@ from zun.tests.unit.db import utils
|
|||||||
|
|
||||||
class DbImageTestCase(base.DbTestCase):
|
class DbImageTestCase(base.DbTestCase):
|
||||||
|
|
||||||
def test_create_image(self):
|
def test_pull_image(self):
|
||||||
utils.create_test_image(repo="ubuntu:latest")
|
utils.create_test_image(repo="ubuntu:latest")
|
||||||
|
|
||||||
def test_create_image_duplicate_repo(self):
|
def test_pull_image_duplicate_repo(self):
|
||||||
utils.create_test_image(repo="ubuntu:latest")
|
utils.create_test_image(repo="ubuntu:latest")
|
||||||
utils.create_test_image(repo="ubuntu:14.04")
|
utils.create_test_image(repo="ubuntu:14.04")
|
||||||
|
|
||||||
def test_create_image_duplicate_tag(self):
|
def test_pull_image_duplicate_tag(self):
|
||||||
utils.create_test_image(repo="ubuntu:latest")
|
utils.create_test_image(repo="ubuntu:latest")
|
||||||
utils.create_test_image(repo="centos:latest")
|
utils.create_test_image(repo="centos:latest")
|
||||||
|
|
||||||
def test_create_image_already_exists(self):
|
def test_pull_image_already_exists(self):
|
||||||
utils.create_test_image(repo="ubuntu:latest")
|
utils.create_test_image(repo="ubuntu:latest")
|
||||||
self.assertRaises(exception.ResourceExists,
|
self.assertRaises(exception.ResourceExists,
|
||||||
utils.create_test_image,
|
utils.create_test_image,
|
||||||
|
@ -103,7 +103,7 @@ def create_test_image(**kw):
|
|||||||
if 'repo' not in kw:
|
if 'repo' not in kw:
|
||||||
image['repo'] = _generate_repo_for_image()
|
image['repo'] = _generate_repo_for_image()
|
||||||
dbapi = db_api.get_instance()
|
dbapi = db_api.get_instance()
|
||||||
return dbapi.create_image(image)
|
return dbapi.pull_image(image)
|
||||||
|
|
||||||
|
|
||||||
def _generate_repo_for_image():
|
def _generate_repo_for_image():
|
||||||
|
@ -72,13 +72,13 @@ class TestImageObject(base.DbTestCase):
|
|||||||
limit=None, marker=None,
|
limit=None, marker=None,
|
||||||
sort_key=None, sort_dir=None)
|
sort_key=None, sort_dir=None)
|
||||||
|
|
||||||
def test_create(self):
|
def test_pull(self):
|
||||||
with mock.patch.object(self.dbapi, 'create_image',
|
with mock.patch.object(self.dbapi, 'pull_image',
|
||||||
autospec=True) as mock_create_image:
|
autospec=True) as mock_pull_image:
|
||||||
mock_create_image.return_value = self.fake_image
|
mock_pull_image.return_value = self.fake_image
|
||||||
image = objects.Image(self.context, **self.fake_image)
|
image = objects.Image(self.context, **self.fake_image)
|
||||||
image.create()
|
image.pull()
|
||||||
mock_create_image.assert_called_once_with(self.fake_image)
|
mock_pull_image.assert_called_once_with(self.fake_image)
|
||||||
self.assertEqual(self.context, image._context)
|
self.assertEqual(self.context, image._context)
|
||||||
|
|
||||||
def test_save(self):
|
def test_save(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user