Raise error when image status is not active
when the image is not active status, it should be raise error, because there is no need to take an error status image to create share server. Change-Id: Ib31b9a627a9bbd413e46bfc09775e0c6d30ac084 Closes-Bug: #1740010
This commit is contained in:
parent
ca03752587
commit
5bfe68664a
|
@ -483,12 +483,14 @@ class ServiceInstanceManager(object):
|
|||
"""Returns ID of service image for service vm creating."""
|
||||
service_image_name = self.get_config_option("service_image_name")
|
||||
images = [image.id for image in self.compute_api.image_list(context)
|
||||
if image.name == service_image_name]
|
||||
if image.name == service_image_name
|
||||
and image.status == 'active']
|
||||
if len(images) == 1:
|
||||
return images[0]
|
||||
elif not images:
|
||||
raise exception.ServiceInstanceException(
|
||||
_("Image with name '%s' not found.") % service_image_name)
|
||||
_("Image with name '%s' was not found or is not in "
|
||||
"'active' state.") % service_image_name)
|
||||
else:
|
||||
raise exception.ServiceInstanceException(
|
||||
_("Found more than one image by name '%s'.") %
|
||||
|
|
|
@ -670,13 +670,20 @@ class ServiceInstanceManagerTestCase(test.TestCase):
|
|||
|
||||
def test_get_service_image(self):
|
||||
fake_image1 = fake_compute.FakeImage(
|
||||
name=self._manager.get_config_option('service_image_name'))
|
||||
fake_image2 = fake_compute.FakeImage(name='another-image')
|
||||
name=self._manager.get_config_option('service_image_name'),
|
||||
status='active')
|
||||
fake_image2 = fake_compute.FakeImage(
|
||||
name='service_image_name',
|
||||
status='error')
|
||||
fake_image3 = fake_compute.FakeImage(
|
||||
name='another-image',
|
||||
status='active')
|
||||
self.mock_object(self._manager.compute_api, 'image_list',
|
||||
mock.Mock(return_value=[fake_image1, fake_image2]))
|
||||
mock.Mock(return_value=[fake_image1,
|
||||
fake_image2,
|
||||
fake_image3]))
|
||||
|
||||
result = self._manager._get_service_image(self._manager.admin_context)
|
||||
|
||||
self.assertEqual(fake_image1.id, result)
|
||||
|
||||
def test_get_service_image_not_found(self):
|
||||
|
@ -686,9 +693,19 @@ class ServiceInstanceManagerTestCase(test.TestCase):
|
|||
exception.ServiceInstanceException,
|
||||
self._manager._get_service_image, self._manager.admin_context)
|
||||
|
||||
fake_error_image = fake_compute.FakeImage(
|
||||
name='service_image_name',
|
||||
status='error')
|
||||
self.mock_object(self._manager.compute_api, 'image_list',
|
||||
mock.Mock(return_value=[fake_error_image]))
|
||||
self.assertRaises(
|
||||
exception.ServiceInstanceException,
|
||||
self._manager._get_service_image, self._manager.admin_context)
|
||||
|
||||
def test_get_service_image_ambiguous(self):
|
||||
fake_image = fake_compute.FakeImage(
|
||||
name=fake_get_config_option('service_image_name'))
|
||||
name=fake_get_config_option('service_image_name'),
|
||||
status='active')
|
||||
fake_images = [fake_image, fake_image]
|
||||
self.mock_object(self._manager.compute_api, 'image_list',
|
||||
mock.Mock(return_value=fake_images))
|
||||
|
|
Loading…
Reference in New Issue