Shift config exceptions to openstack.exceptions
The main config exception can move. The other one isn't used. Change-Id: I6904340ce2e7d5f3224be87ae7e26f488be1802f
This commit is contained in:
@@ -24,7 +24,7 @@ from six.moves import urllib
|
||||
from openstack import version as openstack_version
|
||||
from openstack import _log
|
||||
from openstack.config import defaults as config_defaults
|
||||
from openstack.config import exceptions
|
||||
from openstack import exceptions
|
||||
|
||||
|
||||
def _make_key(key, service_type):
|
||||
@@ -208,7 +208,7 @@ class CloudRegion(object):
|
||||
"""Return a keystoneauth session based on the auth credentials."""
|
||||
if self._keystone_session is None:
|
||||
if not self._auth:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"Problem with auth parameters")
|
||||
(verify, cert) = self.get_requests_verify_args()
|
||||
# Turn off urllib3 warnings about insecure certs if we have
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Copyright (c) 2014 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 OpenStackConfigException(Exception):
|
||||
"""Something went wrong with parsing your OpenStack Config."""
|
||||
|
||||
|
||||
class OpenStackConfigVersionException(OpenStackConfigException):
|
||||
"""A version was requested that is different than what was found."""
|
||||
|
||||
def __init__(self, version):
|
||||
super(OpenStackConfigVersionException, self).__init__()
|
||||
self.version = version
|
||||
|
||||
@@ -31,8 +31,8 @@ import yaml
|
||||
from openstack import _log
|
||||
from openstack.config import cloud_region
|
||||
from openstack.config import defaults
|
||||
from openstack.config import exceptions
|
||||
from openstack.config import vendors
|
||||
from openstack import exceptions
|
||||
|
||||
APPDIRS = appdirs.AppDirs('openstack', 'OpenStack', multipath='/etc')
|
||||
CONFIG_HOME = APPDIRS.user_config_dir
|
||||
@@ -168,7 +168,7 @@ def _fix_argv(argv):
|
||||
if len(old) > 1:
|
||||
overlap.extend(old)
|
||||
if overlap:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"The following options were given: '{options}' which contain"
|
||||
" duplicates except that one has _ and one has -. There is"
|
||||
" no sane way for us to know what you're doing. Remove the"
|
||||
@@ -251,7 +251,7 @@ class OpenStackConfig(object):
|
||||
# Next, process environment variables and add them to the mix
|
||||
self.envvar_key = self._get_envvar('OS_CLOUD_NAME', 'envvars')
|
||||
if self.envvar_key in self.cloud_config['clouds']:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
'"{0}" defines a cloud named "{1}", but'
|
||||
' OS_CLOUD_NAME is also set to "{1}". Please rename'
|
||||
' either your environment based cloud, or one of your'
|
||||
@@ -459,7 +459,7 @@ class OpenStackConfig(object):
|
||||
if region['name'] == region_name:
|
||||
return region
|
||||
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
'Region {region_name} is not a valid region name for cloud'
|
||||
' {cloud}. Valid choices are {region_list}. Please note that'
|
||||
' region names are case sensitive.'.format(
|
||||
@@ -475,7 +475,7 @@ class OpenStackConfig(object):
|
||||
|
||||
# Only validate cloud name if one was given
|
||||
if name and name not in self.cloud_config['clouds']:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"Cloud {name} was not found.".format(
|
||||
name=name))
|
||||
|
||||
@@ -517,7 +517,7 @@ class OpenStackConfig(object):
|
||||
"{profile_name} is deprecated: {message}".format(
|
||||
profile_name=profile_name, message=message))
|
||||
elif status == 'shutdown':
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"{profile_name} references a cloud that no longer"
|
||||
" exists: {message}".format(
|
||||
profile_name=profile_name, message=message))
|
||||
@@ -537,7 +537,7 @@ class OpenStackConfig(object):
|
||||
value = None
|
||||
for net in networks:
|
||||
if value and net[key]:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"Duplicate network entries for {key}: {net1} and {net2}."
|
||||
" Only one network can be flagged with {key}".format(
|
||||
key=key,
|
||||
@@ -554,7 +554,7 @@ class OpenStackConfig(object):
|
||||
for net in cloud.get('networks', []):
|
||||
name = net.get('name')
|
||||
if not name:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
'Entry in network list is missing required field "name".')
|
||||
network = dict(
|
||||
name=name,
|
||||
@@ -576,7 +576,7 @@ class OpenStackConfig(object):
|
||||
for key in ('external_network', 'internal_network'):
|
||||
external = key.startswith('external')
|
||||
if key in cloud and 'networks' in cloud:
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"Both {key} and networks were specified in the config."
|
||||
" Please remove {key} from the config and use the network"
|
||||
" list to configure network behavior.".format(key=key))
|
||||
@@ -691,8 +691,7 @@ class OpenStackConfig(object):
|
||||
as the default value for service_type
|
||||
(optional)
|
||||
|
||||
:raises exceptions.OpenStackConfigException if an invalid auth-type
|
||||
is requested
|
||||
:raises exceptions.ConfigException if an invalid auth-type is requested
|
||||
"""
|
||||
|
||||
if service_keys is None:
|
||||
@@ -750,7 +749,7 @@ class OpenStackConfig(object):
|
||||
# from it doesn't actually make sense to os-client-config users
|
||||
options, _args = parser.parse_known_args(argv)
|
||||
plugin_names = loading.get_available_plugin_names()
|
||||
raise exceptions.OpenStackConfigException(
|
||||
raise exceptions.ConfigException(
|
||||
"An invalid auth-type was specified: {auth_type}."
|
||||
" Valid choices are: {plugin_names}.".format(
|
||||
auth_type=options.os_auth_type,
|
||||
|
||||
@@ -209,3 +209,7 @@ def raise_from_response(response, error_message=None):
|
||||
class ArgumentDeprecationWarning(Warning):
|
||||
"""A deprecated argument has been provided."""
|
||||
pass
|
||||
|
||||
|
||||
class ConfigException(SDKException):
|
||||
"""Something went wrong with parsing your OpenStack Config."""
|
||||
|
||||
@@ -19,7 +19,7 @@ import testtools
|
||||
import openstack
|
||||
import openstack.cloud
|
||||
from openstack.cloud import meta
|
||||
from openstack.config import exceptions as occ_exc
|
||||
from openstack import exceptions
|
||||
from openstack.tests import fakes
|
||||
from openstack.tests.unit import base
|
||||
|
||||
@@ -551,6 +551,6 @@ class TestBogusAuth(base.TestCase):
|
||||
cloud_config_fixture='clouds_cache.yaml')
|
||||
|
||||
def test_get_auth_bogus(self):
|
||||
with testtools.ExpectedException(occ_exc.OpenStackConfigException):
|
||||
with testtools.ExpectedException(exceptions.ConfigException):
|
||||
openstack.connect(
|
||||
cloud='_bogus_test_', config=self.config)
|
||||
|
||||
@@ -19,7 +19,7 @@ import mock
|
||||
from openstack import version as openstack_version
|
||||
from openstack.config import cloud_region
|
||||
from openstack.config import defaults
|
||||
from openstack.config import exceptions
|
||||
from openstack import exceptions
|
||||
from openstack.tests.unit.config import base
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ class TestCloudRegion(base.TestCase):
|
||||
config_dict.update(fake_services_dict)
|
||||
cc = cloud_region.CloudRegion("test1", "region-al", config_dict)
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
cc.get_session)
|
||||
|
||||
@mock.patch.object(ksa_session, 'Session')
|
||||
|
||||
@@ -24,8 +24,8 @@ import yaml
|
||||
from openstack import config
|
||||
from openstack.config import cloud_region
|
||||
from openstack.config import defaults
|
||||
from openstack.config import exceptions
|
||||
from openstack.config import loader
|
||||
from openstack import exceptions
|
||||
from openstack.tests.unit.config import base
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ class TestConfig(base.TestCase):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c.get_one, 'envvars')
|
||||
exceptions.ConfigException, c.get_one, 'envvars')
|
||||
|
||||
def test_fallthrough(self):
|
||||
c = config.OpenStackConfig(config_files=[self.no_yaml],
|
||||
@@ -388,7 +388,7 @@ class TestConfig(base.TestCase):
|
||||
vendor_files=[self.vendor_yaml],
|
||||
secure_files=[self.no_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c._get_region,
|
||||
exceptions.ConfigException, c._get_region,
|
||||
cloud='_test_cloud_regions', region_name='invalid-region')
|
||||
|
||||
def test_get_region_no_cloud(self):
|
||||
@@ -481,7 +481,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
vendor_files=[self.vendor_yaml])
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c.get_one,
|
||||
exceptions.ConfigException, c.get_one,
|
||||
cloud='_test-cloud_', argparse=self.options)
|
||||
|
||||
def test_get_one_argparse(self):
|
||||
@@ -640,7 +640,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
vendor_files=[self.vendor_yaml])
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c.get_one,
|
||||
cloud='_test_cloud_regions', region_name='bad')
|
||||
|
||||
@@ -648,7 +648,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c.get_one,
|
||||
cloud='_test-cloud_', region_name='bad_region')
|
||||
|
||||
@@ -686,7 +686,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
c = config.OpenStackConfig(load_yaml_config=False)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c.get_one,
|
||||
cloud='_test_cloud_regions', region_name='region2', argparse=None)
|
||||
|
||||
@@ -828,7 +828,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
'--os-username', 'user1', '--os-password', 'pass1',
|
||||
'--os-auth-url', 'auth-url', '--os-project-name', 'project']
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c.register_argparse_arguments,
|
||||
parser=parser, argv=argv)
|
||||
|
||||
@@ -837,7 +837,7 @@ class TestConfigArgparse(base.TestCase):
|
||||
vendor_files=[self.vendor_yaml])
|
||||
parser = argparse.ArgumentParser()
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c.register_argparse_arguments,
|
||||
parser, ['--os-auth-type', 'foo'])
|
||||
|
||||
@@ -1068,7 +1068,7 @@ class TestBackwardsCompatibility(base.TestCase):
|
||||
]
|
||||
}
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c._fix_backwards_networks, cloud)
|
||||
|
||||
def test_backwards_network(self):
|
||||
@@ -1121,5 +1121,5 @@ class TestBackwardsCompatibility(base.TestCase):
|
||||
]
|
||||
}
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
exceptions.ConfigException,
|
||||
c._fix_backwards_networks, cloud)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
from openstack import config
|
||||
from openstack.config import cloud_region
|
||||
from openstack.config import exceptions
|
||||
from openstack import exceptions
|
||||
from openstack.tests.unit.config import base
|
||||
|
||||
import fixtures
|
||||
@@ -45,7 +45,7 @@ class TestEnviron(base.TestCase):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c.get_one, 'openstack')
|
||||
exceptions.ConfigException, c.get_one, 'openstack')
|
||||
|
||||
def test_envvar_name_override(self):
|
||||
self.useFixture(
|
||||
@@ -127,7 +127,7 @@ class TestEnvvars(base.TestCase):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c.get_one, 'envvars')
|
||||
exceptions.ConfigException, c.get_one, 'envvars')
|
||||
|
||||
def test_test_envvars(self):
|
||||
self.useFixture(
|
||||
@@ -137,7 +137,7 @@ class TestEnvvars(base.TestCase):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException, c.get_one, 'envvars')
|
||||
exceptions.ConfigException, c.get_one, 'envvars')
|
||||
|
||||
def test_incomplete_envvars(self):
|
||||
self.useFixture(
|
||||
|
||||
Reference in New Issue
Block a user