diff --git a/etc/zun/policy.json b/etc/zun/policy.json index dd00dffa9..909dce79f 100644 --- a/etc/zun/policy.json +++ b/etc/zun/policy.json @@ -20,7 +20,7 @@ "container:kill": "rule:admin_or_user", "container:run": "rule:default", - "image:create": "rule:default", + "image:pull": "rule:default", "image:get_all": "rule:default", "zun-service:get_all": "rule:admin_api" diff --git a/zun/api/controllers/v1/images.py b/zun/api/controllers/v1/images.py index fda101de9..e0fc48768 100644 --- a/zun/api/controllers/v1/images.py +++ b/zun/api/controllers/v1/images.py @@ -181,8 +181,8 @@ class ImagesController(rest.RestController): :param image: an image within the request body. """ context = pecan.request.context - policy.enforce(context, "image:create", - action="image:create") + policy.enforce(context, "image:pull", + action="image:pull") image_dict = Image(**image_dict).as_dict() image_dict['project_id'] = context.project_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( repo_tag) new_image = objects.Image(context, **image_dict) - new_image.create() - pecan.request.rpcapi.image_create(context, new_image) + new_image.pull() + pecan.request.rpcapi.image_pull(context, new_image) # Set the HTTP Location Header pecan.response.location = link.build_url('images', new_image.uuid) pecan.response.status = 202 diff --git a/zun/compute/api.py b/zun/compute/api.py index 8f3dd9883..057edc9fb 100644 --- a/zun/compute/api.py +++ b/zun/compute/api.py @@ -77,5 +77,5 @@ class API(rpc_service.API): def image_show(self, context, image): return self._call('image_show', image=image) - def image_create(self, context, image): - return self._cast('image_create', image=image) + def image_pull(self, context, image): + return self._cast('image_pull', image=image) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 767769377..3fbec9ac3 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -336,10 +336,10 @@ class Manager(object): six.text_type(e)) raise - def image_create(self, context, image): - utils.spawn_n(self._do_image_create, context, image) + def image_pull(self, 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, image=image) repo_tag = image.repo + ":" + image.tag diff --git a/zun/db/api.py b/zun/db/api.py index 7c7963428..e2f3dea66 100644 --- a/zun/db/api.py +++ b/zun/db/api.py @@ -220,7 +220,7 @@ class Connection(object): marker, sort_key, sort_dir) @classmethod - def create_image(cls, values): + def pull_image(cls, values): """Create a new image. :param values: A dict containing several items used to identify @@ -237,7 +237,7 @@ class Connection(object): :returns: An image. """ dbdriver = get_instance() - return dbdriver.create_image(values) + return dbdriver.pull_image(values) @classmethod def update_image(self, image_id, values): diff --git a/zun/db/sqlalchemy/api.py b/zun/db/sqlalchemy/api.py index 0b5735ef7..0922507ea 100644 --- a/zun/db/sqlalchemy/api.py +++ b/zun/db/sqlalchemy/api.py @@ -293,7 +293,7 @@ class Connection(api.Connection): return _paginate_query(models.ZunService, limit, marker, sort_key, sort_dir, query) - def create_image(self, values): + def pull_image(self, values): # ensure defaults are present for new containers if not values.get('uuid'): values['uuid'] = uuidutils.generate_uuid() diff --git a/zun/objects/image.py b/zun/objects/image.py index ba1c390d2..957beb2ba 100644 --- a/zun/objects/image.py +++ b/zun/objects/image.py @@ -95,7 +95,7 @@ class Image(base.ZunPersistentObject, base.ZunObject, return Image._from_db_object_list(db_images, cls, context) @base.remotable - def create(self, context=None): + def pull(self, context=None): """Create an image record in the DB. :param context: Security context. NOTE: This should only @@ -107,7 +107,7 @@ class Image(base.ZunPersistentObject, base.ZunObject, """ 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) @base.remotable diff --git a/zun/tests/unit/api/controllers/v1/test_images.py b/zun/tests/unit/api/controllers/v1/test_images.py index c7528c915..eb5676ae3 100644 --- a/zun/tests/unit/api/controllers/v1/test_images.py +++ b/zun/tests/unit/api/controllers/v1/test_images.py @@ -22,9 +22,9 @@ from zun.tests.unit.db import utils class TestImageController(api_base.FunctionalTest): - @patch('zun.compute.api.API.image_create') - def test_image_create(self, mock_image_create): - mock_image_create.side_effect = lambda x, y: y + @patch('zun.compute.api.API.image_pull') + def test_image_pull(self, mock_image_pull): + mock_image_pull.side_effect = lambda x, y: y params = ('{"repo": "hello-world"}') response = self.app.post('/v1/images/', @@ -32,7 +32,7 @@ class TestImageController(api_base.FunctionalTest): content_type='application/json') self.assertEqual(202, response.status_int) - self.assertTrue(mock_image_create.called) + self.assertTrue(mock_image_pull.called) params = ('{"repo": "hello-world:test"}') response = self.app.post('/v1/images/', @@ -40,20 +40,20 @@ class TestImageController(api_base.FunctionalTest): content_type='application/json') 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') - def test_image_create_with_no_repo(self, mock_image_create): - mock_image_create.side_effect = lambda x, y: y + @patch('zun.compute.api.API.image_pull') + def test_image_pull_with_no_repo(self, mock_image_pull): + mock_image_pull.side_effect = lambda x, y: y self.assertRaises(AppError, self.app.post, '/v1/images/', 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') - def test_image_create_conflict(self, mock_image_create): - mock_image_create.side_effect = lambda x, y: y + @patch('zun.compute.api.API.image_pull') + def test_image_pull_conflict(self, mock_image_pull): + mock_image_pull.side_effect = lambda x, y: y params = ('{"repo": "hello-world"}') response = self.app.post('/v1/images/', @@ -61,28 +61,28 @@ class TestImageController(api_base.FunctionalTest): content_type='application/json') 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/', 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') - def test_create_image_set_project_id_and_user_id( - self, mock_image_create): + @patch('zun.compute.api.API.image_pull') + def test_pull_image_set_project_id_and_user_id( + self, mock_image_pull): def _create_side_effect(cnxt, image): self.assertEqual(self.context.project_id, image.project_id) self.assertEqual(self.context.user_id, image.user_id) return image - mock_image_create.side_effect = _create_side_effect + mock_image_pull.side_effect = _create_side_effect params = ('{"repo": "hello-world"}') self.app.post('/v1/images/', params=params, content_type='application/json') - @patch('zun.compute.api.API.image_create') - def test_image_create_with_tag(self, mock_image_create): - mock_image_create.side_effect = lambda x, y: y + @patch('zun.compute.api.API.image_pull') + def test_image_pull_with_tag(self, mock_image_pull): + mock_image_pull.side_effect = lambda x, y: y params = ('{"repo": "hello-world:latest"}') response = self.app.post('/v1/images/', @@ -90,7 +90,7 @@ class TestImageController(api_base.FunctionalTest): content_type='application/json') 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.objects.Image.list') @@ -173,7 +173,7 @@ class TestImageEnforcement(api_base.FunctionalTest): def test_policy_disallow_create(self): params = ('{"repo": "foo"}') self._common_policy_check( - 'image:create', self.app.post, '/v1/images/', + 'image:pull', self.app.post, '/v1/images/', params=params, content_type='application/json', expect_errors=True) diff --git a/zun/tests/unit/db/test_image.py b/zun/tests/unit/db/test_image.py index f24ad687f..dee368241 100644 --- a/zun/tests/unit/db/test_image.py +++ b/zun/tests/unit/db/test_image.py @@ -21,18 +21,18 @@ from zun.tests.unit.db import utils class DbImageTestCase(base.DbTestCase): - def test_create_image(self): + def test_pull_image(self): 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: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="centos:latest") - def test_create_image_already_exists(self): + def test_pull_image_already_exists(self): utils.create_test_image(repo="ubuntu:latest") self.assertRaises(exception.ResourceExists, utils.create_test_image, diff --git a/zun/tests/unit/db/utils.py b/zun/tests/unit/db/utils.py index 25c3bbe31..1c459a974 100644 --- a/zun/tests/unit/db/utils.py +++ b/zun/tests/unit/db/utils.py @@ -103,7 +103,7 @@ def create_test_image(**kw): if 'repo' not in kw: image['repo'] = _generate_repo_for_image() dbapi = db_api.get_instance() - return dbapi.create_image(image) + return dbapi.pull_image(image) def _generate_repo_for_image(): diff --git a/zun/tests/unit/objects/test_image.py b/zun/tests/unit/objects/test_image.py index 1acf1a13c..aea266284 100644 --- a/zun/tests/unit/objects/test_image.py +++ b/zun/tests/unit/objects/test_image.py @@ -72,13 +72,13 @@ class TestImageObject(base.DbTestCase): limit=None, marker=None, sort_key=None, sort_dir=None) - def test_create(self): - with mock.patch.object(self.dbapi, 'create_image', - autospec=True) as mock_create_image: - mock_create_image.return_value = self.fake_image + def test_pull(self): + with mock.patch.object(self.dbapi, 'pull_image', + autospec=True) as mock_pull_image: + mock_pull_image.return_value = self.fake_image image = objects.Image(self.context, **self.fake_image) - image.create() - mock_create_image.assert_called_once_with(self.fake_image) + image.pull() + mock_pull_image.assert_called_once_with(self.fake_image) self.assertEqual(self.context, image._context) def test_save(self):