Split exceptions into their own file
We were getting to the point where we were making some circular depends. Clear that up by splitting the exceptions into their own file. We're importing * to keep the external interface in the ansible modules. Change-Id: I1d804377c3cd4eebcc94624902f9e5ec6ebf9321
This commit is contained in:
parent
a02cbc5d30
commit
3b64ee66e4
@ -41,6 +41,7 @@ import troveclient.client as trove_client
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore', 'Certificate has no `subjectAltName`')
|
||||
|
||||
from shade.exc import * # noqa
|
||||
from shade import meta
|
||||
from shade import task_manager
|
||||
from shade import _tasks
|
||||
@ -58,25 +59,6 @@ OBJECT_CONTAINER_ACLS = {
|
||||
}
|
||||
|
||||
|
||||
class OpenStackCloudException(Exception):
|
||||
def __init__(self, message, extra_data=None):
|
||||
args = [message]
|
||||
if extra_data:
|
||||
args.append(extra_data)
|
||||
super(OpenStackCloudException, self).__init__(*args)
|
||||
self.extra_data = extra_data
|
||||
|
||||
def __str__(self):
|
||||
if self.extra_data is not None:
|
||||
return "%s (Extra: %s)" % (
|
||||
Exception.__str__(self), self.extra_data)
|
||||
return Exception.__str__(self)
|
||||
|
||||
|
||||
class OpenStackCloudTimeout(OpenStackCloudException):
|
||||
pass
|
||||
|
||||
|
||||
def openstack_clouds(config=None, debug=False):
|
||||
if not config:
|
||||
config = os_client_config.OpenStackConfig()
|
||||
|
32
shade/exc.py
Normal file
32
shade/exc.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
class OpenStackCloudException(Exception):
|
||||
def __init__(self, message, extra_data=None):
|
||||
args = [message]
|
||||
if extra_data:
|
||||
args.append(extra_data)
|
||||
super(OpenStackCloudException, self).__init__(*args)
|
||||
self.extra_data = extra_data
|
||||
|
||||
def __str__(self):
|
||||
if self.extra_data is not None:
|
||||
return "%s (Extra: %s)" % (
|
||||
Exception.__str__(self), self.extra_data)
|
||||
return Exception.__str__(self)
|
||||
|
||||
|
||||
class OpenStackCloudTimeout(OpenStackCloudException):
|
||||
pass
|
@ -20,8 +20,8 @@ Tests for the `create_server` command.
|
||||
"""
|
||||
|
||||
from mock import patch, Mock
|
||||
from shade import (
|
||||
OpenStackCloud, OpenStackCloudException, OpenStackCloudTimeout)
|
||||
from shade import OpenStackCloud
|
||||
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
||||
from shade.tests import base
|
||||
|
||||
|
||||
|
@ -20,8 +20,8 @@ Tests for the `rebuild_server` command.
|
||||
"""
|
||||
|
||||
from mock import patch, Mock
|
||||
from shade import (
|
||||
OpenStackCloud, OpenStackCloudException, OpenStackCloudTimeout)
|
||||
from shade import OpenStackCloud
|
||||
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
import mock
|
||||
|
||||
import shade
|
||||
from shade import exc
|
||||
from shade import meta
|
||||
from shade.tests.unit import base
|
||||
|
||||
@ -89,7 +90,7 @@ class TestShade(base.TestCase):
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_delete_router_not_found(self, mock_client, mock_search):
|
||||
mock_search.return_value = []
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.delete_router,
|
||||
'goofy')
|
||||
self.assertFalse(mock_client.delete_router.called)
|
||||
@ -100,7 +101,7 @@ class TestShade(base.TestCase):
|
||||
router2 = dict(id='456', name='mickey')
|
||||
mock_client.list_routers.return_value = dict(routers=[router1,
|
||||
router2])
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.delete_router,
|
||||
'mickey')
|
||||
self.assertFalse(mock_client.delete_router.called)
|
||||
@ -133,7 +134,7 @@ class TestShade(base.TestCase):
|
||||
def test_create_subnet_bad_network(self, mock_client, mock_list):
|
||||
net1 = dict(id='123', name='donald')
|
||||
mock_list.return_value = [net1]
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.create_subnet,
|
||||
'duck', '192.168.199.0/24')
|
||||
self.assertFalse(mock_client.create_subnet.called)
|
||||
@ -144,7 +145,7 @@ class TestShade(base.TestCase):
|
||||
net1 = dict(id='123', name='donald')
|
||||
net2 = dict(id='456', name='donald')
|
||||
mock_search.return_value = [net1, net2]
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.create_subnet,
|
||||
'donald', '192.168.199.0/24')
|
||||
self.assertFalse(mock_client.create_subnet.called)
|
||||
@ -161,7 +162,7 @@ class TestShade(base.TestCase):
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_delete_subnet_not_found(self, mock_client, mock_search):
|
||||
mock_search.return_value = []
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.delete_subnet,
|
||||
'goofy')
|
||||
self.assertFalse(mock_client.delete_subnet.called)
|
||||
@ -172,7 +173,7 @@ class TestShade(base.TestCase):
|
||||
subnet2 = dict(id='456', name='mickey')
|
||||
mock_client.list_subnets.return_value = dict(subnets=[subnet1,
|
||||
subnet2])
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.delete_subnet,
|
||||
'mickey')
|
||||
self.assertFalse(mock_client.delete_subnet.called)
|
||||
@ -524,8 +525,8 @@ class TestShadeOperator(base.TestCase):
|
||||
def test_register_machine_port_create_failed(self, mock_client):
|
||||
nics = [{'mac': '00:00:00:00:00:00'}]
|
||||
mock_client.port.create.side_effect = (
|
||||
shade.OpenStackCloudException("Error"))
|
||||
self.assertRaises(shade.OpenStackCloudException,
|
||||
exc.OpenStackCloudException("Error"))
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.cloud.register_machine,
|
||||
nics)
|
||||
self.assertTrue(mock_client.node.create.called)
|
||||
|
Loading…
x
Reference in New Issue
Block a user