summaryrefslogtreecommitdiff
path: root/nova/tests/unit/image
diff options
context:
space:
mode:
authorMaciej Szankin <maciej.szankin@intel.com>2016-10-11 15:05:07 +0200
committerMaciej Szankin <maciej.szankin@intel.com>2016-10-12 12:21:59 +0000
commit97e7b97210139a7f7888f0d6901e499664de02a3 (patch)
tree764573f082e118f051ff38a247d81977358f0874 /nova/tests/unit/image
parenta8cf23864e7a3b81d95dc231a700efe7592388f6 (diff)
downloadnova-97e7b97210139a7f7888f0d6901e499664de02a3.tar.gz
conf: Remove deprecated ``use_glance_v1``
Glance option ``use_glance_v1`` was deprecated and listed as to be removed for Ocata. This patch removes it. Blueprint centralize-config-options-ocata Change-Id: Id891172418535a88fefb8ea05d774fe39dc14eaf
Diffstat (limited to 'nova/tests/unit/image')
-rw-r--r--nova/tests/unit/image/test_glance.py974
1 files changed, 1 insertions, 973 deletions
diff --git a/nova/tests/unit/image/test_glance.py b/nova/tests/unit/image/test_glance.py
index 514fb0e928..7025934859 100644
--- a/nova/tests/unit/image/test_glance.py
+++ b/nova/tests/unit/image/test_glance.py
@@ -14,7 +14,6 @@
# under the License.
-import collections
import copy
import datetime
@@ -489,7 +488,7 @@ class TestGlanceClientWrapperRetries(test.NoDBTestCase):
self.assertFalse(sleep_mock.called)
def _get_static_client(self, create_client_mock):
- version = 1 if CONF.glance.use_glance_v1 else 2
+ version = 2
url = 'http://host4:9295'
client = glance.GlanceClientWrapper(context=self.ctx, endpoint=url)
create_client_mock.assert_called_once_with(self.ctx, mock.ANY, version)
@@ -526,261 +525,8 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
"""
@mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_no_data_no_dest_path_v1(self, show_mock, open_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = mock.sentinel.image_chunks
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id)
-
- self.assertFalse(show_mock.called)
- self.assertFalse(open_mock.called)
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- self.assertEqual(mock.sentinel.image_chunks, res)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_data_no_dest_path_v1(self, show_mock, open_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- data = mock.MagicMock()
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id, data=data)
-
- self.assertFalse(show_mock.called)
- self.assertFalse(open_mock.called)
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- self.assertIsNone(res)
- data.write.assert_has_calls(
- [
- mock.call(1),
- mock.call(2),
- mock.call(3)
- ]
- )
- self.assertFalse(data.close.called)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_no_data_dest_path_v1(self, show_mock, open_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- writer = mock.MagicMock()
- open_mock.return_value = writer
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id,
- dst_path=mock.sentinel.dst_path)
-
- self.assertFalse(show_mock.called)
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- open_mock.assert_called_once_with(mock.sentinel.dst_path, 'wb')
- self.assertIsNone(res)
- writer.write.assert_has_calls(
- [
- mock.call(1),
- mock.call(2),
- mock.call(3)
- ]
- )
- writer.close.assert_called_once_with()
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_data_dest_path_v1(self, show_mock, open_mock):
- # NOTE(jaypipes): This really shouldn't be allowed, but because of the
- # horrible design of the download() method in GlanceImageService, no
- # error is raised, and the dst_path is ignored...
- # #TODO(jaypipes): Fix the aforementioned horrible design of
- # the download() method.
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- data = mock.MagicMock()
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id, data=data)
-
- self.assertFalse(show_mock.called)
- self.assertFalse(open_mock.called)
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- self.assertIsNone(res)
- data.write.assert_has_calls(
- [
- mock.call(1),
- mock.call(2),
- mock.call(3)
- ]
- )
- self.assertFalse(data.close.called)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_data_dest_path_write_fails_v1(
- self, show_mock, open_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
-
- # NOTE(mikal): data is a file like object, which in our case always
- # raises an exception when we attempt to write to the file.
- class FakeDiskException(Exception):
- pass
-
- class Exceptionator(StringIO):
- def write(self, _):
- raise FakeDiskException('Disk full!')
-
- self.assertRaises(FakeDiskException, service.download, ctx,
- mock.sentinel.image_id, data=Exceptionator())
-
- @mock.patch('nova.image.glance.GlanceImageService._get_transfer_module')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_direct_file_uri_v1(self, show_mock, get_tran_mock):
- self.flags(allowed_direct_url_schemes=['file'], group='glance')
- show_mock.return_value = {
- 'locations': [
- {
- 'url': 'file:///files/image',
- 'metadata': mock.sentinel.loc_meta
- }
- ]
- }
- tran_mod = mock.MagicMock()
- get_tran_mock.return_value = tran_mod
- client = mock.MagicMock()
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id,
- dst_path=mock.sentinel.dst_path)
-
- self.assertIsNone(res)
- self.assertFalse(client.call.called)
- show_mock.assert_called_once_with(ctx,
- mock.sentinel.image_id,
- include_locations=True)
- get_tran_mock.assert_called_once_with('file')
- tran_mod.download.assert_called_once_with(ctx, mock.ANY,
- mock.sentinel.dst_path,
- mock.sentinel.loc_meta)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService._get_transfer_module')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_direct_exception_fallback_v1(
- self, show_mock, get_tran_mock, open_mock):
- # Test that we fall back to downloading to the dst_path
- # if the download method of the transfer module raised
- # an exception.
- self.flags(use_glance_v1=True, group='glance')
- self.flags(allowed_direct_url_schemes=['file'], group='glance')
- show_mock.return_value = {
- 'locations': [
- {
- 'url': 'file:///files/image',
- 'metadata': mock.sentinel.loc_meta
- }
- ]
- }
- tran_mod = mock.MagicMock()
- tran_mod.download.side_effect = Exception
- get_tran_mock.return_value = tran_mod
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- writer = mock.MagicMock()
- open_mock.return_value = writer
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id,
- dst_path=mock.sentinel.dst_path)
-
- self.assertIsNone(res)
- show_mock.assert_called_once_with(ctx,
- mock.sentinel.image_id,
- include_locations=True)
- get_tran_mock.assert_called_once_with('file')
- tran_mod.download.assert_called_once_with(ctx, mock.ANY,
- mock.sentinel.dst_path,
- mock.sentinel.loc_meta)
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- # NOTE(jaypipes): log messages call open() in part of the
- # download path, so here, we just check that the last open()
- # call was done for the dst_path file descriptor.
- open_mock.assert_called_with(mock.sentinel.dst_path, 'wb')
- self.assertIsNone(res)
- writer.write.assert_has_calls(
- [
- mock.call(1),
- mock.call(2),
- mock.call(3)
- ]
- )
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.GlanceImageService._get_transfer_module')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_direct_no_mod_fallback_v1(
- self, show_mock, get_tran_mock, open_mock):
- # Test that we fall back to downloading to the dst_path
- # if no appropriate transfer module is found...
- # an exception.
- self.flags(use_glance_v1=True, group='glance')
- self.flags(allowed_direct_url_schemes=['funky'], group='glance')
- show_mock.return_value = {
- 'locations': [
- {
- 'url': 'file:///files/image',
- 'metadata': mock.sentinel.loc_meta
- }
- ]
- }
- get_tran_mock.return_value = None
- client = mock.MagicMock()
- client.call.return_value = [1, 2, 3]
- ctx = mock.sentinel.ctx
- writer = mock.MagicMock()
- open_mock.return_value = writer
- service = glance.GlanceImageService(client)
- res = service.download(ctx, mock.sentinel.image_id,
- dst_path=mock.sentinel.dst_path)
-
- self.assertIsNone(res)
- show_mock.assert_called_once_with(ctx,
- mock.sentinel.image_id,
- include_locations=True)
- get_tran_mock.assert_called_once_with('file')
- client.call.assert_called_once_with(ctx, 1, 'data',
- mock.sentinel.image_id)
- # NOTE(jaypipes): log messages call open() in part of the
- # download path, so here, we just check that the last open()
- # call was done for the dst_path file descriptor.
- open_mock.assert_called_with(mock.sentinel.dst_path, 'wb')
- self.assertIsNone(res)
- writer.write.assert_has_calls(
- [
- mock.call(1),
- mock.call(2),
- mock.call(3)
- ]
- )
- writer.close.assert_called_once_with()
-
- @mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_no_data_no_dest_path_v2(self, show_mock, open_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = mock.sentinel.image_chunks
ctx = mock.sentinel.ctx
@@ -796,7 +542,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_data_no_dest_path_v2(self, show_mock, open_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [1, 2, 3]
ctx = mock.sentinel.ctx
@@ -821,7 +566,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_no_data_dest_path_v2(self, show_mock, open_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [1, 2, 3]
ctx = mock.sentinel.ctx
@@ -853,7 +597,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
# error is raised, and the dst_path is ignored...
# #TODO(jaypipes): Fix the aforementioned horrible design of
# the download() method.
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [1, 2, 3]
ctx = mock.sentinel.ctx
@@ -879,7 +622,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_data_dest_path_write_fails_v2(
self, show_mock, open_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [1, 2, 3]
ctx = mock.sentinel.ctx
@@ -900,7 +642,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
@mock.patch('nova.image.glance.GlanceImageServiceV2._get_transfer_module')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_direct_file_uri_v2(self, show_mock, get_tran_mock):
- self.flags(use_glance_v1=False, group='glance')
self.flags(allowed_direct_url_schemes=['file'], group='glance')
show_mock.return_value = {
'locations': [
@@ -936,7 +677,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
# Test that we fall back to downloading to the dst_path
# if the download method of the transfer module raised
# an exception.
- self.flags(use_glance_v1=False, group='glance')
self.flags(allowed_direct_url_schemes=['file'], group='glance')
show_mock.return_value = {
'locations': [
@@ -989,7 +729,6 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
# Test that we fall back to downloading to the dst_path
# if no appropriate transfer module is found...
# an exception.
- self.flags(use_glance_v1=False, group='glance')
self.flags(allowed_direct_url_schemes=['funky'], group='glance')
show_mock.return_value = {
'locations': [
@@ -1065,135 +804,12 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
self.client.call.return_value = self.fake_img_data
@mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- @mock.patch('nova.signature_utils.get_verifier')
- def test_download_with_signature_verification_v1(self,
- mock_get_verifier,
- mock_show,
- mock_log):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_get_verifier.return_value = self.MockVerifier()
- mock_show.return_value = self.fake_img_props
- res = service.download(context=None, image_id=None,
- data=None, dst_path=None)
- self.assertEqual(self.fake_img_data, res)
- mock_get_verifier.assert_called_once_with(None,
- uuids.img_sig_cert_uuid,
- 'SHA-224',
- 'signature', 'RSA-PSS')
- mock_log.info.assert_called_once_with(mock.ANY, mock.ANY)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- @mock.patch('nova.signature_utils.get_verifier')
- def test_download_dst_path_signature_verification_v1(self,
- mock_get_verifier,
- mock_show,
- mock_log,
- mock_open):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_get_verifier.return_value = self.MockVerifier()
- mock_show.return_value = self.fake_img_props
- mock_dest = mock.MagicMock()
- fake_path = 'FAKE_PATH'
- mock_open.return_value = mock_dest
- service.download(context=None, image_id=None,
- data=None, dst_path=fake_path)
- mock_get_verifier.assert_called_once_with(None,
- uuids.img_sig_cert_uuid,
- 'SHA-224',
- 'signature', 'RSA-PSS')
- mock_log.info.assert_called_once_with(mock.ANY, mock.ANY)
- self.assertEqual(len(self.fake_img_data), mock_dest.write.call_count)
- self.assertTrue(mock_dest.close.called)
-
- @mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- @mock.patch('nova.signature_utils.get_verifier')
- def test_download_with_get_verifier_failure_v1(self,
- mock_get_verifier,
- mock_show,
- mock_log):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_get_verifier.side_effect = exception.SignatureVerificationError(
- reason='Signature verification '
- 'failed.'
- )
- mock_show.return_value = self.fake_img_props
- self.assertRaises(exception.SignatureVerificationError,
- service.download,
- context=None, image_id=None,
- data=None, dst_path=None)
- mock_log.error.assert_called_once_with(mock.ANY, mock.ANY)
-
- @mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- @mock.patch('nova.signature_utils.get_verifier')
- def test_download_with_invalid_signature_v1(self,
- mock_get_verifier,
- mock_show,
- mock_log):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_get_verifier.return_value = self.BadVerifier()
- mock_show.return_value = self.fake_img_props
- self.assertRaises(cryptography.exceptions.InvalidSignature,
- service.download,
- context=None, image_id=None,
- data=None, dst_path=None)
- mock_log.error.assert_called_once_with(mock.ANY, mock.ANY)
-
- @mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_missing_signature_metadata_v1(self,
- mock_show,
- mock_log):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_show.return_value = {'properties': {}}
- self.assertRaisesRegex(exception.SignatureVerificationError,
- 'Required image properties for signature '
- 'verification do not exist. Cannot verify '
- 'signature. Missing property: .*',
- service.download,
- context=None, image_id=None,
- data=None, dst_path=None)
-
- @mock.patch.object(six.moves.builtins, 'open')
- @mock.patch('nova.signature_utils.get_verifier')
- @mock.patch('nova.image.glance.LOG')
- @mock.patch('nova.image.glance.GlanceImageService.show')
- def test_download_dst_path_signature_fail_v1(self, mock_show,
- mock_log, mock_get_verifier,
- mock_open):
- self.flags(use_glance_v1=True, group='glance')
- service = glance.GlanceImageService(self.client)
- mock_get_verifier.return_value = self.BadVerifier()
- mock_dest = mock.MagicMock()
- fake_path = 'FAKE_PATH'
- mock_open.return_value = mock_dest
- mock_show.return_value = self.fake_img_props
- self.assertRaises(cryptography.exceptions.InvalidSignature,
- service.download,
- context=None, image_id=None,
- data=None, dst_path=fake_path)
- mock_log.error.assert_called_once_with(mock.ANY, mock.ANY)
- mock_open.assert_called_once_with(fake_path, 'wb')
- mock_dest.truncate.assert_called_once_with(0)
- self.assertTrue(mock_dest.close.called)
-
- @mock.patch('nova.image.glance.LOG')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
@mock.patch('nova.signature_utils.get_verifier')
def test_download_with_signature_verification_v2(self,
mock_get_verifier,
mock_show,
mock_log):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_get_verifier.return_value = self.MockVerifier()
mock_show.return_value = self.fake_img_props
@@ -1215,7 +831,6 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
mock_show,
mock_log,
mock_open):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_get_verifier.return_value = self.MockVerifier()
mock_show.return_value = self.fake_img_props
@@ -1239,7 +854,6 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
mock_get_verifier,
mock_show,
mock_log):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_get_verifier.side_effect = exception.SignatureVerificationError(
reason='Signature verification '
@@ -1259,7 +873,6 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
mock_get_verifier,
mock_show,
mock_log):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_get_verifier.return_value = self.BadVerifier()
mock_show.return_value = self.fake_img_props
@@ -1274,7 +887,6 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
def test_download_missing_signature_metadata_v2(self,
mock_show,
mock_log):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_show.return_value = {'properties': {}}
self.assertRaisesRegex(exception.SignatureVerificationError,
@@ -1292,7 +904,6 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
def test_download_dst_path_signature_fail_v2(self, mock_show,
mock_log, mock_get_verifier,
mock_open):
- self.flags(use_glance_v1=False, group='glance')
service = glance.GlanceImageServiceV2(self.client)
mock_get_verifier.return_value = self.BadVerifier()
mock_dest = mock.MagicMock()
@@ -1316,10 +927,6 @@ class TestIsImageAvailable(test.NoDBTestCase):
visibility = None
properties = None
- class ImageSpecV1(object):
- is_public = None
- properties = None
-
def test_auth_token_override(self):
ctx = mock.MagicMock(auth_token=True)
img = mock.MagicMock()
@@ -1348,14 +955,6 @@ class TestIsImageAvailable(test.NoDBTestCase):
res = glance._is_image_available(ctx, img)
self.assertTrue(res)
- def test_v1_is_public(self):
- ctx = mock.MagicMock(auth_token=False, is_admin=False)
- img = mock.MagicMock(is_public=True,
- spec=TestIsImageAvailable.ImageSpecV1)
-
- res = glance._is_image_available(ctx, img)
- self.assertTrue(res)
-
def test_project_is_owner(self):
ctx = mock.MagicMock(auth_token=False, is_admin=False,
project_id='123')
@@ -1368,13 +967,6 @@ class TestIsImageAvailable(test.NoDBTestCase):
res = glance._is_image_available(ctx, img)
self.assertTrue(res)
- ctx.reset_mock()
- img = mock.MagicMock(is_public=False, properties=props,
- spec=TestIsImageAvailable.ImageSpecV1)
-
- res = glance._is_image_available(ctx, img)
- self.assertTrue(res)
-
def test_project_context_matches_project_prop(self):
ctx = mock.MagicMock(auth_token=False, is_admin=False,
project_id='123')
@@ -1387,13 +979,6 @@ class TestIsImageAvailable(test.NoDBTestCase):
res = glance._is_image_available(ctx, img)
self.assertTrue(res)
- ctx.reset_mock()
- img = mock.MagicMock(is_public=False, properties=props,
- spec=TestIsImageAvailable.ImageSpecV1)
-
- res = glance._is_image_available(ctx, img)
- self.assertTrue(res)
-
def test_no_user_in_props(self):
ctx = mock.MagicMock(auth_token=False, is_admin=False,
project_id='123')
@@ -1405,13 +990,6 @@ class TestIsImageAvailable(test.NoDBTestCase):
res = glance._is_image_available(ctx, img)
self.assertFalse(res)
- ctx.reset_mock()
- img = mock.MagicMock(is_public=False, properties=props,
- spec=TestIsImageAvailable.ImageSpecV1)
-
- res = glance._is_image_available(ctx, img)
- self.assertFalse(res)
-
def test_user_matches_context(self):
ctx = mock.MagicMock(auth_token=False, is_admin=False,
user_id='123')
@@ -1424,183 +1002,13 @@ class TestIsImageAvailable(test.NoDBTestCase):
res = glance._is_image_available(ctx, img)
self.assertTrue(res)
- ctx.reset_mock()
- img = mock.MagicMock(is_public=False, properties=props,
- spec=TestIsImageAvailable.ImageSpecV1)
-
- res = glance._is_image_available(ctx, img)
- self.assertTrue(res)
-
class TestShow(test.NoDBTestCase):
"""Tests the show method of the GlanceImageService."""
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_show_success_v1(self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- is_avail_mock.return_value = True
- trans_from_mock.return_value = {'mock': mock.sentinel.trans_from}
- client = mock.MagicMock()
- client.call.return_value = {}
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- info = service.show(ctx, mock.sentinel.image_id)
-
- client.call.assert_called_once_with(ctx, 1, 'get',
- mock.sentinel.image_id)
- is_avail_mock.assert_called_once_with(ctx, {})
- trans_from_mock.assert_called_once_with({}, include_locations=False)
- self.assertIn('mock', info)
- self.assertEqual(mock.sentinel.trans_from, info['mock'])
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_show_not_available_v1(self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- is_avail_mock.return_value = False
- client = mock.MagicMock()
- client.call.return_value = mock.sentinel.images_0
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
-
- with testtools.ExpectedException(exception.ImageNotFound):
- service.show(ctx, mock.sentinel.image_id)
-
- client.call.assert_called_once_with(ctx, 1, 'get',
- mock.sentinel.image_id)
- is_avail_mock.assert_called_once_with(ctx, mock.sentinel.images_0)
- self.assertFalse(trans_from_mock.called)
-
- @mock.patch('nova.image.glance._reraise_translated_image_exception')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_show_client_failure_v1(self, is_avail_mock, trans_from_mock,
- reraise_mock):
- self.flags(use_glance_v1=True, group='glance')
- raised = exception.ImageNotAuthorized(image_id=123)
- client = mock.MagicMock()
- client.call.side_effect = glanceclient.exc.Forbidden
- ctx = mock.sentinel.ctx
- reraise_mock.side_effect = raised
- service = glance.GlanceImageService(client)
-
- with testtools.ExpectedException(exception.ImageNotAuthorized):
- service.show(ctx, mock.sentinel.image_id)
- client.call.assert_called_once_with(ctx, 1, 'get',
- mock.sentinel.image_id)
- self.assertFalse(is_avail_mock.called)
- self.assertFalse(trans_from_mock.called)
- reraise_mock.assert_called_once_with(mock.sentinel.image_id)
-
- @mock.patch('nova.image.glance._is_image_available')
- def test_show_queued_image_without_some_attrs_v1(self, is_avail_mock):
- self.flags(use_glance_v1=True, group='glance')
- is_avail_mock.return_value = True
- client = mock.MagicMock()
-
- # fake image cls without disk_format, container_format, name attributes
- class fake_image_cls(dict):
- id = 'b31aa5dd-f07a-4748-8f15-398346887584'
- deleted = False
- protected = False
- min_disk = 0
- created_at = '2014-05-20T08:16:48'
- size = 0
- status = 'queued'
- is_public = False
- min_ram = 0
- owner = '980ec4870033453ead65c0470a78b8a8'
- updated_at = '2014-05-20T08:16:48'
- glance_image = fake_image_cls()
- client.call.return_value = glance_image
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- image_info = service.show(ctx, glance_image.id)
- client.call.assert_called_once_with(ctx, 1, 'get',
- glance_image.id)
- NOVA_IMAGE_ATTRIBUTES = set(['size', 'disk_format', 'owner',
- 'container_format', 'status', 'id',
- 'name', 'created_at', 'updated_at',
- 'deleted', 'deleted_at', 'checksum',
- 'min_disk', 'min_ram', 'is_public',
- 'properties'])
-
- self.assertEqual(NOVA_IMAGE_ATTRIBUTES, set(image_info.keys()))
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_include_locations_success_v1(self, avail_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- locations = [mock.sentinel.loc1]
- avail_mock.return_value = True
- trans_from_mock.return_value = {'locations': locations}
-
- client = mock.Mock()
- client.call.return_value = mock.sentinel.image
- service = glance.GlanceImageService(client)
- ctx = mock.sentinel.ctx
- image_id = mock.sentinel.image_id
- info = service.show(ctx, image_id, include_locations=True)
-
- client.call.assert_called_once_with(ctx, 2, 'get', image_id)
- avail_mock.assert_called_once_with(ctx, mock.sentinel.image)
- trans_from_mock.assert_called_once_with(mock.sentinel.image,
- include_locations=True)
- self.assertIn('locations', info)
- self.assertEqual(locations, info['locations'])
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_include_direct_uri_success_v1(self, avail_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- locations = [mock.sentinel.loc1]
- avail_mock.return_value = True
- trans_from_mock.return_value = {'locations': locations,
- 'direct_uri': mock.sentinel.duri}
-
- client = mock.Mock()
- client.call.return_value = mock.sentinel.image
- service = glance.GlanceImageService(client)
- ctx = mock.sentinel.ctx
- image_id = mock.sentinel.image_id
- info = service.show(ctx, image_id, include_locations=True)
-
- client.call.assert_called_once_with(ctx, 2, 'get', image_id)
- expected = locations
- expected.append({'url': mock.sentinel.duri, 'metadata': {}})
- self.assertIn('locations', info)
- self.assertEqual(expected, info['locations'])
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_do_not_show_deleted_images_v1(
- self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
-
- class fake_image_cls(dict):
- id = 'b31aa5dd-f07a-4748-8f15-398346887584'
- deleted = True
-
- glance_image = fake_image_cls()
- client = mock.MagicMock()
- client.call.return_value = glance_image
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
-
- with testtools.ExpectedException(exception.ImageNotFound):
- service.show(ctx, glance_image.id, show_deleted=False)
-
- client.call.assert_called_once_with(ctx, 1, 'get',
- glance_image.id)
- self.assertFalse(is_avail_mock.called)
- self.assertFalse(trans_from_mock.called)
-
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_show_success_v2(self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
is_avail_mock.return_value = True
trans_from_mock.return_value = {'mock': mock.sentinel.trans_from}
client = mock.MagicMock()
@@ -1619,7 +1027,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_show_not_available_v2(self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
is_avail_mock.return_value = False
client = mock.MagicMock()
client.call.return_value = mock.sentinel.images_0
@@ -1639,7 +1046,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._is_image_available')
def test_show_client_failure_v2(self, is_avail_mock, trans_from_mock,
reraise_mock):
- self.flags(use_glance_v1=False, group='glance')
raised = exception.ImageNotAuthorized(image_id=123)
client = mock.MagicMock()
client.call.side_effect = glanceclient.exc.Forbidden
@@ -1659,7 +1065,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._is_image_available')
def test_show_queued_image_without_some_attrs_v2(self, is_avail_mock,
mocked_schema):
- self.flags(use_glance_v1=False, group='glance')
is_avail_mock.return_value = True
client = mock.MagicMock()
@@ -1700,7 +1105,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_include_locations_success_v2(self, avail_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
locations = [mock.sentinel.loc1]
avail_mock.return_value = True
trans_from_mock.return_value = {'locations': locations}
@@ -1722,7 +1126,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_include_direct_uri_success_v2(self, avail_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
locations = [mock.sentinel.loc1]
avail_mock.return_value = True
trans_from_mock.return_value = {'locations': locations,
@@ -1745,7 +1148,6 @@ class TestShow(test.NoDBTestCase):
@mock.patch('nova.image.glance._is_image_available')
def test_do_not_show_deleted_images_v2(
self, is_avail_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
class fake_image_cls(dict):
id = 'b31aa5dd-f07a-4748-8f15-398346887584'
@@ -1770,96 +1172,11 @@ class TestDetail(test.NoDBTestCase):
"""Tests the detail method of the GlanceImageService."""
- @mock.patch('nova.image.glance._extract_query_params')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_detail_success_available_v1(self, is_avail_mock, trans_from_mock,
- ext_query_mock):
- self.flags(use_glance_v1=True, group='glance')
- params = {}
- is_avail_mock.return_value = True
- ext_query_mock.return_value = params
- trans_from_mock.return_value = mock.sentinel.trans_from
- client = mock.MagicMock()
- client.call.return_value = [mock.sentinel.images_0]
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- images = service.detail(ctx, **params)
-
- client.call.assert_called_once_with(ctx, 1, 'list')
- is_avail_mock.assert_called_once_with(ctx, mock.sentinel.images_0)
- trans_from_mock.assert_called_once_with(mock.sentinel.images_0)
- self.assertEqual([mock.sentinel.trans_from], images)
-
- @mock.patch('nova.image.glance._extract_query_params')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_detail_success_unavailable_v1(
- self, is_avail_mock, trans_from_mock, ext_query_mock):
- self.flags(use_glance_v1=True, group='glance')
- params = {}
- is_avail_mock.return_value = False
- ext_query_mock.return_value = params
- trans_from_mock.return_value = mock.sentinel.trans_from
- client = mock.MagicMock()
- client.call.return_value = [mock.sentinel.images_0]
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- images = service.detail(ctx, **params)
-
- client.call.assert_called_once_with(ctx, 1, 'list')
- is_avail_mock.assert_called_once_with(ctx, mock.sentinel.images_0)
- self.assertFalse(trans_from_mock.called)
- self.assertEqual([], images)
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_detail_params_passed_v1(self, is_avail_mock, _trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [mock.sentinel.images_0]
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- service.detail(ctx, page_size=5, limit=10)
-
- expected_filters = {
- 'is_public': 'none'
- }
- client.call.assert_called_once_with(ctx, 1, 'list',
- filters=expected_filters,
- page_size=5,
- limit=10)
-
- @mock.patch('nova.image.glance._reraise_translated_exception')
- @mock.patch('nova.image.glance._extract_query_params')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_detail_client_failure_v1(self, is_avail_mock, trans_from_mock,
- ext_query_mock, reraise_mock):
- self.flags(use_glance_v1=True, group='glance')
- params = {}
- ext_query_mock.return_value = params
- raised = exception.Forbidden()
- client = mock.MagicMock()
- client.call.side_effect = glanceclient.exc.Forbidden
- ctx = mock.sentinel.ctx
- reraise_mock.side_effect = raised
- service = glance.GlanceImageService(client)
-
- with testtools.ExpectedException(exception.Forbidden):
- service.detail(ctx, **params)
-
- client.call.assert_called_once_with(ctx, 1, 'list')
- self.assertFalse(is_avail_mock.called)
- self.assertFalse(trans_from_mock.called)
- reraise_mock.assert_called_once_with()
-
@mock.patch('nova.image.glance._extract_query_params_v2')
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_detail_success_available_v2(self, is_avail_mock, trans_from_mock,
ext_query_mock):
- self.flags(use_glance_v1=False, group='glance')
params = {}
is_avail_mock.return_value = True
ext_query_mock.return_value = params
@@ -1880,7 +1197,6 @@ class TestDetail(test.NoDBTestCase):
@mock.patch('nova.image.glance._is_image_available')
def test_detail_success_unavailable_v2(
self, is_avail_mock, trans_from_mock, ext_query_mock):
- self.flags(use_glance_v1=False, group='glance')
params = {}
is_avail_mock.return_value = False
ext_query_mock.return_value = params
@@ -1899,7 +1215,6 @@ class TestDetail(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_detail_params_passed_v2(self, is_avail_mock, _trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [mock.sentinel.images_0]
ctx = mock.sentinel.ctx
@@ -1917,7 +1232,6 @@ class TestDetail(test.NoDBTestCase):
@mock.patch('nova.image.glance._is_image_available')
def test_detail_client_failure_v2(self, is_avail_mock, trans_from_mock,
ext_query_mock, reraise_mock):
- self.flags(use_glance_v1=False, group='glance')
params = {}
ext_query_mock.return_value = params
raised = exception.Forbidden()
@@ -1942,41 +1256,8 @@ class TestCreate(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._translate_to_glance')
- def test_create_success_v1(self, trans_to_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- translated = {
- 'image_id': mock.sentinel.image_id
- }
- trans_to_mock.return_value = translated
- trans_from_mock.return_value = mock.sentinel.trans_from
- image_mock = mock.MagicMock(spec=dict)
- client = mock.MagicMock()
- client.call.return_value = mock.sentinel.image_meta
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- image_meta = service.create(ctx, image_mock)
-
- trans_to_mock.assert_called_once_with(image_mock,)
- client.call.assert_called_once_with(ctx, 1, 'create',
- image_id=mock.sentinel.image_id)
- trans_from_mock.assert_called_once_with(mock.sentinel.image_meta)
-
- self.assertEqual(mock.sentinel.trans_from, image_meta)
-
- # Now verify that if we supply image data to the call,
- # that the client is also called with the data kwarg
- client.reset_mock()
- service.create(ctx, image_mock, data=mock.sentinel.data)
-
- client.call.assert_called_once_with(ctx, 1, 'create',
- image_id=mock.sentinel.image_id,
- data=mock.sentinel.data)
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._translate_to_glance')
def test_create_success_v2(
self, trans_to_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
translated = {
'name': mock.sentinel.name,
}
@@ -2013,7 +1294,6 @@ class TestCreate(test.NoDBTestCase):
"""Tests that creating an image with the v2 API with a size of 0 will
trigger a call to set the disk and container formats.
"""
- self.flags(use_glance_v1=False, group='glance')
translated = {
'name': mock.sentinel.name,
}
@@ -2041,7 +1321,6 @@ class TestCreate(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_to_glance')
def test_create_success_v2_with_location(
self, trans_to_mock, trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
translated = {
'id': mock.sentinel.id,
'name': mock.sentinel.name,
@@ -2063,29 +1342,8 @@ class TestCreate(test.NoDBTestCase):
@mock.patch('nova.image.glance._reraise_translated_exception')
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._translate_to_glance')
- def test_create_client_failure_v1(self, trans_to_mock, trans_from_mock,
- reraise_mock):
- self.flags(use_glance_v1=True, group='glance')
- translated = {}
- trans_to_mock.return_value = translated
- image_mock = mock.MagicMock(spec=dict)
- raised = exception.Invalid()
- client = mock.MagicMock()
- client.call.side_effect = glanceclient.exc.BadRequest
- ctx = mock.sentinel.ctx
- reraise_mock.side_effect = raised
- service = glance.GlanceImageService(client)
-
- self.assertRaises(exception.Invalid, service.create, ctx, image_mock)
- trans_to_mock.assert_called_once_with(image_mock)
- self.assertFalse(trans_from_mock.called)
-
- @mock.patch('nova.image.glance._reraise_translated_exception')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._translate_to_glance')
def test_create_client_failure_v2(self, trans_to_mock, trans_from_mock,
reraise_mock):
- self.flags(use_glance_v1=False, group='glance')
translated = {}
trans_to_mock.return_value = translated
image_mock = mock.MagicMock(spec=dict)
@@ -2164,56 +1422,11 @@ class TestCreate(test.NoDBTestCase):
class TestUpdate(test.NoDBTestCase):
"""Tests the update method of the GlanceImageService."""
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._translate_to_glance')
- def test_update_success_v1(
- self, trans_to_mock, trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- translated = {
- 'id': mock.sentinel.image_id,
- 'name': mock.sentinel.name
- }
- trans_to_mock.return_value = translated
- trans_from_mock.return_value = mock.sentinel.trans_from
- image_mock = mock.MagicMock(spec=dict)
- client = mock.MagicMock()
- client.call.return_value = mock.sentinel.image_meta
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- image_meta = service.update(
- ctx, mock.sentinel.image_id, image_mock, purge_props=True)
-
- trans_to_mock.assert_called_once_with(image_mock)
- # Verify that the 'id' element has been removed as a kwarg to
- # the call to glanceclient's update (since the image ID is
- # supplied as a positional arg), and that the
- # purge_props default is True.
- client.call.assert_called_once_with(ctx, 1, 'update',
- mock.sentinel.image_id,
- name=mock.sentinel.name,
- purge_props=True)
- trans_from_mock.assert_called_once_with(mock.sentinel.image_meta)
- self.assertEqual(mock.sentinel.trans_from, image_meta)
-
- # Now verify that if we supply image data to the call,
- # that the client is also called with the data kwarg
- client.reset_mock()
- service.update(ctx, mock.sentinel.image_id,
- image_mock, data=mock.sentinel.data)
-
- client.call.assert_called_once_with(ctx, 1, 'update',
- mock.sentinel.image_id,
- name=mock.sentinel.name,
- purge_props=True,
- data=mock.sentinel.data)
-
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._translate_to_glance')
def test_update_success_v2(
self, trans_to_mock, trans_from_mock, show_mock):
- self.flags(use_glance_v1=False, group='glance')
image = {
'id': mock.sentinel.image_id,
'name': mock.sentinel.name,
@@ -2268,7 +1481,6 @@ class TestUpdate(test.NoDBTestCase):
@mock.patch('nova.image.glance._translate_to_glance')
def test_update_success_v2_with_location(
self, trans_to_mock, trans_from_mock, show_mock):
- self.flags(use_glance_v1=False, group='glance')
translated = {
'id': mock.sentinel.id,
'name': mock.sentinel.name,
@@ -2289,42 +1501,12 @@ class TestUpdate(test.NoDBTestCase):
trans_from_mock.assert_called_once_with(translated)
self.assertEqual(mock.sentinel.trans_from, image_meta)
- @mock.patch('nova.image.glance._reraise_translated_image_exception')
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._translate_to_glance')
- def test_update_client_failure_v1(self, trans_to_mock, trans_from_mock,
- reraise_mock):
- self.flags(use_glance_v1=True, group='glance')
- translated = {
- 'name': mock.sentinel.name
- }
- trans_to_mock.return_value = translated
- trans_from_mock.return_value = mock.sentinel.trans_from
- image_mock = mock.MagicMock(spec=dict)
- raised = exception.ImageNotAuthorized(image_id=123)
- client = mock.MagicMock()
- client.call.side_effect = glanceclient.exc.Forbidden
- ctx = mock.sentinel.ctx
- reraise_mock.side_effect = raised
- service = glance.GlanceImageService(client)
-
- self.assertRaises(exception.ImageNotAuthorized,
- service.update, ctx, mock.sentinel.image_id,
- image_mock)
- client.call.assert_called_once_with(ctx, 1, 'update',
- mock.sentinel.image_id,
- purge_props=True,
- name=mock.sentinel.name)
- self.assertFalse(trans_from_mock.called)
- reraise_mock.assert_called_once_with(mock.sentinel.image_id)
-
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
@mock.patch('nova.image.glance._reraise_translated_image_exception')
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._translate_to_glance')
def test_update_client_failure_v2(self, trans_to_mock, trans_from_mock,
reraise_mock, show_mock):
- self.flags(use_glance_v1=False, group='glance')
image = {
'id': mock.sentinel.image_id,
'name': mock.sentinel.name,
@@ -2365,27 +1547,7 @@ class TestDelete(test.NoDBTestCase):
"""Tests the delete method of the GlanceImageService."""
- def test_delete_success_v1(self):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = True
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- service.delete(ctx, mock.sentinel.image_id)
- client.call.assert_called_once_with(ctx, 1, 'delete',
- mock.sentinel.image_id)
-
- def test_delete_client_failure_v1(self):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.side_effect = glanceclient.exc.NotFound
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- self.assertRaises(exception.ImageNotFound, service.delete, ctx,
- mock.sentinel.image_id)
-
def test_delete_success_v2(self):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = True
ctx = mock.sentinel.ctx
@@ -2395,7 +1557,6 @@ class TestDelete(test.NoDBTestCase):
mock.sentinel.image_id)
def test_delete_client_failure_v2(self):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.side_effect = glanceclient.exc.NotFound
ctx = mock.sentinel.ctx
@@ -2438,30 +1599,9 @@ class TestUpdateGlanceImage(test.NoDBTestCase):
class TestExtractAttributes(test.NoDBTestCase):
- """Test that image output translations from v1 and v2 are the same"""
-
- @mock.patch.object(schemas, 'Schema', side_effect=FakeSchema)
- def test_extract_image_attributes_active_images_no_locations(
- self, mocked_schema):
- image_v1_dict = image_fixtures['active_image_v1']
- image_v2 = ImageV2(image_fixtures['active_image_v2'])
-
- image_v1 = collections.namedtuple('_', image_v1_dict.keys())(
- **image_v1_dict)
-
- self.flags(use_glance_v1=True, group='glance')
- v1_output = glance._translate_from_glance(
- image_v1, include_locations=False)
- self.flags(use_glance_v1=False, group='glance')
- v2_output = glance._translate_from_glance(
- image_v2, include_locations=False)
- self.assertEqual(v1_output, v2_output)
-
@mock.patch.object(schemas, 'Schema', side_effect=FakeSchema)
def test_extract_image_attributes_active_images_with_locations(
self, mocked_schema):
- # Glance API v1 doesn't provide info about locations
- self.flags(use_glance_v1=False, group='glance')
image_v2 = ImageV2(image_fixtures['active_image_v2'])
image_v2_meta = glance._translate_from_glance(
@@ -2476,96 +1616,12 @@ class TestExtractAttributes(test.NoDBTestCase):
self.assertNotIn('locations', image_v2_meta)
self.assertNotIn('direct_url', image_v2_meta)
- @mock.patch.object(schemas, 'Schema', side_effect=FakeSchema)
- def test_extract_image_attributes_empty_images(self, mocked_schema):
- image_v1_dict = image_fixtures['empty_image_v1']
- image_v2 = ImageV2(image_fixtures['empty_image_v2'])
-
- image_v1 = collections.namedtuple('_', image_v1_dict.keys())(
- **image_v1_dict)
-
- self.flags(use_glance_v1=True, group='glance')
- v1_output = glance._translate_from_glance(
- image_v1, include_locations=False)
- self.flags(use_glance_v1=False, group='glance')
- v2_output = glance._translate_from_glance(
- image_v2, include_locations=False)
- self.assertEqual(v1_output, v2_output)
-
- @mock.patch.object(schemas, 'Schema', side_effect=FakeSchema)
- def test_extract_image_attributes_empty_images_no_size(self,
- mocked_schema):
- image_v1_dict = dict(image_fixtures['empty_image_v1'])
- # pop the size attribute since it might not be set on a snapshot image
- image_v1_dict.pop('size')
- image_v2 = ImageV2(image_fixtures['empty_image_v2'])
-
- image_v1 = collections.namedtuple('_', image_v1_dict.keys())(
- **image_v1_dict)
-
- self.flags(use_glance_v1=True, group='glance')
- v1_output = glance._translate_from_glance(
- image_v1, include_locations=False)
- self.flags(use_glance_v1=False, group='glance')
- v2_output = glance._translate_from_glance(
- image_v2, include_locations=False)
- self.assertEqual(v1_output, v2_output)
-
- @mock.patch.object(schemas, 'Schema', side_effect=FakeSchema)
- def test_extract_image_attributes_active_images_custom_prop(
- self, mocked_schema):
- image_v1_dict = image_fixtures['custom_property_image_v1']
- image_v2 = ImageV2(image_fixtures['custom_property_image_v2'])
-
- image_v1 = collections.namedtuple('_', image_v1_dict.keys())(
- **image_v1_dict)
-
- self.flags(use_glance_v1=True, group='glance')
- v1_output = glance._translate_from_glance(
- image_v1, include_locations=False)
- self.flags(use_glance_v1=False, group='glance')
- v2_output = glance._translate_from_glance(
- image_v2, include_locations=False)
- self.assertEqual(v1_output, v2_output)
-
class TestExtractQueryParams(test.NoDBTestCase):
- """Test that list in v1 and v2 can work with the same query parameters"""
-
- @mock.patch('nova.image.glance._translate_from_glance')
- @mock.patch('nova.image.glance._is_image_available')
- def test_detail_extract_query_params_v1(
- self, is_avail_mock, _trans_from_mock):
- self.flags(use_glance_v1=True, group='glance')
- client = mock.MagicMock()
- client.call.return_value = [mock.sentinel.images_0]
- ctx = mock.sentinel.ctx
- service = glance.GlanceImageService(client)
- input_filters = {
- 'property-kernel-id': 'some-id',
- 'changes-since': 'some-date',
- 'is_public': 'true',
- 'name': 'some-name'
- }
-
- service.detail(ctx, filters=input_filters, page_size=5, limit=10)
-
- expected_filters_v1 = {
- 'property-kernel-id': 'some-id',
- 'name': 'some-name',
- 'is_public': 'true',
- 'changes-since': 'some-date'}
-
- client.call.assert_called_once_with(ctx, 1, 'list',
- filters=expected_filters_v1,
- page_size=5,
- limit=10)
-
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._is_image_available')
def test_detail_extract_query_params_v2(
self, is_avail_mock, _trans_from_mock):
- self.flags(use_glance_v1=False, group='glance')
client = mock.MagicMock()
client.call.return_value = [mock.sentinel.images_0]
ctx = mock.sentinel.ctx
@@ -2621,34 +1677,6 @@ class TestTranslateToGlance(test.NoDBTestCase):
'updated_at': ""}
super(TestTranslateToGlance, self).setUp()
- def test_convert_to_v1(self):
- self.flags(use_glance_v1=True, group='glance')
- expected_v1_image = {
- 'checksum': 'fb10c6486390bec8414be90a93dfff3b',
- 'container_format': 'bare',
- 'deleted': False,
- 'disk_format': 'raw',
- 'id': 'f8116538-309f-449c-8d49-df252a97a48d',
- 'is_public': True,
- 'min_disk': '0',
- 'min_ram': '0',
- 'name': 'tempest-image-1294122904',
- 'owner': 'd76b51cf8a44427ea404046f4c1d82ab',
- 'properties': {
- 'base_image_ref': 'ea36315c-e527-4643-a46a-9fd61d027cc1',
- 'image_type': 'test',
- 'instance_uuid': 'ec1ea9c7-8c5e-498d-a753-6ccc2464123c',
- 'kernel_id': 'None',
- 'os_distro': 'value2',
- 'os_version': 'value1',
- 'ramdisk_id': ' ',
- 'user_id': 'ca2ff78fd33042ceb45fbbe19012ef3f',
- 'boolean_prop': True},
- 'size': 1024}
- nova_image_dict = self.fixture
- image_v1_dict = glance._translate_to_glance(nova_image_dict)
- self.assertEqual(expected_v1_image, image_v1_dict)
-
def test_convert_to_v2(self):
expected_v2_image = {
'base_image_ref': 'ea36315c-e527-4643-a46a-9fd61d027cc1',