|
16 | 16 | import importlib |
17 | 17 | from unittest import mock |
18 | 18 |
|
| 19 | +from glanceclient import exc as glance_exception |
| 20 | + |
19 | 21 | from magnum.api import validation as v |
20 | 22 | from magnum.common import exception |
21 | 23 | import magnum.conf |
@@ -384,3 +386,61 @@ def test_validate_cluster_properties(self): |
384 | 386 | else: |
385 | 387 | self.assertRaises(exception.InvalidParameterValue, |
386 | 388 | v.validate_cluster_properties, set([field])) |
| 389 | + |
| 390 | + @mock.patch('pecan.request') |
| 391 | + @mock.patch('magnum.common.clients.OpenStackClients') |
| 392 | + @mock.patch('magnum.api.utils.get_openstack_resource') |
| 393 | + def test_enforce_driver_supported_image_not_found( |
| 394 | + self, mock_get_resource, mock_os_clients, mock_pecan_request): |
| 395 | + |
| 396 | + @v.enforce_driver_supported() |
| 397 | + def test(self, cluster_template): |
| 398 | + pass |
| 399 | + |
| 400 | + mock_get_resource.side_effect = exception.ResourceNotFound( |
| 401 | + name='image', id='test-image-id') |
| 402 | + cluster_template = mock.MagicMock() |
| 403 | + cluster_template.cluster_distro = None |
| 404 | + cluster_template.driver = None |
| 405 | + cluster_template.image_id = 'test-image-id' |
| 406 | + |
| 407 | + self.assertRaises(exception.ImageNotFound, |
| 408 | + test, self, cluster_template) |
| 409 | + |
| 410 | + @mock.patch('pecan.request') |
| 411 | + @mock.patch('magnum.common.clients.OpenStackClients') |
| 412 | + @mock.patch('magnum.api.utils.get_openstack_resource') |
| 413 | + def test_enforce_driver_supported_image_not_found_glance( |
| 414 | + self, mock_get_resource, mock_os_clients, mock_pecan_request): |
| 415 | + |
| 416 | + @v.enforce_driver_supported() |
| 417 | + def test(self, cluster_template): |
| 418 | + pass |
| 419 | + |
| 420 | + mock_get_resource.side_effect = glance_exception.NotFound() |
| 421 | + cluster_template = mock.MagicMock() |
| 422 | + cluster_template.cluster_distro = None |
| 423 | + cluster_template.driver = None |
| 424 | + cluster_template.image_id = 'test-image-id' |
| 425 | + |
| 426 | + self.assertRaises(exception.ImageNotFound, |
| 427 | + test, self, cluster_template) |
| 428 | + |
| 429 | + @mock.patch('pecan.request') |
| 430 | + @mock.patch('magnum.common.clients.OpenStackClients') |
| 431 | + @mock.patch('magnum.api.utils.get_openstack_resource') |
| 432 | + def test_enforce_driver_supported_image_forbidden( |
| 433 | + self, mock_get_resource, mock_os_clients, mock_pecan_request): |
| 434 | + |
| 435 | + @v.enforce_driver_supported() |
| 436 | + def test(self, cluster_template): |
| 437 | + pass |
| 438 | + |
| 439 | + mock_get_resource.side_effect = glance_exception.HTTPForbidden() |
| 440 | + cluster_template = mock.MagicMock() |
| 441 | + cluster_template.cluster_distro = None |
| 442 | + cluster_template.driver = None |
| 443 | + cluster_template.image_id = 'test-image-id' |
| 444 | + |
| 445 | + self.assertRaises(exception.ImageNotAuthorized, |
| 446 | + test, self, cluster_template) |
0 commit comments