Don't catch all exceptions in image constraint
Just catch ImageNotFound, as otherwise we can hide other problems. Change-Id: Ib0e813043b1e4fe7b5b4a14ae8130ac17c4355a5 Closes-Bug: #1297349
This commit is contained in:
parent
ba5647c400
commit
bd2d830074
|
@ -11,6 +11,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import clients
|
||||
from heat.engine.resources import nova_utils
|
||||
|
||||
|
@ -21,7 +22,7 @@ class ImageConstraint(object):
|
|||
try:
|
||||
nova_client = clients.Clients(context).nova()
|
||||
nova_utils.get_image_id(nova_client, value)
|
||||
except Exception:
|
||||
except exception.ImageNotFound:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
import mock
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import clients
|
||||
from heat.engine.resources import image
|
||||
from heat.engine.resources import nova_utils
|
||||
|
@ -32,5 +33,6 @@ class ImageConstraintTest(HeatTestCase):
|
|||
def test_validation_error(self, mock_get_image):
|
||||
with mock.patch.object(clients, "OpenStackClients"):
|
||||
constraint = image.ImageConstraint()
|
||||
mock_get_image.side_effect = ValueError("Not found")
|
||||
mock_get_image.side_effect = exception.ImageNotFound(
|
||||
image_name='bar')
|
||||
self.assertFalse(constraint.validate("bar", None))
|
||||
|
|
|
@ -273,8 +273,8 @@ class ServersTest(HeatTestCase):
|
|||
|
||||
error = self.assertRaises(ValueError, server.handle_create)
|
||||
self.assertEqual(
|
||||
'server_create_image_err: image "CentOS 5.2" does not '
|
||||
'validate glance.image',
|
||||
'server_create_image_err: image Multiple physical resources were '
|
||||
'found with name (CentOS 5.2).',
|
||||
str(error))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
|
Loading…
Reference in New Issue