Merge "Glance wrapper: De-obfuscate image fetching"
This commit is contained in:
commit
b6c69603b8
@ -26,7 +26,6 @@ from rally.plugins.openstack.scenarios.keystone import utils as kutils
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
from rally.plugins.openstack.wrappers import glance as glance_wrapper
|
||||
from rally.plugins.openstack.wrappers import keystone as keystone_wrapper
|
||||
from rally.task import utils as task_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -386,24 +385,15 @@ class ManilaSecurityService(base.ResourceManager):
|
||||
@base.resource("glance", "images", order=500, tenant_resource=True)
|
||||
class GlanceImage(base.ResourceManager):
|
||||
|
||||
def _manager(self):
|
||||
def _wrapper(self):
|
||||
return glance_wrapper.wrap(
|
||||
getattr(self.admin or self.user, self._service), self)
|
||||
|
||||
def list(self):
|
||||
return self._manager().list_images(owner=self.tenant_uuid)
|
||||
|
||||
def is_deleted(self):
|
||||
try:
|
||||
resource = self._manager().get_image(self.raw_resource)
|
||||
except Exception as e:
|
||||
return getattr(e, "code", getattr(e, "http_status", 400)) == 404
|
||||
|
||||
return task_utils.get_status(resource) in ("DELETED",
|
||||
"DELETE_COMPLETE")
|
||||
return self._wrapper().list_images(owner=self.tenant_uuid)
|
||||
|
||||
def delete(self):
|
||||
return self._manager().delete_image(self.raw_resource)
|
||||
return self._wrapper().delete_image(self.raw_resource)
|
||||
|
||||
|
||||
# SAHARA
|
||||
|
@ -117,4 +117,4 @@ class ImageGenerator(context.Context):
|
||||
api_info=self.context["config"].get("api_versions"))
|
||||
glance_wrap = glance_wrapper.wrap(clients.glance, self)
|
||||
for image in self.context["tenants"][tenant_id].get("images", []):
|
||||
glance_wrap.delete_image(glance_wrap.get_image(image))
|
||||
glance_wrap.delete_image(clients.glance().images.get(image))
|
||||
|
@ -60,10 +60,6 @@ class GlanceWrapper(object):
|
||||
self.owner = owner
|
||||
self.client = client
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_image(self, image):
|
||||
"""Refresh an image from an image object."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def create_image(self, container_format, image_location, disk_format):
|
||||
"""Creates new image."""
|
||||
@ -78,9 +74,6 @@ class GlanceWrapper(object):
|
||||
|
||||
|
||||
class GlanceV1Wrapper(GlanceWrapper):
|
||||
def get_image(self, image):
|
||||
return image.manager.get(image.id)
|
||||
|
||||
def create_image(self, container_format, image_location,
|
||||
disk_format, **kwargs):
|
||||
kw = {
|
||||
@ -128,12 +121,9 @@ class GlanceV1Wrapper(GlanceWrapper):
|
||||
|
||||
|
||||
class GlanceV2Wrapper(GlanceWrapper):
|
||||
def get_image(self, image):
|
||||
return self.client.images.get(image.id)
|
||||
|
||||
def _update_image(self, image):
|
||||
try:
|
||||
return self.get_image(image)
|
||||
return self.client.images.get(image.id)
|
||||
except glance_exc.HTTPNotFound:
|
||||
raise exceptions.GetResourceNotFound(resource=image)
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
from boto import exception as boto_exception
|
||||
import ddt
|
||||
from glanceclient import exc as glance_exc
|
||||
import mock
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
|
||||
@ -397,77 +396,53 @@ class NeutronQuotaTestCase(test.TestCase):
|
||||
class GlanceImageTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
|
||||
def test__manager_admin(self, mock_glance_wrap):
|
||||
def test__wrapper_admin(self, mock_glance_wrap):
|
||||
admin = mock.Mock()
|
||||
glance = resources.GlanceImage(admin=admin)
|
||||
manager = glance._manager()
|
||||
wrapper = glance._wrapper()
|
||||
|
||||
mock_glance_wrap.assert_called_once_with(admin.glance, glance)
|
||||
self.assertEqual(manager, mock_glance_wrap.return_value)
|
||||
self.assertEqual(wrapper, mock_glance_wrap.return_value)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
|
||||
def test__manager_user(self, mock_glance_wrap):
|
||||
def test__wrapper_user(self, mock_glance_wrap):
|
||||
user = mock.Mock()
|
||||
glance = resources.GlanceImage(user=user)
|
||||
manager = glance._manager()
|
||||
wrapper = glance._wrapper()
|
||||
|
||||
mock_glance_wrap.assert_called_once_with(user.glance, glance)
|
||||
self.assertEqual(manager, mock_glance_wrap.return_value)
|
||||
self.assertEqual(wrapper, mock_glance_wrap.return_value)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
|
||||
def test__manager_admin_preferred(self, mock_glance_wrap):
|
||||
def test__wrapper_admin_preferred(self, mock_glance_wrap):
|
||||
admin = mock.Mock()
|
||||
user = mock.Mock()
|
||||
glance = resources.GlanceImage(admin=admin, user=user)
|
||||
manager = glance._manager()
|
||||
wrapper = glance._wrapper()
|
||||
|
||||
mock_glance_wrap.assert_called_once_with(admin.glance, glance)
|
||||
self.assertEqual(manager, mock_glance_wrap.return_value)
|
||||
self.assertEqual(wrapper, mock_glance_wrap.return_value)
|
||||
|
||||
@mock.patch("%s.GlanceImage._manager" % BASE)
|
||||
def test_list(self, mock_glance_image__manager):
|
||||
def test_list(self):
|
||||
glance = resources.GlanceImage()
|
||||
glance._wrapper = mock.Mock()
|
||||
glance.tenant_uuid = mock.Mock()
|
||||
|
||||
manager = mock_glance_image__manager.return_value
|
||||
self.assertEqual(glance.list(),
|
||||
manager.list_images.return_value)
|
||||
manager.list_images.assert_called_once_with(
|
||||
glance._wrapper.return_value.list_images.return_value)
|
||||
glance._wrapper.return_value.list_images.assert_called_once_with(
|
||||
owner=glance.tenant_uuid)
|
||||
|
||||
@ddt.data(
|
||||
{"resource": mock.Mock(), "deleted": False},
|
||||
{"resource": mock.Mock(status="deleted"), "deleted": True},
|
||||
{"resource": mock.Mock(status="active"), "deleted": False},
|
||||
{"resource": mock.Mock(status="delete_complete"), "deleted": True},
|
||||
{"exception": glance_exc.HTTPNotFound, "deleted": True},
|
||||
{"exception": glance_exc.HTTPUnauthorized, "deleted": False},
|
||||
{"exception": Exception, "deleted": False})
|
||||
@ddt.unpack
|
||||
@mock.patch("%s.GlanceImage._manager" % BASE)
|
||||
def test_is_deleted(self, mock_glance_image__manager, resource=None,
|
||||
exception=None, deleted=True):
|
||||
if resource is None:
|
||||
resource = mock.Mock()
|
||||
manager = mock_glance_image__manager.return_value
|
||||
if exception is not None:
|
||||
manager.get_image.side_effect = exception
|
||||
else:
|
||||
manager.get_image.return_value = resource
|
||||
|
||||
glance = resources.GlanceImage(resource=resource)
|
||||
self.assertEqual(deleted, glance.is_deleted())
|
||||
manager.get_image.assert_called_once_with(resource)
|
||||
|
||||
@mock.patch("%s.GlanceImage._manager" % BASE)
|
||||
def test_delete(self, mock_glance_image__manager):
|
||||
def test_delete(self):
|
||||
glance = resources.GlanceImage()
|
||||
glance._wrapper = mock.Mock()
|
||||
glance.raw_resource = mock.Mock()
|
||||
|
||||
manager = mock_glance_image__manager.return_value
|
||||
self.assertEqual(glance.delete(),
|
||||
manager.delete_image.return_value)
|
||||
manager.delete_image.assert_called_once_with(glance.raw_resource)
|
||||
self.assertEqual(
|
||||
glance.delete(),
|
||||
glance._wrapper.return_value.delete_image.return_value)
|
||||
glance._wrapper.return_value.delete_image.assert_called_once_with(
|
||||
glance.raw_resource)
|
||||
|
||||
|
||||
class CeilometerTestCase(test.TestCase):
|
||||
|
@ -185,15 +185,16 @@ class ImageGeneratorTestCase(test.ScenarioTestCase):
|
||||
images_ctx = images.ImageGenerator(self.context)
|
||||
images_ctx.cleanup()
|
||||
|
||||
wrapper = mock_wrap.return_value
|
||||
glance_client = mock_clients.return_value.glance.return_value
|
||||
glance_client.images.get.assert_has_calls([mock.call(i)
|
||||
for i in created_images])
|
||||
wrapper_calls = []
|
||||
wrapper_calls.extend([mock.call(mock_clients.return_value.glance,
|
||||
images_ctx)] * tenants_count)
|
||||
wrapper_calls.extend([mock.call().get_image(i)
|
||||
for i in created_images])
|
||||
wrapper_calls.extend(
|
||||
[mock.call().delete_image(wrapper.get_image.return_value)] *
|
||||
[mock.call().delete_image(glance_client.images.get.return_value)] *
|
||||
len(created_images))
|
||||
mock_wrap.assert_has_calls(wrapper_calls, any_order=True)
|
||||
mock_clients.assert_has_calls(
|
||||
[mock.call(mock.ANY, api_info=api_versions)] * tenants_count)
|
||||
[mock.call(mock.ANY, api_info=api_versions)] * tenants_count,
|
||||
any_order=True)
|
||||
|
@ -47,14 +47,6 @@ class GlanceV1WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
|
||||
self.owner = mock.Mock()
|
||||
self.wrapped_client = glance_wrapper.wrap(self.client, self.owner)
|
||||
|
||||
def test_get_image(self):
|
||||
image = mock.Mock()
|
||||
|
||||
return_image = self.wrapped_client.get_image(image)
|
||||
|
||||
image.manager.get.assert_called_once_with(image.id)
|
||||
self.assertEqual(return_image, image.manager.get.return_value)
|
||||
|
||||
@ddt.data(
|
||||
{"location": "image_location"},
|
||||
{"location": "image_location", "fakearg": "fake"},
|
||||
@ -120,15 +112,6 @@ class GlanceV2WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
|
||||
self.owner = mock.Mock()
|
||||
self.wrapped_client = glance_wrapper.wrap(self.client, self.owner)
|
||||
|
||||
def test_get_image(self):
|
||||
image = mock.Mock()
|
||||
|
||||
return_image = self.wrapped_client.get_image(image)
|
||||
|
||||
self.client.return_value.images.get.assert_called_once_with(image.id)
|
||||
self.assertEqual(return_image,
|
||||
self.client.return_value.images.get.return_value)
|
||||
|
||||
def test__update_image(self):
|
||||
image = mock.Mock()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user