From dcbcfbf1241b8a0b228d70ca4393a93edba02eab Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 12 May 2018 10:31:30 -0500 Subject: [PATCH] Fix recent pep8 issues The latest version of pycodestyle got stricter with undefined objects pulled in via * imports. It's a nice check and actually found a bug, so instead of disabling it, fix the places where we're using a * import. W503 on the other hand is terrible. Change-Id: Id73599ca494545b0f6d2345236190fc13cf2a326 --- shade/__init__.py | 8 +- shade/_heat/event_utils.py | 12 +- shade/openstackcloud.py | 564 +++++++++++++++++++------------------ tox.ini | 4 +- 4 files changed, 302 insertions(+), 286 deletions(-) diff --git a/shade/__init__.py b/shade/__init__.py index 8e300ddd3..4b4e8082c 100644 --- a/shade/__init__.py +++ b/shade/__init__.py @@ -20,7 +20,9 @@ from openstack.config import loader import pbr.version import requestsexceptions +# The star import is for backwards compat reasons from shade.exc import * # noqa +from shade import exc from shade.openstackcloud import OpenStackCloud from shade.operatorcloud import OperatorCloud from shade import _log @@ -95,7 +97,7 @@ def openstack_clouds( if f.name == cloud ] except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e))) @@ -107,7 +109,7 @@ def openstack_cloud( try: cloud_config = config.get_one_cloud(**kwargs) except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e))) return OpenStackCloud( cloud_config=cloud_config, strict=strict, @@ -122,7 +124,7 @@ def operator_cloud( try: cloud_config = config.get_one_cloud(**kwargs) except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e))) return OperatorCloud( cloud_config=cloud_config, strict=strict, diff --git a/shade/_heat/event_utils.py b/shade/_heat/event_utils.py index 839f2aad4..d8557536a 100644 --- a/shade/_heat/event_utils.py +++ b/shade/_heat/event_utils.py @@ -44,11 +44,17 @@ def poll_for_events( cloud, stack_name, action=None, poll_period=5, marker=None): """Continuously poll events and logs for performed action on stack.""" - if action: + def stop_check_action(a): stop_status = ('%s_FAILED' % action, '%s_COMPLETE' % action) - stop_check = lambda a: a in stop_status + return a in stop_status + + def stop_check_no_action(a): + return a.endswith('_COMPLETE') or a.endswith('_FAILED') + + if action: + stop_check = stop_check_action else: - stop_check = lambda a: a.endswith('_COMPLETE') or a.endswith('_FAILED') + stop_check = stop_check_no_action no_event_polls = 0 msg_template = "\n Stack %(name)s %(status)s \n" diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 71caa75c5..2255dc9da 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -37,8 +37,8 @@ import os from openstack.config import loader import shade -from shade.exc import * # noqa from shade import _adapter +from shade import exc from shade._heat import event_utils from shade._heat import template_utils from shade import _log @@ -452,7 +452,7 @@ class OpenStackCloud( {'service': service_key}, exc_info=True) raise if client is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Failed to instantiate {service} client." " This could mean that your credentials are wrong.".format( service=service_key)) @@ -478,14 +478,14 @@ class OpenStackCloud( # does know about it found, that's a warning in shade. if config_version: if min_major and config_major < min_major: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Version {config_version} requested for {service_type}" " but shade understands a minimum of {min_version}".format( config_version=config_version, service_type=service_type, min_version=min_version)) elif max_major and config_major > max_major: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Version {config_version} requested for {service_type}" " but shade understands a maximum of {max_version}".format( config_version=config_version, @@ -693,7 +693,7 @@ class OpenStackCloud( self._keystone_session.additional_user_agent.append( ('shade', shade.__version__)) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error authenticating to keystone: %s " % str(e)) return self._keystone_session @@ -812,7 +812,7 @@ class OpenStackCloud( # mention api versions if self._is_client_version('identity', 3): if not domain_id: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "User or project creation requires an explicit" " domain_id argument.") else: @@ -925,7 +925,7 @@ class OpenStackCloud( self._get_and_munchify(key, data)) except Exception as e: self.log.debug("Failed to list projects", exc_info=True) - raise OpenStackCloudException(str(e)) + raise exc.OpenStackCloudException(str(e)) return _utils._filter_list(projects, name_or_id, filters) def search_projects(self, name_or_id=None, filters=None, domain_id=None): @@ -962,7 +962,7 @@ class OpenStackCloud( project=name_or_id)): proj = self.get_project(name_or_id, domain_id=domain_id) if not proj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Project %s not found." % name_or_id) if enabled is not None: kwargs.update({'enabled': enabled}) @@ -1192,12 +1192,12 @@ class OpenStackCloud( def _get_user_and_group(self, user_name_or_id, group_name_or_id): user = self.get_user(user_name_or_id) if not user: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'User {user} not found'.format(user=user_name_or_id)) group = self.get_group(group_name_or_id) if not group: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Group {user} not found'.format(user=group_name_or_id)) return (user, group) @@ -1236,7 +1236,7 @@ class OpenStackCloud( self._identity_client.head( '/groups/{g}/users/{u}'.format(g=group['id'], u=user['id'])) return True - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: # NOTE(samueldmq): knowing this URI exists, let's interpret this as # user not found in group rather than URI not found. return False @@ -1266,7 +1266,7 @@ class OpenStackCloud( template_file=template_file, template_url=template_url, template_object=template_object, files=files) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in processing template files: %s" % str(e)) def create_stack( @@ -1424,11 +1424,11 @@ class OpenStackCloud( stack_name=name_or_id, action='DELETE', marker=marker) - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: pass stack = self.get_stack(name_or_id, resolve_outputs=False) if stack and stack['stack_status'] == 'DELETE_FAILED': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Failed to delete stack {id}: {reason}".format( id=name_or_id, reason=stack['stack_status_reason'])) @@ -1462,7 +1462,7 @@ class OpenStackCloud( if (flavor['ram'] >= ram and (not include or include in flavor['name'])): return flavor - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Could not find a flavor with {ram} and '{include}'".format( ram=ram, include=include)) @@ -1473,10 +1473,10 @@ class OpenStackCloud( self.log.debug( "Endpoint not found in %s cloud: %s", self.name, str(e)) endpoint = None - except OpenStackCloudException: + except exc.OpenStackCloudException: raise except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error getting {service} endpoint on {cloud}:{region}:" " {error}".format( service=service_key, @@ -1497,7 +1497,7 @@ class OpenStackCloud( return False try: endpoint = self.get_session_endpoint(service_key) - except OpenStackCloudException: + except exc.OpenStackCloudException: return False if endpoint: return True @@ -1804,7 +1804,7 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') # Translate None from search interface to empty {} for kwargs below @@ -1825,11 +1825,11 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') if not self._has_neutron_extension('qos-rule-type-details'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'qos-rule-type-details extension is not available ' 'on target cloud') @@ -1847,7 +1847,7 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') # Translate None from search interface to empty {} for kwargs below if not filters: @@ -1874,7 +1874,7 @@ class OpenStackCloud( if endpoint: try: _list(self._volume_client.get(endpoint)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: # Catch and re-raise here because we are making recursive # calls and we just have context for the log here self.log.debug( @@ -1901,7 +1901,7 @@ class OpenStackCloud( try: _list(data) break - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: pass else: self.log.debug( @@ -1939,7 +1939,7 @@ class OpenStackCloud( """ try: data = self._compute_client.get('/os-availability-zone') - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: self.log.debug( "Availability zone list could not be fetched", exc_info=True) @@ -1980,7 +1980,7 @@ class OpenStackCloud( error_message="Error fetching flavor extra specs") flavor.extra_specs = self._get_and_munchify( 'extra_specs', data) - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: flavor.extra_specs = {} self.log.debug( 'Fetching extra specs for flavor failed:' @@ -2020,7 +2020,7 @@ class OpenStackCloud( def _get_server_security_groups(self, server, security_groups): if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) @@ -2100,7 +2100,7 @@ class OpenStackCloud( '/servers/%s/action' % server['id'], json={'removeSecurityGroup': {'name': sg.name}}) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: # NOTE(jamielennox): Is this ok? If we remove something that # isn't present should we just conclude job done or is that an # error? Nova returns ok if you try to add a group twice. @@ -2120,7 +2120,7 @@ class OpenStackCloud( """ # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) @@ -2239,7 +2239,7 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") project_id = proj.id params['tenant_id'] = project_id error_msg = "{msg} for the project: {project} ".format( @@ -2316,7 +2316,7 @@ class OpenStackCloud( """ if not self._has_nova_extension('os-floating-ip-pools'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'Floating IP pools extension is not available on target cloud') data = self._compute_client.get( @@ -2330,7 +2330,7 @@ class OpenStackCloud( try: return self._normalize_floating_ips( self._neutron_list_floating_ips(filters)) - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: # Nova-network don't support server-side floating ips # filtering, so it's safer to return and empty list than # to fallback to Nova which may return more results that @@ -2411,7 +2411,7 @@ class OpenStackCloud( def _nova_list_floating_ips(self): try: data = self._compute_client.get('/os-floating-ips') - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: return [] return self._get_and_munchify('floating_ips', data) @@ -2456,7 +2456,7 @@ class OpenStackCloud( # though, that's fine, clearly the neutron introspection is # not going to work. all_networks = self.list_networks() - except OpenStackCloudException: + except exc.OpenStackCloudException: self._network_list_stamp = True return @@ -2509,7 +2509,7 @@ class OpenStackCloud( if self._nat_destination in ( network['name'], network['id']): if nat_destination: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Multiple networks were found matching' ' {nat_net} which is the network configured' ' to be the NAT destination. Please check your' @@ -2526,7 +2526,7 @@ class OpenStackCloud( if all_subnets is None: try: all_subnets = self.list_subnets() - except OpenStackCloudException: + except exc.OpenStackCloudException: # Thanks Rackspace broken neutron all_subnets = [] @@ -2542,7 +2542,7 @@ class OpenStackCloud( if self._default_network in ( network['name'], network['id']): if default_network: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Multiple networks were found matching' ' {default_net} which is the network' ' configured to be the default interface' @@ -2556,41 +2556,41 @@ class OpenStackCloud( # Validate config vs. reality for net_name in self._external_ipv4_names: if net_name not in [net['name'] for net in external_ipv4_networks]: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Networks: {network} was provided for external IPv4" " access and those networks could not be found".format( network=net_name)) for net_name in self._internal_ipv4_names: if net_name not in [net['name'] for net in internal_ipv4_networks]: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Networks: {network} was provided for internal IPv4" " access and those networks could not be found".format( network=net_name)) for net_name in self._external_ipv6_names: if net_name not in [net['name'] for net in external_ipv6_networks]: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Networks: {network} was provided for external IPv6" " access and those networks could not be found".format( network=net_name)) for net_name in self._internal_ipv6_names: if net_name not in [net['name'] for net in internal_ipv6_networks]: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Networks: {network} was provided for internal IPv6" " access and those networks could not be found".format( network=net_name)) if self._nat_destination and not nat_destination: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Network {network} was configured to be the' ' destination for inbound NAT but it could not be' ' found'.format( network=self._nat_destination)) if self._default_network and not default_network: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Network {network} was configured to be the' ' default network interface but it could not be' ' found'.format( @@ -3033,7 +3033,7 @@ class OpenStackCloud( error_message="Error fetching flavor extra specs") flavor.extra_specs = self._get_and_munchify( 'extra_specs', data) - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: flavor.extra_specs = {} self.log.debug( 'Fetching extra specs for flavor failed:' @@ -3074,7 +3074,7 @@ class OpenStackCloud( :returns: A security group ``munch.Munch``. """ if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) error_message = ("Error getting security group with" @@ -3108,12 +3108,12 @@ class OpenStackCloud( server = self.get_server(server, bare=True) if not server: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Console log requested for invalid server") try: return self._get_server_console_output(server['id'], length) - except OpenStackCloudBadRequest: + except exc.OpenStackCloudBadRequest: return "" def _get_server_console_output(self, server_id, length=None): @@ -3282,17 +3282,19 @@ class OpenStackCloud( the name or ID provided """ if output_path is None and output_file is None: - raise OpenStackCloudException('No output specified, an output path' - ' or file object is necessary to ' - 'write the image data to') + raise exc.OpenStackCloudException( + 'No output specified, an output path' + ' or file object is necessary to ' + 'write the image data to') elif output_path is not None and output_file is not None: - raise OpenStackCloudException('Both an output path and file object' - ' were provided, however only one ' - 'can be used at once') + raise exc.OpenStackCloudException( + 'Both an output path and file object' + ' were provided, however only one ' + 'can be used at once') image = self.search_images(name_or_id) if len(image) == 0: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "No images with name or ID %s were found" % name_or_id, None) if self._is_client_version('image', 2): endpoint = '/images/{id}/file'.format(id=image[0]['id']) @@ -3387,7 +3389,7 @@ class OpenStackCloud( # Treat DELETE_COMPLETE stacks as a NotFound if stack['stack_status'] == 'DELETE_COMPLETE': return [] - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: return [] stack = self._normalize_stack(stack) return _utils._filter_list([stack], name_or_id, filters) @@ -3427,7 +3429,7 @@ class OpenStackCloud( try: self._compute_client.delete('/os-keypairs/{name}'.format( name=name)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: self.log.debug("Keypair %s not found for deleting", name) return False return True @@ -3466,17 +3468,17 @@ class OpenStackCloud( if availability_zone_hints is not None: if not isinstance(availability_zone_hints, list): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Parameter 'availability_zone_hints' must be a list") if not self._has_neutron_extension('network_availability_zone'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'network_availability_zone extension is not available on ' 'target cloud') network['availability_zone_hints'] = availability_zone_hints if provider: if not isinstance(provider, dict): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Parameter 'provider' must be a dict") # Only pass what we know for attr in ('physical_network', 'network_type', @@ -3493,7 +3495,7 @@ class OpenStackCloud( if port_security_enabled is not None: if not isinstance(port_security_enabled, bool): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Parameter 'port_security_enabled' must be a bool") network['port_security_enabled'] = port_security_enabled @@ -3542,7 +3544,7 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') default = kwargs.pop("default", None) @@ -3577,7 +3579,7 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') default = kwargs.pop("default", None) @@ -3594,7 +3596,7 @@ class OpenStackCloud( curr_policy = self.get_qos_policy(name_or_id) if not curr_policy: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "QoS policy %s not found." % name_or_id) data = self._network_client.put( @@ -3613,7 +3615,7 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(name_or_id) if not policy: @@ -3656,12 +3658,12 @@ class OpenStackCloud( found. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3689,12 +3691,12 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3723,12 +3725,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3764,12 +3766,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3787,7 +3789,7 @@ class OpenStackCloud( curr_rule = self.get_qos_bandwidth_limit_rule( policy_name_or_id, rule_id) if not curr_rule: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "QoS bandwidth_limit_rule {rule_id} not found in policy " "{policy_id}".format(rule_id=rule_id, policy_id=policy['id'])) @@ -3808,12 +3810,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3821,7 +3823,7 @@ class OpenStackCloud( self._network_client.delete( "/qos/policies/{policy}/bandwidth_limit_rules/{rule}.json". format(policy=policy['id'], rule=rule_id)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: self.log.debug( "QoS bandwidth limit rule {rule_id} not found in policy " "{policy_id}. Ignoring.".format(rule_id=rule_id, @@ -3861,12 +3863,12 @@ class OpenStackCloud( found. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3894,12 +3896,12 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3922,12 +3924,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3954,12 +3956,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -3970,7 +3972,7 @@ class OpenStackCloud( curr_rule = self.get_qos_dscp_marking_rule( policy_name_or_id, rule_id) if not curr_rule: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "QoS dscp_marking_rule {rule_id} not found in policy " "{policy_id}".format(rule_id=rule_id, policy_id=policy['id'])) @@ -3991,12 +3993,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4004,7 +4006,7 @@ class OpenStackCloud( self._network_client.delete( "/qos/policies/{policy}/dscp_marking_rules/{rule}.json". format(policy=policy['id'], rule=rule_id)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: self.log.debug( "QoS DSCP marking rule {rule_id} not found in policy " "{policy_id}. Ignoring.".format(rule_id=rule_id, @@ -4046,12 +4048,12 @@ class OpenStackCloud( found. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4079,12 +4081,12 @@ class OpenStackCloud( """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4111,12 +4113,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4143,12 +4145,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4159,7 +4161,7 @@ class OpenStackCloud( curr_rule = self.get_qos_minimum_bandwidth_rule( policy_name_or_id, rule_id) if not curr_rule: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "QoS minimum_bandwidth_rule {rule_id} not found in policy " "{policy_id}".format(rule_id=rule_id, policy_id=policy['id'])) @@ -4180,12 +4182,12 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ if not self._has_neutron_extension('qos'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'QoS extension is not available on target cloud') policy = self.get_qos_policy(policy_name_or_id) if not policy: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "QoS policy {name_or_id} not Found.".format( name_or_id=policy_name_or_id)) @@ -4193,7 +4195,7 @@ class OpenStackCloud( self._network_client.delete( "/qos/policies/{policy}/minimum_bandwidth_rules/{rule}.json". format(policy=policy['id'], rule=rule_id)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: self.log.debug( "QoS minimum bandwidth rule {rule_id} not found in policy " "{policy_id}. Ignoring.".format(rule_id=rule_id, @@ -4353,10 +4355,10 @@ class OpenStackCloud( router['external_gateway_info'] = ext_gw_info if availability_zone_hints is not None: if not isinstance(availability_zone_hints, list): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Parameter 'availability_zone_hints' must be a list") if not self._has_neutron_extension('router_availability_zone'): - raise OpenStackCloudUnavailableExtension( + raise exc.OpenStackCloudUnavailableExtension( 'router_availability_zone extension is not available on ' 'target cloud') router['availability_zone_hints'] = availability_zone_hints @@ -4408,7 +4410,7 @@ class OpenStackCloud( curr_router = self.get_router(name_or_id) if not curr_router: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Router %s not found." % name_or_id) data = self._network_client.put( @@ -4486,7 +4488,7 @@ class OpenStackCloud( if not isinstance(server, dict): server_obj = self.get_server(server, bare=True) if not server_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Server {server} could not be found and therefore" " could not be snapshotted.".format(server=server)) server = server_obj @@ -4535,7 +4537,7 @@ class OpenStackCloud( if image['status'] == 'active': return image elif image['status'] == 'error': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Image {image} hit error state'.format(image=image_id)) def delete_image( @@ -4585,7 +4587,7 @@ class OpenStackCloud( if os.path.exists(name_with_ext): return (os.path.basename(name), name_with_ext) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'No filename parameter was given to create_image,' ' and {name} was not the path to an existing file.' ' Please provide either a path to an existing file' @@ -4684,7 +4686,7 @@ class OpenStackCloud( else: volume_obj = self.get_volume(volume) if not volume_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Volume {volume} given to create_image could" " not be foud".format(volume=volume)) volume_id = volume_obj['id'] @@ -4757,11 +4759,11 @@ class OpenStackCloud( name, filename, meta=meta, wait=wait, timeout=timeout, **image_kwargs) - except OpenStackCloudException: + except exc.OpenStackCloudException: self.log.debug("Image creation failed", exc_info=True) raise except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Image creation failed: {message}".format(message=str(e))) def _make_v2_image_params(self, meta, properties): @@ -4801,7 +4803,7 @@ class OpenStackCloud( image_obj = self.get_image(response['image_id']) if image_obj and image_obj.status not in ('queued', 'saving'): return image_obj - except OpenStackCloudTimeout: + except exc.OpenStackCloudTimeout: self.log.debug( "Timeout waiting for image to become ready. Deleting.") self.delete_image(response['image_id'], wait=True) @@ -4827,7 +4829,7 @@ class OpenStackCloud( try: self._image_client.delete( '/images/{id}'.format(id=image.id)) - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: # We're just trying to clean up - if it doesn't work - shrug self.log.debug( "Failed deleting image after we failed uploading it.", @@ -4858,11 +4860,11 @@ class OpenStackCloud( '/images/{id}'.format(id=image.id), headers=headers, data=image_data) - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: self.log.debug("Deleting failed upload of image %s", name) try: self._image_client.delete('/images/{id}'.format(id=image.id)) - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: # We're just trying to clean up - if it doesn't work - shrug self.log.debug( "Failed deleting image after we failed uploading it.", @@ -4890,7 +4892,7 @@ class OpenStackCloud( image_obj = self.get_image(image.id) if image_obj and image_obj.status not in ('queued', 'saving'): return image_obj - except OpenStackCloudTimeout: + except exc.OpenStackCloudTimeout: self.log.debug( "Timeout waiting for image to become ready. Deleting.") self.delete_image(image.id, wait=True) @@ -4931,7 +4933,7 @@ class OpenStackCloud( if image_id is None: status = self._image_client.get( '/tasks/{id}'.format(id=glance_task.id)) - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code == 503: # Clear the exception so that it doesn't linger # and get reported as an Inner Exception later @@ -4944,7 +4946,7 @@ class OpenStackCloud( image_id = status['result']['image_id'] try: image = self.get_image(image_id) - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code == 503: # Clear the exception so that it doesn't linger # and get reported as an Inner Exception later @@ -4974,7 +4976,7 @@ class OpenStackCloud( # like the content. So we don't want to keep it for # next time. self.delete_object(container, name) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Image creation failed: {message}".format( message=status['message']), extra_data=status) @@ -5064,7 +5066,7 @@ class OpenStackCloud( if image: image_obj = self.get_image(image) if not image_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Image {image} was requested as the basis for a new" " volume, but was not found on the cloud".format( image=image)) @@ -5083,7 +5085,7 @@ class OpenStackCloud( self.list_volumes.invalidate(self) if volume['status'] == 'error': - raise OpenStackCloudException("Error in creating volume") + raise exc.OpenStackCloudException("Error in creating volume") if wait: vol_id = volume['id'] @@ -5103,7 +5105,8 @@ class OpenStackCloud( return volume if volume['status'] == 'error': - raise OpenStackCloudException("Error in creating volume") + raise exc.OpenStackCloudException( + "Error in creating volume") return self._normalize_volume(volume) @@ -5121,7 +5124,7 @@ class OpenStackCloud( volume = self.get_volume(name_or_id) if not volume: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Volume {name_or_id} does not exist".format( name_or_id=name_or_id)) @@ -5165,7 +5168,7 @@ class OpenStackCloud( else: self._volume_client.delete( 'volumes/{id}'.format(id=volume['id'])) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: self.log.debug( "Volume {id} not found when deleting. Ignoring.".format( id=volume['id'])) @@ -5206,7 +5209,7 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") project_id = proj.id params['tenant_id'] = project_id error_msg = "{msg} for the project: {project} ".format( @@ -5276,7 +5279,7 @@ class OpenStackCloud( return if vol['status'] == 'error': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in detaching volume %s" % volume['id'] ) @@ -5306,13 +5309,13 @@ class OpenStackCloud( """ dev = self.get_volume_attach_device(volume, server['id']) if dev: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Volume %s already attached to server %s on device %s" % (volume['id'], server['id'], dev) ) if volume['status'] != 'available': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Volume %s is not available. Status is '%s'" % (volume['id'], volume['status']) ) @@ -5348,7 +5351,7 @@ class OpenStackCloud( # and also attached. If so, we should move this # above the get_volume_attach_device call if vol['status'] == 'error': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in attaching volume %s" % volume['id'] ) return self._normalize_volume_attachment( @@ -5414,7 +5417,7 @@ class OpenStackCloud( break if snapshot['status'] == 'error': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in creating volume snapshot") # TODO(mordred) need to normalize snapshots. We were normalizing them @@ -5507,7 +5510,7 @@ class OpenStackCloud( break if backup['status'] == 'error': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in creating volume backup {id}".format( id=backup_id)) @@ -5693,7 +5696,7 @@ class OpenStackCloud( self._neutron_available_floating_ips( network=network, server=server)) return f_ips[0] - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: self.log.debug( "Something went wrong talking to neutron API: " "'%(msg)s'. Trying with Nova.", {'msg': str(e)}) @@ -5714,7 +5717,7 @@ class OpenStackCloud( if floating_network: floating_network_id = floating_network else: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "unable to find an external network") return floating_network_id @@ -5753,7 +5756,7 @@ class OpenStackCloud( break if floating_network_id is None: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "unable to find external network {net}".format( net=network) ) @@ -5799,7 +5802,7 @@ class OpenStackCloud( if pool is None: pools = self.list_floating_ip_pools() if not pools: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "unable to find a floating ip pool") pool = pools[0]['name'] @@ -5857,14 +5860,14 @@ class OpenStackCloud( nat_destination=nat_destination, port=port, wait=wait, timeout=timeout) - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: self.log.debug( "Something went wrong talking to neutron API: " "'%(msg)s'. Trying with Nova.", {'msg': str(e)}) # Fall-through, trying with Nova if port: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "This cloud uses nova-network which does not support" " arbitrary floating-ip/port mappings. Please nudge" " your cloud provider to upgrade the networking stack" @@ -5892,7 +5895,7 @@ class OpenStackCloud( if network_name_or_id: network = self.get_network(network_name_or_id) if not network: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "unable to find network for floating ips with ID " "{0}".format(network_name_or_id)) network_id = network['id'] @@ -5930,7 +5933,7 @@ class OpenStackCloud( fip = self.get_floating_ip(fip_id) if fip and fip['status'] == 'ACTIVE': break - except OpenStackCloudTimeout: + except exc.OpenStackCloudTimeout: self.log.error( "Timed out on floating ip %(fip)s becoming active." " Deleting", {'fip': fip_id}) @@ -5945,13 +5948,13 @@ class OpenStackCloud( raise if fip['port_id'] != port: if server: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Attempted to create FIP on port {port} for server" " {server} but FIP has port {port_id}".format( port=port, port_id=fip['port_id'], server=server['id'])) else: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Attempted to create FIP on port {port}" " but something went wrong".format(port=port)) return fip @@ -5963,7 +5966,7 @@ class OpenStackCloud( if pool is None: pools = self.list_floating_ip_pools() if not pools: - raise OpenStackCloudResourceNotFound( + raise exc.OpenStackCloudResourceNotFound( "unable to find a floating ip pool") pool = pools[0]['name'] @@ -6007,7 +6010,7 @@ class OpenStackCloud( if not f_ip or f_ip['status'] == 'DOWN': return True - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Attempted to delete Floating IP {ip} with ID {id} a total of" " {retry} times. Although the cloud did not indicate any errors" " the floating ip is still in existence. Aborting further" @@ -6019,7 +6022,7 @@ class OpenStackCloud( if self._use_neutron_floating(): try: return self._neutron_delete_floating_ip(floating_ip_id) - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: self.log.debug( "Something went wrong talking to neutron API: " "'%(msg)s'. Trying with Nova.", {'msg': str(e)}) @@ -6030,10 +6033,10 @@ class OpenStackCloud( self._network_client.delete( "/floatingips/{fip_id}.json".format(fip_id=floating_ip_id), error_message="unable to delete floating IP") - except OpenStackCloudResourceNotFound: + except exc.OpenStackCloudResourceNotFound: return False except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Unable to delete floating IP ID {fip_id}: {msg}".format( fip_id=floating_ip_id, msg=str(e))) return True @@ -6044,7 +6047,7 @@ class OpenStackCloud( '/os-floating-ips/{id}'.format(id=floating_ip_id), error_message='Unable to delete floating IP {fip_id}'.format( fip_id=floating_ip_id)) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: return False return True @@ -6114,7 +6117,7 @@ class OpenStackCloud( server=server, floating_ip=floating_ip, fixed_address=fixed_address, nat_destination=nat_destination) - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: self.log.debug( "Something went wrong talking to neutron API: " "'%(msg)s'. Trying with Nova.", {'msg': str(e)}) @@ -6168,7 +6171,7 @@ class OpenStackCloud( port_filter = {'device_id': server['id']} ports = self.search_ports(filters=port_filter) break - except OpenStackCloudTimeout: + except exc.OpenStackCloudTimeout: ports = None if not ports: return (None, None) @@ -6178,7 +6181,7 @@ class OpenStackCloud( if nat_destination: nat_network = self.get_network(nat_destination) if not nat_network: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'NAT Destination {nat_destination} was configured' ' but not found on the cloud. Please check your' ' config and your cloud and try again.'.format( @@ -6187,7 +6190,7 @@ class OpenStackCloud( nat_network = self.get_nat_destination() if not nat_network: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Multiple ports were found for server {server}' ' but none of the networks are a valid NAT' ' destination, so it is impossible to add a' @@ -6204,7 +6207,7 @@ class OpenStackCloud( if maybe_port['network_id'] == nat_network['id']: maybe_ports.append(maybe_port) if not maybe_ports: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'No port on server {server} was found matching' ' your NAT destination network {dest}. Please ' ' check your config'.format( @@ -6229,7 +6232,7 @@ class OpenStackCloud( if ip.version == 4: fixed_address = address['ip_address'] return port, fixed_address - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "unable to find a free fixed IPv4 address for server " "{0}".format(server['id'])) # unfortunately a port can have more than one fixed IP: @@ -6259,7 +6262,7 @@ class OpenStackCloud( server, fixed_address=fixed_address, nat_destination=nat_destination) if not port: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "unable to find a port for server {0}".format( server['id'])) @@ -6280,7 +6283,7 @@ class OpenStackCloud( f_ip = self.get_floating_ip( id=floating_ip_id) if f_ip is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "unable to find floating IP {0}".format(floating_ip_id)) error_message = "Error attaching IP {ip} to instance {id}".format( ip=floating_ip_id, id=server_id) @@ -6309,7 +6312,7 @@ class OpenStackCloud( try: return self._neutron_detach_ip_from_server( server_id=server_id, floating_ip_id=floating_ip_id) - except OpenStackCloudURINotFound as e: + except exc.OpenStackCloudURINotFound as e: self.log.debug( "Something went wrong talking to neutron API: " "'%(msg)s'. Trying with Nova.", {'msg': str(e)}) @@ -6336,7 +6339,7 @@ class OpenStackCloud( f_ip = self.get_floating_ip(id=floating_ip_id) if f_ip is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "unable to find floating IP {0}".format(floating_ip_id)) error_message = "Error detaching IP {ip} from instance {id}".format( ip=floating_ip_id, id=server_id) @@ -6473,7 +6476,7 @@ class OpenStackCloud( return self._attach_ip_to_server( server=server, floating_ip=f_ip, wait=wait, timeout=timeout, skip_attach=skip_attach) - except OpenStackCloudTimeout: + except exc.OpenStackCloudTimeout: if self._use_neutron_floating() and created: # We are here because we created an IP on the port # It failed. Delete so as not to leak an unmanaged @@ -6556,7 +6559,7 @@ class OpenStackCloud( # No floating ip network - no FIPs try: self._get_floating_network_id() - except OpenStackCloudException: + except exc.OpenStackCloudException: return False (port_obj, fixed_ip_address) = self._nat_destination_port( @@ -6587,7 +6590,7 @@ class OpenStackCloud( if boot_volume: volume = self.get_volume(boot_volume) if not volume: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Volume {boot_volume} is not a valid volume' ' in {cloud}:{region}'.format( boot_volume=boot_volume, @@ -6608,7 +6611,7 @@ class OpenStackCloud( else: image_obj = self.get_image(image) if not image_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Image {image} is not a valid image in' ' {cloud}:{region}'.format( image=image, @@ -6638,7 +6641,7 @@ class OpenStackCloud( for volume in volumes: volume_obj = self.get_volume(volume) if not volume_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Volume {volume} is not a valid volume' ' in {cloud}:{region}'.format( volume=volume, @@ -6662,7 +6665,7 @@ class OpenStackCloud( if not isinstance(userdata, six.binary_type): # If the userdata passed in is bytes, just send it unmodified if not isinstance(userdata, six.string_types): - raise TypeError("%s can't be encoded" % type(text)) + raise TypeError("%s can't be encoded" % type(userdata)) # If it's not bytes, make it bytes userdata = userdata.encode('utf-8', 'strict') @@ -6804,7 +6807,7 @@ class OpenStackCloud( if group: group_obj = self.get_server_group(group) if not group_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Server Group {group} was requested but was not found" " on the cloud".format(group=group)) hints['group'] = group_obj['id'] @@ -6816,7 +6819,7 @@ class OpenStackCloud( # Be nice and help the user out kwargs['nics'] = [kwargs['nics']] else: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'nics parameter to create_server takes a list of dicts.' ' Got: {nics}'.format(nics=kwargs['nics'])) @@ -6830,7 +6833,7 @@ class OpenStackCloud( else: network_obj = self.get_network(name_or_id=net_name) if not network_obj: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Network {network} is not a valid network in' ' {cloud}:{region}'.format( network=network, @@ -6854,7 +6857,7 @@ class OpenStackCloud( elif 'net-name' in nic: nic_net = self.get_network(nic['net-name']) if not nic_net: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Requested network {net} could not be found.".format( net=nic['net-name'])) net['uuid'] = nic_net['id'] @@ -6866,7 +6869,7 @@ class OpenStackCloud( if 'port-id' in nic: net['port'] = nic.pop('port-id') if nic: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Additional unsupported keys given for server network" " creation: {keys}".format(keys=nic.keys())) networks.append(net) @@ -6921,7 +6924,7 @@ class OpenStackCloud( # going to do the wait loop below, this is a waste of a call server = self.get_server_by_id(server.id) if server.status == 'ERROR': - raise OpenStackCloudCreateException( + raise exc.OpenStackCloudCreateException( resource='server', resource_id=server.id) if wait: @@ -6966,7 +6969,7 @@ class OpenStackCloud( # and pass it down into the IP stack. remaining_timeout = timeout - int(time.time() - start_time) if remaining_timeout <= 0: - raise OpenStackCloudTimeout(timeout_message) + raise exc.OpenStackCloudTimeout(timeout_message) server = self.get_active_server( server=server, reuse=reuse, @@ -6983,12 +6986,12 @@ class OpenStackCloud( if server['status'] == 'ERROR': if 'fault' in server and 'message' in server['fault']: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in creating the server: {reason}".format( reason=server['fault']['message']), extra_data=dict(server=server)) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in creating the server", extra_data=dict(server=server)) if server['status'] == 'ACTIVE': @@ -7006,12 +7009,12 @@ class OpenStackCloud( self._delete_server( server=server, wait=wait, timeout=timeout) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Server reached ACTIVE state without being' ' allocated an IP address AND then could not' ' be deleted: {0}'.format(e), extra_data=dict(server=server)) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Server reached ACTIVE state without being' ' allocated an IP address.', extra_data=dict(server=server)) @@ -7049,7 +7052,7 @@ class OpenStackCloud( continue if server['status'] == 'ERROR': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error in rebuilding the server", extra_data=dict(server=server)) @@ -7072,7 +7075,7 @@ class OpenStackCloud( """ server = self.get_server(name_or_id, bare=True) if not server: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Invalid Server {server}'.format(server=name_or_id)) self._compute_client.post( @@ -7092,7 +7095,7 @@ class OpenStackCloud( """ server = self.get_server(name_or_id, bare=True) if not server: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Invalid Server {server}'.format(server=name_or_id)) for key in metadata_keys: @@ -7143,7 +7146,7 @@ class OpenStackCloud( try: ip = self.get_floating_ip(id=None, filters={ 'floating_ip_address': fip['addr']}) - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: # We're deleting. If it doesn't exist - awesome # NOTE(mordred) If the cloud is a nova FIP cloud but # floating_ip_source is set to neutron, this @@ -7154,7 +7157,7 @@ class OpenStackCloud( deleted = self.delete_floating_ip( ip['id'], retry=delete_ip_retry) if not deleted: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Tried to delete floating ip {floating_ip}" " associated with server {id} but there was" " an error deleting it. Not deleting server.".format( @@ -7174,7 +7177,7 @@ class OpenStackCloud( self._compute_client.delete( '/servers/{id}'.format(id=server['id']), error_message="Error in deleting server") - except OpenStackCloudURINotFound: + except exc.OpenStackCloudURINotFound: return False except Exception: raise @@ -7232,7 +7235,7 @@ class OpenStackCloud( """ server = self.get_server(name_or_id=name_or_id, bare=True) if server is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "failed to find server '{server}'".format(server=name_or_id)) data = self._compute_client.put( @@ -7301,7 +7304,7 @@ class OpenStackCloud( try: container = self._object_store_client.head(name) self._container_cache[name] = container.headers - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code == 404: return None raise @@ -7320,11 +7323,11 @@ class OpenStackCloud( try: self._object_store_client.delete(name) return True - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code == 404: return False if e.response.status_code == 409: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Attempt to delete container {container} failed. The' ' container is not empty. Please delete the objects' ' inside it before deleting the container'.format( @@ -7336,7 +7339,7 @@ class OpenStackCloud( def set_container_access(self, name, access): if access not in OBJECT_CONTAINER_ACLS: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Invalid container access specified: %s. Must be one of %s" % (access, list(OBJECT_CONTAINER_ACLS.keys()))) header = {'x-container-read': OBJECT_CONTAINER_ACLS[access]} @@ -7345,7 +7348,7 @@ class OpenStackCloud( def get_container_access(self, name): container = self.get_container(name, skip_cache=True) if not container: - raise OpenStackCloudException("Container not found: %s" % name) + raise exc.OpenStackCloudException("Container not found: %s" % name) acl = container.get('x-container-read', '') for key, value in OBJECT_CONTAINER_ACLS.items(): # Convert to string for the comparison because swiftclient @@ -7353,7 +7356,7 @@ class OpenStackCloud( # on bytes doesn't work like you'd think if str(acl) == str(value): return key - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Could not determine container access for ACL: %s." % acl) def _get_file_hashes(self, filename): @@ -7398,7 +7401,7 @@ class OpenStackCloud( min_segment_size = 0 try: caps = self.get_object_capabilities() - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code in (404, 412): # Clear the exception so that it doesn't linger # and get reported as an Inner Exception later @@ -7704,7 +7707,7 @@ class OpenStackCloud( container=container, object=name), params=params) return True - except OpenStackCloudHTTPError: + except exc.OpenStackCloudHTTPError: return False def delete_autocreated_image_objects( @@ -7734,7 +7737,7 @@ class OpenStackCloud( return self._object_store_client.head( '{container}/{object}'.format( container=container, object=name)).headers - except OpenStackCloudException as e: + except exc.OpenStackCloudException as e: if e.response.status_code == 404: return None raise @@ -7786,7 +7789,7 @@ class OpenStackCloud( return (response_headers, None) else: return (response_headers, response.text) - except OpenStackCloudHTTPError as e: + except exc.OpenStackCloudHTTPError as e: if e.response.status_code == 404: return None raise @@ -7875,19 +7878,19 @@ class OpenStackCloud( network = self.get_network(network_name_or_id, filters) if not network: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Network %s not found." % network_name_or_id) if disable_gateway_ip and gateway_ip: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'arg:disable_gateway_ip is not allowed with arg:gateway_ip') if not cidr and not use_default_subnetpool: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'arg:cidr is required when a subnetpool is not used') if cidr and use_default_subnetpool: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'arg:cidr must be set to None when use_default_subnetpool == ' 'True') @@ -7896,7 +7899,8 @@ class OpenStackCloud( try: ip_version = int(ip_version) except ValueError: - raise OpenStackCloudException('ip_version must be an integer') + raise exc.OpenStackCloudException( + 'ip_version must be an integer') # The body of the neutron message for the subnet we wish to create. # This includes attributes that are required or have defaults. @@ -8031,12 +8035,12 @@ class OpenStackCloud( return if disable_gateway_ip and gateway_ip: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'arg:disable_gateway_ip is not allowed with arg:gateway_ip') curr_subnet = self.get_subnet(name_or_id) if not curr_subnet: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Subnet %s not found." % name_or_id) data = self._network_client.put( @@ -8164,7 +8168,7 @@ class OpenStackCloud( """ port = self.get_port(name_or_id=name_or_id) if port is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "failed to find port '{port}'".format(port=name_or_id)) data = self._network_client.put( @@ -8210,7 +8214,7 @@ class OpenStackCloud( # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) @@ -8245,7 +8249,7 @@ class OpenStackCloud( """ # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) @@ -8284,14 +8288,14 @@ class OpenStackCloud( """ # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) group = self.get_security_group(name_or_id) if group is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Security group %s not found." % name_or_id) if self._use_neutron_secgroups(): @@ -8366,13 +8370,13 @@ class OpenStackCloud( """ # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) secgroup = self.get_security_group(secgroup_name_or_id) if not secgroup: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Security group %s not found." % secgroup_name_or_id) if self._use_neutron_secgroups(): @@ -8400,13 +8404,14 @@ class OpenStackCloud( else: # NOTE: Neutron accepts None for protocol. Nova does not. if protocol is None: - raise OpenStackCloudException('Protocol must be specified') + raise exc.OpenStackCloudException('Protocol must be specified') if direction == 'egress': self.log.debug( 'Rule creation failed: Nova does not support egress rules' ) - raise OpenStackCloudException('No support for egress rules') + raise exc.OpenStackCloudException( + 'No support for egress rules') # NOTE: Neutron accepts None for ports, but Nova requires -1 # as the equivalent value for ICMP. @@ -8456,7 +8461,7 @@ class OpenStackCloud( """ # Security groups not supported if not self._has_secgroups(): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( "Unavailable feature: security groups" ) @@ -8466,7 +8471,7 @@ class OpenStackCloud( '/security-group-rules/{sg_id}.json'.format(sg_id=rule_id), error_message="Error deleting security group rule " "{0}".format(rule_id)) - except OpenStackCloudResourceNotFound: + except exc.OpenStackCloudResourceNotFound: return False return True @@ -8528,7 +8533,7 @@ class OpenStackCloud( if zone_type is not None: zone_type = zone_type.upper() if zone_type not in ('PRIMARY', 'SECONDARY'): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Invalid type %s, valid choices are PRIMARY or SECONDARY" % zone_type) @@ -8569,7 +8574,7 @@ class OpenStackCloud( """ zone = self.get_zone(name_or_id) if not zone: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Zone %s not found." % name_or_id) data = self._dns_client.patch( @@ -8649,7 +8654,7 @@ class OpenStackCloud( """ if self.get_zone(zone) is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Zone %s not found." % zone) # We capitalize the type in case the user sends in lowercase @@ -8688,12 +8693,12 @@ class OpenStackCloud( """ zone_obj = self.get_zone(zone) if zone_obj is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Zone %s not found." % zone) recordset_obj = self.get_recordset(zone, name_or_id) if recordset_obj is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Recordset %s not found." % name_or_id) new_recordset = self._dns_client.put( @@ -8876,7 +8881,7 @@ class OpenStackCloud( self.list_cluster_templates.invalidate(self) cluster_template = self.get_cluster_template(name_or_id) if not cluster_template: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Cluster template %s not found." % name_or_id) if operation not in ['add', 'replace', 'remove']: @@ -9003,7 +9008,7 @@ class OpenStackCloud( machine = self.get_machine(name_or_id) if not machine: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine inspection failed to find: %s." % name_or_id) # NOTE(TheJulia): If in available state, we can do this, however @@ -9017,7 +9022,7 @@ class OpenStackCloud( wait=True, timeout=timeout) elif ("manage" not in machine['provision_state'] and "inspect failed" not in machine['provision_state']): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine must be in 'manage' or 'available' state to " "engage inspection: Machine: %s State: %s" % (machine['uuid'], machine['provision_state'])) @@ -9031,7 +9036,7 @@ class OpenStackCloud( machine = self.get_machine(name_or_id) if "inspect failed" in machine['provision_state']: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Inspection of node %s failed, last error: %s" % (machine['uuid'], machine['last_error'])) @@ -9136,7 +9141,7 @@ class OpenStackCloud( self._baremetal_client.delete(url, error_message=msg, microversion=version) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error registering NICs with the baremetal service: %s" % str(e)) @@ -9160,7 +9165,7 @@ class OpenStackCloud( self.node_set_provision_state( machine['uuid'], 'provide') elif machine['last_error'] is not None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine encountered a failure: %s" % machine['last_error']) @@ -9201,7 +9206,7 @@ class OpenStackCloud( break elif machine['last_error'] is not None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine encountered a failure: %s" % machine['last_error']) if not isinstance(machine, str): @@ -9232,7 +9237,7 @@ class OpenStackCloud( machine = self.get_machine(uuid) invalid_states = ['active', 'cleaning', 'clean wait', 'clean failed'] if machine['provision_state'] in invalid_states: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error unregistering node '%s' due to current provision " "state '%s'" % (uuid, machine['provision_state'])) @@ -9242,11 +9247,11 @@ class OpenStackCloud( # failure, and resubitted the request in python-ironicclient. try: self.wait_for_baremetal_node_lock(machine, timeout=timeout) - except OpenStackCloudException as e: - raise OpenStackCloudException("Error unregistering node '%s': " - "Exception occured while waiting " - "to be able to proceed: %s" - % (machine['uuid'], e)) + except exc.OpenStackCloudException as e: + raise exc.OpenStackCloudException( + "Error unregistering node '%s': Exception occured while" + " waiting to be able to proceed: %s" + % (machine['uuid'], e)) for nic in nics: port_msg = ("Error removing NIC {nic} from baremetal API for " @@ -9366,7 +9371,7 @@ class OpenStackCloud( """ machine = self.get_machine(name_or_id) if not machine: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine update failed to find Machine: %s. " % name_or_id) machine_config = {} @@ -9404,7 +9409,7 @@ class OpenStackCloud( self.log.debug( "Unexpected machine response missing key %s [%s]", e.args[0], name_or_id) - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine update failed - machine [%s] missing key %s. " "Potential API issue." % (name_or_id, e.args[0])) @@ -9412,7 +9417,7 @@ class OpenStackCloud( try: patch = jsonpatch.JsonPatch.from_diff(machine_config, new_config) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine update failed - Error generating JSON patch object " "for submission to the API. Machine: %s Error: %s" % (name_or_id, str(e))) @@ -9457,7 +9462,7 @@ class OpenStackCloud( is_power_valid = validate_resp.get( 'power', {'result': False}).get('result', False) if not is_deploy_valid or not is_power_valid: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "ironic node {} failed to validate. " "(deploy: {}, power: {})".format( uuid, @@ -9525,7 +9530,7 @@ class OpenStackCloud( "target state of '%s'" % state): machine = self.get_machine(name_or_id) if 'failed' in machine['provision_state']: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Machine encountered a failure.") # NOTE(TheJulia): This performs matching if the requested # end state matches the state the node has reached. @@ -9795,7 +9800,7 @@ class OpenStackCloud( def update_service(self, name_or_id, **kwargs): # NOTE(SamYaple): Service updates are only available on v3 api if self._is_client_version('identity', 2): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( 'Unavailable Feature: Service update requires Identity v3' ) @@ -9927,20 +9932,21 @@ class OpenStackCloud( admin_url = kwargs.pop('admin_url', None) if (url or interface) and (public_url or internal_url or admin_url): - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "create_endpoint takes either url and interface OR" " public_url, internal_url, admin_url") service = self.get_service(name_or_id=service_name_or_id) if service is None: - raise OpenStackCloudException("service {service} not found".format( - service=service_name_or_id)) + raise exc.OpenStackCloudException( + "service {service} not found".format( + service=service_name_or_id)) if self._is_client_version('identity', 2): if url: # v2.0 in use, v3-like arguments, one endpoint created if interface != 'public': - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Error adding endpoint for service {service}." " On a v2 cloud the url/interface API may only be" " used for public url. Try using the public_url," @@ -10009,7 +10015,7 @@ class OpenStackCloud( def update_endpoint(self, endpoint_id, **kwargs): # NOTE(SamYaple): Endpoint updates are only available on v3 api if self._is_client_version('identity', 2): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( 'Unavailable Feature: Endpoint update' ) @@ -10116,7 +10122,7 @@ class OpenStackCloud( :returns: a ``munch.Munch`` containing the domain representation. - :raise OpenStackCloudException: if the domain cannot be created. + :raise exc.OpenStackCloudException: if the domain cannot be created. """ domain_ref = {'name': name, 'enabled': enabled} if description is not None: @@ -10132,12 +10138,12 @@ class OpenStackCloud( enabled=None, name_or_id=None): if domain_id is None: if name_or_id is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "You must pass either domain_id or name_or_id value" ) dom = self.get_domain(None, name_or_id) if dom is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Domain {0} not found for updating".format(name_or_id) ) domain_id = dom['id'] @@ -10167,7 +10173,7 @@ class OpenStackCloud( """ if domain_id is None: if name_or_id is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "You must pass either domain_id or name_or_id value" ) dom = self.get_domain(name_or_id=name_or_id) @@ -10321,7 +10327,7 @@ class OpenStackCloud( if domain: dom = self.get_domain(domain) if not dom: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Creating group {group} failed: Invalid domain " "{domain}".format(group=name, domain=domain) ) @@ -10351,7 +10357,7 @@ class OpenStackCloud( self.list_groups.invalidate(self) group = self.get_group(name_or_id, **kwargs) if group is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Group {0} not found for updating".format(name_or_id) ) @@ -10555,7 +10561,7 @@ class OpenStackCloud( if self._is_client_version('identity', 2): if filters.get('project') is None or filters.get('user') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Must provide project and user for keystone v2" ) assignments = self._keystone_v2_role_assignments(**filters) @@ -10640,7 +10646,7 @@ class OpenStackCloud( "/flavors/{id}/os-extra_specs".format(id=flavor_id), json=dict(extra_specs=extra_specs)) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Unable to set flavor specs: {0}".format(str(e)) ) @@ -10659,7 +10665,7 @@ class OpenStackCloud( "/flavors/{id}/os-extra_specs/{key}".format( id=flavor_id, key=key)) except Exception as e: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Unable to delete flavor spec {0}: {1}".format( key, str(e))) @@ -10721,7 +10727,7 @@ class OpenStackCloud( :returns: a ``munch.Munch`` containing the role description - :raise OpenStackCloudException: if the role cannot be created + :raise exc.OpenStackCloudException: if the role cannot be created """ v2 = self._is_client_version('identity', 2) url = '/OS-KSADM/roles' if v2 else '/roles' @@ -10742,10 +10748,10 @@ class OpenStackCloud( :returns: a ``munch.Munch`` containing the role description - :raise OpenStackCloudException: if the role cannot be created + :raise exc.OpenStackCloudException: if the role cannot be created """ if self._is_client_version('identity', 2): - raise OpenStackCloudUnavailableFeature( + raise exc.OpenStackCloudUnavailableFeature( 'Unavailable Feature: Role update requires Identity v3' ) kwargs['name_or_id'] = name_or_id @@ -10839,24 +10845,24 @@ class OpenStackCloud( :returns: True if the role is assigned, otherwise False - :raise OpenStackCloudException: if the role cannot be granted + :raise exc.OpenStackCloudException: if the role cannot be granted """ data = self._get_grant_revoke_params(name_or_id, user, group, project, domain) filters = data.copy() if not data: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Role {0} not found.'.format(name_or_id)) if data.get('user') is not None and data.get('group') is not None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Specify either a group or a user, not both') if data.get('user') is None and data.get('group') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify either a user or a group') if self._is_client_version('identity', 2) and \ data.get('project') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify project for keystone v2') if self.list_role_assignments(filters=filters): @@ -10873,7 +10879,7 @@ class OpenStackCloud( endpoint_filter={'interface': 'admin'}) else: if data.get('project') is None and data.get('domain') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify either a domain or project') # For v3, figure out the assignment type and build the URL @@ -10916,25 +10922,25 @@ class OpenStackCloud( :returns: True if the role is revoke, otherwise False - :raise OpenStackCloudException: if the role cannot be removed + :raise exc.OpenStackCloudException: if the role cannot be removed """ data = self._get_grant_revoke_params(name_or_id, user, group, project, domain) filters = data.copy() if not data: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Role {0} not found.'.format(name_or_id)) if data.get('user') is not None and data.get('group') is not None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Specify either a group or a user, not both') if data.get('user') is None and data.get('group') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify either a user or a group') if self._is_client_version('identity', 2) and \ data.get('project') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify project for keystone v2') if not self.list_role_assignments(filters=filters): @@ -10952,7 +10958,7 @@ class OpenStackCloud( endpoint_filter={'interface': 'admin'}) else: if data.get('project') is None and data.get('domain') is None: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( 'Must specify either a domain or project') # For v3, figure out the assignment type and build the URL @@ -11067,7 +11073,7 @@ class OpenStackCloud( """ aggregate = self.get_aggregate(name_or_id) if not aggregate: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Host aggregate %s not found." % name_or_id) data = self._compute_client.put( @@ -11111,7 +11117,7 @@ class OpenStackCloud( """ aggregate = self.get_aggregate(name_or_id) if not aggregate: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Host aggregate %s not found." % name_or_id) err_msg = "Unable to set metadata for host aggregate {name}".format( @@ -11133,7 +11139,7 @@ class OpenStackCloud( """ aggregate = self.get_aggregate(name_or_id) if not aggregate: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Host aggregate %s not found." % name_or_id) err_msg = "Unable to add host {host} to aggregate {name}".format( @@ -11154,7 +11160,7 @@ class OpenStackCloud( """ aggregate = self.get_aggregate(name_or_id) if not aggregate: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Host aggregate %s not found." % name_or_id) err_msg = "Unable to remove host {host} to aggregate {name}".format( @@ -11174,7 +11180,7 @@ class OpenStackCloud( """ volume_type = self.get_volume_type(name_or_id) if not volume_type: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) data = self._volume_client.get( @@ -11196,7 +11202,7 @@ class OpenStackCloud( """ volume_type = self.get_volume_type(name_or_id) if not volume_type: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) with _utils.shade_exceptions(): payload = {'project': project_id} @@ -11217,7 +11223,7 @@ class OpenStackCloud( """ volume_type = self.get_volume_type(name_or_id) if not volume_type: - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) with _utils.shade_exceptions(): payload = {'project': project_id} @@ -11240,7 +11246,7 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") # compute_quotas = {key: val for key, val in kwargs.items() # if key in quota.COMPUTE_QUOTAS} @@ -11266,7 +11272,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") data = self._compute_client.get( '/os-quota-sets/{project}'.format(project=proj.id)) return self._get_and_munchify('quota_set', data) @@ -11282,7 +11288,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") return self._compute_client.delete( '/os-quota-sets/{project}'.format(project=proj.id)) @@ -11306,7 +11312,7 @@ class OpenStackCloud( # Yes. This is an exception mask. However,iso8601 is an # implementation detail - and the error message is actually # less informative. - raise OpenStackCloudException( + raise exc.OpenStackCloudException( "Date given, {date}, is invalid. Please pass in a date" " string in ISO 8601 format -" " YYYY-MM-DDTHH:MM:SS".format( @@ -11338,8 +11344,8 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist: {}".format( - name=proj.id)) + raise exc.OpenStackCloudException( + "project does not exist: {}".format(name=proj.id)) data = self._compute_client.get( '/os-simple-tenant-usage/{project}'.format(project=proj.id), @@ -11361,7 +11367,7 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") kwargs['tenant_id'] = proj.id self._volume_client.put( @@ -11379,7 +11385,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") data = self._volume_client.get( '/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id), @@ -11397,7 +11403,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") return self._volume_client.delete( '/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id), @@ -11415,7 +11421,7 @@ class OpenStackCloud( proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") self._network_client.put( '/quotas/{project_id}.json'.format(project_id=proj.id), @@ -11435,7 +11441,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") url = '/quotas/{project_id}'.format(project_id=proj.id) if details: url = url + "/details" @@ -11464,7 +11470,7 @@ class OpenStackCloud( """ proj = self.get_project(name_or_id) if not proj: - raise OpenStackCloudException("project does not exist") + raise exc.OpenStackCloudException("project does not exist") self._network_client.delete( '/quotas/{project_id}.json'.format(project_id=proj.id), error_message=("Error deleting Neutron's quota for " diff --git a/tox.ini b/tox.ini index 84502f892..e1f55d7ec 100644 --- a/tox.ini +++ b/tox.ini @@ -88,7 +88,9 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen # single vs double quotes in the license text. Fixing is not worth it # H306 Is about alphabetical imports - there's a lot to fix # H4 Are about docstrings - and there's just too many of them to fix -ignore = H103,H306,H4 +# W503 Is supposed to be off by default but a bug has it on by default. It's +# also a categorially terrible idea and Donald Knuth agrees with me. +ignore = H103,H306,H4,W503 show-source = True builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build