Remove pep8 whitespace ignores

We had carried over the full list of pep8 whitespace ignores from nova.
Trying to address them all in the entire nova repository would have been
too big a task; but it's tenable here in placement.

Do it now rather than letting these whitespace issues compound.

This change removes the E* whitespace ignores and fixes the pep8 issues
they were masking.

Change-Id: Icbabdb9b56fd5a3e9fd14ab537abf3d0d6456fee
This commit is contained in:
Eric Fried 2019-03-01 17:12:20 -06:00
parent d158cbc8a4
commit 849c89d0e5
35 changed files with 615 additions and 566 deletions

View File

@ -79,7 +79,7 @@ html_theme = 'openstackdocs'
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"sidebar_mode": "toc",
"sidebar_mode": "toc",
}
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,

View File

@ -15,14 +15,16 @@
from oslo_config import cfg
api_group = cfg.OptGroup('api',
api_group = cfg.OptGroup(
'api',
title='API options',
help="""
Options under this group are used to define Placement API.
""")
api_opts = [
cfg.StrOpt("auth_strategy",
cfg.StrOpt(
"auth_strategy",
default="keystone",
choices=("keystone", "noauth2"),
deprecated_group="DEFAULT",

View File

@ -21,9 +21,10 @@ from oslo_config import cfg
ALL_OPTS = [
cfg.StrOpt('pybasedir',
default=os.path.abspath(os.path.join(os.path.dirname(__file__),
'../../')),
cfg.StrOpt(
'pybasedir',
default=os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../')),
sample_default='<Path>',
help="""
The directory where the Placement python modules are installed.
@ -40,7 +41,8 @@ Related options:
* ``state_path``
"""),
cfg.StrOpt('state_path',
cfg.StrOpt(
'state_path',
default='$pybasedir',
help="""
The top-level directory for maintaining state used in Placement.

View File

@ -30,159 +30,183 @@ depends_on = None
def upgrade():
op.create_table('allocations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('consumer_id', sa.String(length=36), nullable=False),
sa.Column('resource_class_id', sa.Integer(), nullable=False),
sa.Column('used', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
)
op.create_index('allocations_resource_provider_class_used_idx',
'allocations', ['resource_provider_id', 'resource_class_id',
'used'], unique=False)
op.create_index('allocations_resource_class_id_idx', 'allocations',
['resource_class_id'], unique=False)
op.create_index('allocations_consumer_id_idx', 'allocations',
['consumer_id'], unique=False)
op.create_table(
'allocations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('consumer_id', sa.String(length=36), nullable=False),
sa.Column('resource_class_id', sa.Integer(), nullable=False),
sa.Column('used', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(
'allocations_resource_provider_class_used_idx', 'allocations',
['resource_provider_id', 'resource_class_id', 'used'], unique=False)
op.create_index(
'allocations_resource_class_id_idx', 'allocations',
['resource_class_id'], unique=False)
op.create_index(
'allocations_consumer_id_idx', 'allocations', ['consumer_id'],
unique=False)
op.create_table('consumers',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('project_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('generation', sa.Integer(), server_default=sa.text('0'),
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_consumers0uuid'),
)
op.create_index('consumers_project_id_user_id_uuid_idx', 'consumers',
['project_id', 'user_id', 'uuid'], unique=False)
op.create_index('consumers_project_id_uuid_idx', 'consumers',
['project_id', 'uuid'], unique=False)
op.create_table(
'consumers',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('project_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('generation', sa.Integer(), server_default=sa.text('0'),
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_consumers0uuid'),
)
op.create_index(
'consumers_project_id_user_id_uuid_idx', 'consumers',
['project_id', 'user_id', 'uuid'], unique=False)
op.create_index(
'consumers_project_id_uuid_idx', 'consumers',
['project_id', 'uuid'], unique=False)
op.create_table('inventories',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('resource_class_id', sa.Integer(), nullable=False),
sa.Column('total', sa.Integer(), nullable=False),
sa.Column('reserved', sa.Integer(), nullable=False),
sa.Column('min_unit', sa.Integer(), nullable=False),
sa.Column('max_unit', sa.Integer(), nullable=False),
sa.Column('step_size', sa.Integer(), nullable=False),
sa.Column('allocation_ratio', sa.Float(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('resource_provider_id', 'resource_class_id',
name='uniq_inventories0resource_provider_resource_class'),
)
op.create_index('inventories_resource_class_id_idx', 'inventories',
['resource_class_id'], unique=False)
op.create_index('inventories_resource_provider_id_idx', 'inventories',
['resource_provider_id'], unique=False)
op.create_index('inventories_resource_provider_resource_class_idx',
'inventories', ['resource_provider_id', 'resource_class_id'],
unique=False)
op.create_table(
'inventories',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('resource_class_id', sa.Integer(), nullable=False),
sa.Column('total', sa.Integer(), nullable=False),
sa.Column('reserved', sa.Integer(), nullable=False),
sa.Column('min_unit', sa.Integer(), nullable=False),
sa.Column('max_unit', sa.Integer(), nullable=False),
sa.Column('step_size', sa.Integer(), nullable=False),
sa.Column('allocation_ratio', sa.Float(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint(
'resource_provider_id', 'resource_class_id',
name='uniq_inventories0resource_provider_resource_class'),
)
op.create_index(
'inventories_resource_class_id_idx', 'inventories',
['resource_class_id'], unique=False)
op.create_index(
'inventories_resource_provider_id_idx', 'inventories',
['resource_provider_id'], unique=False)
op.create_index(
'inventories_resource_provider_resource_class_idx',
'inventories', ['resource_provider_id', 'resource_class_id'],
unique=False)
op.create_table('placement_aggregates',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_placement_aggregates0uuid')
)
op.create_table(
'placement_aggregates',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_placement_aggregates0uuid')
)
op.create_index(op.f('ix_placement_aggregates_uuid'),
'placement_aggregates', ['uuid'], unique=False)
'placement_aggregates', ['uuid'], unique=False)
op.create_table('projects',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('external_id', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('external_id',
name='uniq_projects0external_id'),
)
op.create_table(
'projects',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('external_id', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('external_id', name='uniq_projects0external_id'),
)
op.create_table('resource_classes',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_resource_classes0name'),
)
op.create_table(
'resource_classes',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_resource_classes0name'),
)
op.create_table('resource_provider_aggregates',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('aggregate_id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('resource_provider_id', 'aggregate_id'),
)
op.create_index('resource_provider_aggregates_aggregate_id_idx',
'resource_provider_aggregates', ['aggregate_id'], unique=False)
op.create_table(
'resource_provider_aggregates',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('aggregate_id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('resource_provider_id', 'aggregate_id'),
)
op.create_index(
'resource_provider_aggregates_aggregate_id_idx',
'resource_provider_aggregates', ['aggregate_id'], unique=False)
op.create_table('resource_providers',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('name', sa.Unicode(length=200), nullable=True),
sa.Column('generation', sa.Integer(), nullable=True),
sa.Column('root_provider_id', sa.Integer(), nullable=True),
sa.Column('parent_provider_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['parent_provider_id'],
['resource_providers.id']),
sa.ForeignKeyConstraint(['root_provider_id'],
['resource_providers.id']),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_resource_providers0name'),
sa.UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
)
op.create_index('resource_providers_name_idx', 'resource_providers',
['name'], unique=False)
op.create_index('resource_providers_parent_provider_id_idx',
'resource_providers', ['parent_provider_id'], unique=False)
op.create_index('resource_providers_root_provider_id_idx',
'resource_providers', ['root_provider_id'], unique=False)
op.create_index('resource_providers_uuid_idx', 'resource_providers',
['uuid'], unique=False)
op.create_table(
'resource_providers',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('name', sa.Unicode(length=200), nullable=True),
sa.Column('generation', sa.Integer(), nullable=True),
sa.Column('root_provider_id', sa.Integer(), nullable=True),
sa.Column('parent_provider_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['parent_provider_id'],
['resource_providers.id']),
sa.ForeignKeyConstraint(['root_provider_id'],
['resource_providers.id']),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_resource_providers0name'),
sa.UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
)
op.create_index(
'resource_providers_name_idx', 'resource_providers', ['name'],
unique=False)
op.create_index(
'resource_providers_parent_provider_id_idx', 'resource_providers',
['parent_provider_id'], unique=False)
op.create_index(
'resource_providers_root_provider_id_idx',
'resource_providers', ['root_provider_id'], unique=False)
op.create_index(
'resource_providers_uuid_idx', 'resource_providers', ['uuid'],
unique=False)
op.create_table('traits',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.Unicode(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_traits0name'),
)
op.create_table(
'traits',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.Unicode(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_traits0name'),
)
op.create_table('users',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('external_id', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('external_id', name='uniq_users0external_id'),
)
op.create_table(
'users',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('external_id', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('external_id', name='uniq_users0external_id'),
)
op.create_table('resource_provider_traits',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('trait_id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['resource_provider_id'],
['resource_providers.id'], ),
sa.ForeignKeyConstraint(['trait_id'], ['traits.id'], ),
sa.PrimaryKeyConstraint('trait_id', 'resource_provider_id'),
)
op.create_index('resource_provider_traits_resource_provider_trait_idx',
'resource_provider_traits', ['resource_provider_id', 'trait_id'],
unique=False)
op.create_table(
'resource_provider_traits',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('trait_id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['resource_provider_id'],
['resource_providers.id'], ),
sa.ForeignKeyConstraint(['trait_id'], ['traits.id'], ),
sa.PrimaryKeyConstraint('trait_id', 'resource_provider_id'),
)
op.create_index(
'resource_provider_traits_resource_provider_trait_idx',
'resource_provider_traits', ['resource_provider_id', 'trait_id'],
unique=False)

View File

@ -51,15 +51,13 @@ class ResourceProvider(BASE):
__tablename__ = "resource_providers"
__table_args__ = (
Index('resource_providers_uuid_idx', 'uuid'),
schema.UniqueConstraint('uuid',
name='uniq_resource_providers0uuid'),
schema.UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
Index('resource_providers_name_idx', 'name'),
Index('resource_providers_root_provider_id_idx',
'root_provider_id'),
Index('resource_providers_parent_provider_id_idx',
'parent_provider_id'),
schema.UniqueConstraint('name',
name='uniq_resource_providers0name')
schema.UniqueConstraint('name', name='uniq_resource_providers0name')
)
id = Column(Integer, primary_key=True, nullable=False)
@ -67,12 +65,12 @@ class ResourceProvider(BASE):
name = Column(Unicode(200), nullable=True)
generation = Column(Integer, default=0)
# Represents the root of the "tree" that the provider belongs to
root_provider_id = Column(Integer, ForeignKey('resource_providers.id'),
nullable=True)
root_provider_id = Column(
Integer, ForeignKey('resource_providers.id'), nullable=True)
# The immediate parent provider of this provider, or NULL if there is no
# parent. If parent_provider_id == NULL then root_provider_id == id
parent_provider_id = Column(Integer, ForeignKey('resource_providers.id'),
nullable=True)
parent_provider_id = Column(
Integer, ForeignKey('resource_providers.id'), nullable=True)
class Inventory(BASE):
@ -86,7 +84,8 @@ class Inventory(BASE):
'resource_class_id'),
Index('inventories_resource_provider_resource_class_idx',
'resource_provider_id', 'resource_class_id'),
schema.UniqueConstraint('resource_provider_id', 'resource_class_id',
schema.UniqueConstraint(
'resource_provider_id', 'resource_class_id',
name='uniq_inventories0resource_provider_resource_class')
)

View File

@ -76,8 +76,8 @@ class PlacementDirect(interceptor.RequestsInterceptor):
# TODO(efried): Figure out why this isn't working:
# default_microversion='latest' if latest_microversion else None)
self._mocked_endpoint = mock.patch(
'keystoneauth1.session.Session.get_endpoint',
new=mock.Mock(return_value=self.url))
'keystoneauth1.session.Session.get_endpoint',
new=mock.Mock(return_value=self.url))
super(PlacementDirect, self).__init__(app, url=self.url)
def __enter__(self):

View File

@ -206,8 +206,8 @@ class PlacementHandler(object):
try:
if clen and (int(clen) > 0) and not environ.get('CONTENT_TYPE'):
raise webob.exc.HTTPBadRequest(
_('content-type header required when content-length > 0'),
json_formatter=util.json_error_formatter)
_('content-type header required when content-length > 0'),
json_formatter=util.json_error_formatter)
except ValueError as exc:
raise webob.exc.HTTPBadRequest(
_('content-length header must be an integer'),

View File

@ -409,9 +409,9 @@ def _set_allocations_for_consumer(req, schema):
# NOTE(jaypipes): This will only occur 1.28+. The JSONSchema will
# prevent an empty allocations object from being passed when there is
# no consumer generation, so this is safe to do.
data_util.ensure_consumer(context, consumer_uuid,
data.get('project_id'), data.get('user_id'),
data.get('consumer_generation'), want_version)
data_util.ensure_consumer(
context, consumer_uuid, data.get('project_id'),
data.get('user_id'), data.get('consumer_generation'), want_version)
allocations = alloc_obj.get_all_by_consumer_id(context, consumer_uuid)
for allocation in allocations:
allocation.used = 0
@ -448,9 +448,8 @@ def _set_allocations_for_consumer(req, schema):
# capacity limits have been exceeded.
except exception.NotFound as exc:
raise webob.exc.HTTPBadRequest(
_("Unable to allocate inventory for consumer "
"%(consumer_uuid)s: %(error)s") %
{'consumer_uuid': consumer_uuid, 'error': exc})
_("Unable to allocate inventory for consumer %(consumer_uuid)s: "
"%(error)s") % {'consumer_uuid': consumer_uuid, 'error': exc})
except exception.InvalidInventory as exc:
raise webob.exc.HTTPConflict(
_('Unable to allocate inventory: %(error)s') % {'error': exc})
@ -458,7 +457,7 @@ def _set_allocations_for_consumer(req, schema):
raise webob.exc.HTTPConflict(
_('Inventory and/or allocations changed while attempting to '
'allocate: %(error)s') % {'error': exc},
comment=errors.CONCURRENT_UPDATE)
comment=errors.CONCURRENT_UPDATE)
req.response.status = 204
req.response.content_type = None
@ -536,7 +535,7 @@ def set_allocations(req):
raise webob.exc.HTTPConflict(
_('Inventory and/or allocations changed while attempting to '
'allocate: %(error)s') % {'error': exc},
comment=errors.CONCURRENT_UPDATE)
comment=errors.CONCURRENT_UPDATE)
req.response.status = 204
req.response.content_type = None
@ -558,9 +557,9 @@ def delete_allocations(req):
# activity. In that case, delete_all() will throw a NotFound exception.
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("Allocation for consumer with id %(id)s not found."
"error: %(error)s") %
{'id': consumer_uuid, 'error': exc})
_("Allocation for consumer with id %(id)s not found. error: "
"%(error)s") %
{'id': consumer_uuid, 'error': exc})
else:
raise webob.exc.HTTPNotFound(
_("No allocations for consumer '%(consumer_uuid)s'") %

View File

@ -245,7 +245,7 @@ def delete_inventory(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_('No inventory of class %(class)s found for delete: %(error)s') %
{'class': resource_class, 'error': exc})
{'class': resource_class, 'error': exc})
response = req.response
response.status = 204
@ -269,7 +269,7 @@ def get_inventories(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %(uuid)s found : %(error)s") %
{'uuid': uuid, 'error': exc})
{'uuid': uuid, 'error': exc})
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(context, rp)
@ -293,7 +293,7 @@ def get_inventory(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %(uuid)s found : %(error)s") %
{'uuid': uuid, 'error': exc})
{'uuid': uuid, 'error': exc})
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(context, rp)
inventory = inv_list.find(resource_class)
@ -369,7 +369,7 @@ def set_inventories(req):
raise webob.exc.HTTPBadRequest(
_('Unable to update inventory for resource provider '
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
'error': exc})
'error': exc})
return _send_inventories(req, resource_provider, inventories)
@ -398,9 +398,9 @@ def delete_inventories(req):
raise webob.exc.HTTPConflict(
_('Unable to delete inventory for resource provider '
'%(rp_uuid)s because the inventory was updated by '
'another process. Please retry your request.')
% {'rp_uuid': resource_provider.uuid},
comment=errors.CONCURRENT_UPDATE)
'another process. Please retry your request.') %
{'rp_uuid': resource_provider.uuid},
comment=errors.CONCURRENT_UPDATE)
except exception.InventoryInUse as ex:
raise webob.exc.HTTPConflict(ex.format_message(),
comment=errors.INVENTORY_INUSE)
@ -460,6 +460,6 @@ def update_inventory(req):
raise webob.exc.HTTPBadRequest(
_('Unable to update inventory for resource provider '
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
'error': exc})
'error': exc})
return _send_inventory(req, resource_provider, inventory)

View File

@ -70,7 +70,7 @@ def _serialize_providers(environ, resource_providers, want_version):
provider_data = _serialize_provider(environ, provider, want_version)
output.append(provider_data)
last_modified = last_modified or timeutils.utcnow(with_timezone=True)
return ({"resource_providers": output}, last_modified)
return {"resource_providers": output}, last_modified
@wsgi_wrapper.PlacementWsgify
@ -106,8 +106,8 @@ def create_resource_provider(req):
# Whether exc.columns has one or two entries (in the event
# of both fields being duplicates) appears to be database
# dependent, so going with the complete solution here.
duplicate = ', '.join(['%s: %s' % (column, data[column])
for column in exc.columns])
duplicate = ', '.join(
['%s: %s' % (column, data[column]) for column in exc.columns])
raise webob.exc.HTTPConflict(
_('Conflicting resource provider %(duplicate)s already exists.') %
{'duplicate': duplicate},
@ -152,10 +152,10 @@ def delete_resource_provider(req):
_('Unable to delete resource provider %(rp_uuid)s: %(error)s') %
{'rp_uuid': uuid, 'error': exc},
comment=errors.PROVIDER_IN_USE)
except exception.NotFound as exc:
except exception.NotFound:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %s found for delete") % uuid)
except exception.CannotDeleteParentResourceProvider as exc:
except exception.CannotDeleteParentResourceProvider:
raise webob.exc.HTTPConflict(
_("Unable to delete parent resource provider %(rp_uuid)s: "
"It has child resource providers.") % {'rp_uuid': uuid},
@ -287,7 +287,7 @@ def update_resource_provider(req):
try:
resource_provider.save()
except db_exc.DBDuplicateEntry as exc:
except db_exc.DBDuplicateEntry:
raise webob.exc.HTTPConflict(
_('Conflicting resource provider %(name)s already exists.') %
{'name': data['name']},

View File

@ -192,7 +192,7 @@ def list_traits_for_resource_provider(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %(uuid)s found: %(error)s") %
{'uuid': uuid, 'error': exc})
{'uuid': uuid, 'error': exc})
traits = rp_obj.TraitList.get_all_by_resource_provider(context, rp)
response_body, last_modified = _serialize_traits(traits, want_version)

View File

@ -60,7 +60,7 @@ def list_usages(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %(uuid)s found: %(error)s") %
{'uuid': uuid, 'error': exc})
{'uuid': uuid, 'error': exc})
usage = usage_obj.get_all_by_resource_provider_uuid(context, uuid)

View File

@ -82,11 +82,11 @@ def ensure_consumer(ctx, consumer_uuid, project_id, user_id,
raise webob.exc.HTTPConflict(
_('consumer generation conflict - '
'expected %(expected_gen)s but got %(got_gen)s') %
{
'expected_gen': consumer.generation,
'got_gen': consumer_generation,
},
comment=errors.CONCURRENT_UPDATE)
{
'expected_gen': consumer.generation,
'got_gen': consumer_generation,
},
comment=errors.CONCURRENT_UPDATE)
# NOTE(jaypipes): The user may have specified a different project and
# user external ID than the one that we had for the consumer. If this
# is the case, go ahead and modify the consumer record with the

View File

@ -29,7 +29,7 @@ _QS_REQUIRED = 'required'
_QS_MEMBER_OF = 'member_of'
_QS_IN_TREE = 'in_tree'
_QS_KEY_PATTERN = re.compile(
r"^(%s)([1-9][0-9]*)?$" % '|'.join(
r"^(%s)([1-9][0-9]*)?$" % '|'.join(
(_QS_RESOURCES, _QS_REQUIRED, _QS_MEMBER_OF, _QS_IN_TREE)))
@ -144,8 +144,7 @@ class RequestGroup(object):
for suff, group in by_suffix.items():
forbidden = [trait for trait in group.required_traits
if trait.startswith('!')]
group.required_traits = (
group.required_traits - set(forbidden))
group.required_traits = group.required_traits - set(forbidden)
group.forbidden_traits = set([trait.lstrip('!') for trait in
forbidden])
conflicts = group.forbidden_traits & group.required_traits

View File

@ -121,23 +121,25 @@ def _check_capacity_exceeded(ctx, allocs):
# We then take the results of the above and determine if any of the
# inventory will have its capacity exceeded.
rc_ids = set([rc_cache.RC_CACHE.id_from_string(a.resource_class)
for a in allocs])
for a in allocs])
provider_uuids = set([a.resource_provider.uuid for a in allocs])
provider_ids = set([a.resource_provider.id for a in allocs])
usage = sa.select([_ALLOC_TBL.c.resource_provider_id,
_ALLOC_TBL.c.resource_class_id,
sql.func.sum(_ALLOC_TBL.c.used).label('used')])
usage = usage.where(
sa.and_(_ALLOC_TBL.c.resource_class_id.in_(rc_ids),
_ALLOC_TBL.c.resource_provider_id.in_(provider_ids)))
sa.and_(_ALLOC_TBL.c.resource_class_id.in_(rc_ids),
_ALLOC_TBL.c.resource_provider_id.in_(provider_ids)))
usage = usage.group_by(_ALLOC_TBL.c.resource_provider_id,
_ALLOC_TBL.c.resource_class_id)
usage = sa.alias(usage, name='usage')
inv_join = sql.join(_RP_TBL, _INV_TBL,
sql.and_(_RP_TBL.c.id == _INV_TBL.c.resource_provider_id,
_INV_TBL.c.resource_class_id.in_(rc_ids)))
primary_join = sql.outerjoin(inv_join, usage,
inv_join = sql.join(
_RP_TBL, _INV_TBL,
sql.and_(_RP_TBL.c.id == _INV_TBL.c.resource_provider_id,
_INV_TBL.c.resource_class_id.in_(rc_ids)))
primary_join = sql.outerjoin(
inv_join, usage,
sql.and_(
_INV_TBL.c.resource_provider_id == usage.c.resource_provider_id,
_INV_TBL.c.resource_class_id == usage.c.resource_class_id)
@ -158,8 +160,8 @@ def _check_capacity_exceeded(ctx, allocs):
sel = sa.select(cols_in_output).select_from(primary_join)
sel = sel.where(
sa.and_(_RP_TBL.c.id.in_(provider_ids),
_INV_TBL.c.resource_class_id.in_(rc_ids)))
sa.and_(_RP_TBL.c.id.in_(provider_ids),
_INV_TBL.c.resource_class_id.in_(rc_ids)))
records = ctx.session.execute(sel)
# Create a map keyed by (rp_uuid, res_class) for the records in the DB
usage_map = {}
@ -176,8 +178,8 @@ def _check_capacity_exceeded(ctx, allocs):
class_str = ', '.join([rc_cache.RC_CACHE.string_from_id(rc_id)
for rc_id in rc_ids])
provider_str = ', '.join(missing_provs)
raise exception.InvalidInventory(resource_class=class_str,
resource_provider=provider_str)
raise exception.InvalidInventory(
resource_class=class_str, resource_provider=provider_str)
res_providers = {}
rp_resource_class_sum = collections.defaultdict(
@ -198,8 +200,8 @@ def _check_capacity_exceeded(ctx, allocs):
except KeyError:
# The resource class at rc_id is not in the usage map.
raise exception.InvalidInventory(
resource_class=alloc.resource_class,
resource_provider=rp_uuid)
resource_class=alloc.resource_class,
resource_provider=rp_uuid)
allocation_ratio = usage['allocation_ratio']
min_unit = usage['min_unit']
max_unit = usage['max_unit']
@ -227,7 +229,7 @@ def _check_capacity_exceeded(ctx, allocs):
used = usage['used'] or 0
capacity = (usage['total'] - usage['reserved']) * allocation_ratio
if (capacity < (used + amount_needed) or
capacity < (used + rp_resource_class_sum[rp_uuid][rc_id])):
capacity < (used + rp_resource_class_sum[rp_uuid][rc_id])):
LOG.warning(
"Over capacity for %(rc)s on resource provider %(rp)s. "
"Needed: %(needed)s, Used: %(used)s, Capacity: %(cap)s",
@ -457,10 +459,10 @@ def _set_allocations(context, allocs):
rp = alloc.resource_provider
rc_id = rc_cache.RC_CACHE.id_from_string(alloc.resource_class)
ins_stmt = _ALLOC_TBL.insert().values(
resource_provider_id=rp.id,
resource_class_id=rc_id,
consumer_id=consumer_id,
used=alloc.used)
resource_provider_id=rp.id,
resource_class_id=rc_id,
consumer_id=consumer_id,
used=alloc.used)
res = context.session.execute(ins_stmt)
alloc.id = res.lastrowid

View File

@ -197,7 +197,7 @@ def _get_current_inventory_resources(ctx, rp):
:param rp: Resource provider to query inventory for.
"""
cur_res_sel = sa.select([_INV_TBL.c.resource_class_id]).where(
_INV_TBL.c.resource_provider_id == rp.id)
_INV_TBL.c.resource_provider_id == rp.id)
existing_resources = ctx.session.execute(cur_res_sel).fetchall()
return set([r[0] for r in existing_resources])
@ -216,10 +216,11 @@ def _delete_inventory_from_provider(ctx, rp, to_delete):
delete.
"""
allocation_query = sa.select(
[_ALLOC_TBL.c.resource_class_id.label('resource_class')]).where(
sa.and_(_ALLOC_TBL.c.resource_provider_id == rp.id,
_ALLOC_TBL.c.resource_class_id.in_(to_delete))
).group_by(_ALLOC_TBL.c.resource_class_id)
[_ALLOC_TBL.c.resource_class_id.label('resource_class')]
).where(
sa.and_(_ALLOC_TBL.c.resource_provider_id == rp.id,
_ALLOC_TBL.c.resource_class_id.in_(to_delete))
).group_by(_ALLOC_TBL.c.resource_class_id)
allocations = ctx.session.execute(allocation_query).fetchall()
if allocations:
resource_classes = ', '.join(
@ -228,7 +229,8 @@ def _delete_inventory_from_provider(ctx, rp, to_delete):
raise exception.InventoryInUse(resource_classes=resource_classes,
resource_provider=rp.uuid)
del_stmt = _INV_TBL.delete().where(sa.and_(
del_stmt = _INV_TBL.delete().where(
sa.and_(
_INV_TBL.c.resource_provider_id == rp.id,
_INV_TBL.c.resource_class_id.in_(to_delete)))
res = ctx.session.execute(del_stmt)
@ -249,14 +251,14 @@ def _add_inventory_to_provider(ctx, rp, inv_list, to_add):
rc_str = rc_cache.RC_CACHE.string_from_id(rc_id)
inv_record = inv_list.find(rc_str)
ins_stmt = _INV_TBL.insert().values(
resource_provider_id=rp.id,
resource_class_id=rc_id,
total=inv_record.total,
reserved=inv_record.reserved,
min_unit=inv_record.min_unit,
max_unit=inv_record.max_unit,
step_size=inv_record.step_size,
allocation_ratio=inv_record.allocation_ratio)
resource_provider_id=rp.id,
resource_class_id=rc_id,
total=inv_record.total,
reserved=inv_record.reserved,
min_unit=inv_record.min_unit,
max_unit=inv_record.max_unit,
step_size=inv_record.step_size,
allocation_ratio=inv_record.allocation_ratio)
ctx.session.execute(ins_stmt)
@ -282,23 +284,25 @@ def _update_inventory_for_provider(ctx, rp, inv_list, to_update):
_ALLOC_TBL.c.resource_provider_id == rp.id,
_ALLOC_TBL.c.resource_class_id == rc_id))
allocations = ctx.session.execute(allocation_query).first()
if (allocations
and allocations['usage'] is not None
and allocations['usage'] > inv_record.capacity):
if (allocations and
allocations['usage'] is not None and
allocations['usage'] > inv_record.capacity):
exceeded.append((rp.uuid, rc_str))
upd_stmt = _INV_TBL.update().where(sa.and_(
upd_stmt = _INV_TBL.update().where(
sa.and_(
_INV_TBL.c.resource_provider_id == rp.id,
_INV_TBL.c.resource_class_id == rc_id)).values(
total=inv_record.total,
reserved=inv_record.reserved,
min_unit=inv_record.min_unit,
max_unit=inv_record.max_unit,
step_size=inv_record.step_size,
allocation_ratio=inv_record.allocation_ratio)
_INV_TBL.c.resource_class_id == rc_id)
).values(
total=inv_record.total,
reserved=inv_record.reserved,
min_unit=inv_record.min_unit,
max_unit=inv_record.max_unit,
step_size=inv_record.step_size,
allocation_ratio=inv_record.allocation_ratio)
res = ctx.session.execute(upd_stmt)
if not res.rowcount:
raise exception.InventoryWithResourceClassNotFound(
resource_class=rc_str)
resource_class=rc_str)
return exceeded
@ -413,7 +417,8 @@ def _get_provider_by_uuid(context, uuid):
# TODO(jaypipes): Change this to an inner join when we are sure all
# root_provider_id values are NOT NULL
rp_to_root = sa.outerjoin(rpt, root, rpt.c.root_provider_id == root.c.id)
rp_to_parent = sa.outerjoin(rp_to_root, parent,
rp_to_parent = sa.outerjoin(
rp_to_root, parent,
rpt.c.parent_provider_id == parent.c.id)
cols = [
rpt.c.id,
@ -597,7 +602,8 @@ def _set_aggregates(context, resource_provider, provided_aggregates,
pass
for agg_id, agg_uuid in aggs_to_disassociate.items():
del_stmt = _RP_AGG_TBL.delete().where(sa.and_(
del_stmt = _RP_AGG_TBL.delete().where(
sa.and_(
_RP_AGG_TBL.c.resource_provider_id == rp_id,
_RP_AGG_TBL.c.aggregate_id == agg_id))
context.session.execute(del_stmt)
@ -786,7 +792,8 @@ def _provider_ids_from_rp_ids(context, rp_ids):
# TODO(jaypipes): Change this to an inner join when we are sure all
# root_provider_id values are NOT NULL
me_to_root = sa.outerjoin(me, root, me.c.root_provider_id == root.c.id)
me_to_parent = sa.outerjoin(me_to_root, parent,
me_to_parent = sa.outerjoin(
me_to_root, parent,
me.c.parent_provider_id == parent.c.id)
sel = sa.select(cols).select_from(me_to_parent)
sel = sel.where(me.c.id.in_(rp_ids))
@ -837,7 +844,8 @@ def _provider_ids_from_uuid(context, uuid):
# TODO(jaypipes): Change this to an inner join when we are sure all
# root_provider_id values are NOT NULL
me_to_root = sa.outerjoin(me, root, me.c.root_provider_id == root.c.id)
me_to_parent = sa.outerjoin(me_to_root, parent,
me_to_parent = sa.outerjoin(
me_to_root, parent,
me.c.parent_provider_id == parent.c.id)
sel = sa.select(cols).select_from(me_to_parent)
sel = sel.where(me.c.uuid == uuid)
@ -1094,16 +1102,16 @@ class ResourceProvider(object):
# Setting parent to ourselves doesn't make any sense
if parent_uuid == self.uuid:
raise exception.ObjectActionError(
action='create',
reason=_('parent provider UUID cannot be same as '
'UUID. Please set parent provider UUID to '
'None if there is no parent.'))
action='create',
reason=_('parent provider UUID cannot be same as UUID. '
'Please set parent provider UUID to None if '
'there is no parent.'))
parent_ids = _provider_ids_from_uuid(context, parent_uuid)
if parent_ids is None:
raise exception.ObjectActionError(
action='create',
reason=_('parent provider UUID does not exist.'))
action='create',
reason=_('parent provider UUID does not exist.'))
parent_id = parent_ids.id
root_id = parent_ids.root_id
@ -1140,9 +1148,8 @@ class ResourceProvider(object):
raise exception.CannotDeleteParentResourceProvider()
# Don't delete the resource provider if it has allocations.
rp_allocations = context.session.query(models.Allocation).\
filter(models.Allocation.resource_provider_id == _id).\
count()
rp_allocations = context.session.query(models.Allocation).filter(
models.Allocation.resource_provider_id == _id).count()
if rp_allocations:
raise exception.ResourceProviderInUse()
# Delete any inventory associated with the resource provider
@ -1152,12 +1159,12 @@ class ResourceProvider(object):
# Delete any aggregate associations for the resource provider
# The name substitution on the next line is needed to satisfy pep8
RPA_model = models.ResourceProviderAggregate
context.session.query(RPA_model).\
filter(RPA_model.resource_provider_id == _id).delete()
context.session.query(RPA_model).filter(
RPA_model.resource_provider_id == _id).delete()
# delete any trait associations for the resource provider
RPT_model = models.ResourceProviderTrait
context.session.query(RPT_model).\
filter(RPT_model.resource_provider_id == _id).delete()
context.session.query(RPT_model).filter(
RPT_model.resource_provider_id == _id).delete()
# set root_provider_id to null to make deletion possible
context.session.query(models.ResourceProvider).\
filter(models.ResourceProvider.id == _id,
@ -1197,14 +1204,14 @@ class ResourceProvider(object):
# User supplied a parent, let's make sure it exists
if parent_ids is None:
raise exception.ObjectActionError(
action='create',
reason=_('parent provider UUID does not exist.'))
action='create',
reason=_('parent provider UUID does not exist.'))
if (my_ids.parent_id is not None and
my_ids.parent_id != parent_ids.id):
raise exception.ObjectActionError(
action='update',
reason=_('re-parenting a provider is not '
'currently allowed.'))
action='update',
reason=_('re-parenting a provider is not currently '
'allowed.'))
if my_ids.parent_uuid is None:
# So the user specifies a parent for an RP that doesn't
# have one. We have to check that by this new parent we
@ -1229,9 +1236,9 @@ class ResourceProvider(object):
else:
if my_ids.parent_id is not None:
raise exception.ObjectActionError(
action='update',
reason=_('un-parenting a provider is not '
'currently allowed.'))
action='update',
reason=_('un-parenting a provider is not currently '
'allowed.'))
db_rp = context.session.query(models.ResourceProvider).filter_by(
id=id).first()
@ -1259,8 +1266,8 @@ class ResourceProvider(object):
# for this resource provider in between the above check for a valid
# parent provider and here...
raise exception.ObjectActionError(
action='update',
reason=_('parent provider UUID does not exist.'))
action='update',
reason=_('parent provider UUID does not exist.'))
@staticmethod
@db_api.placement_context_manager.writer # For online data migration
@ -1462,9 +1469,11 @@ class ResourceProviderList(common_obj.ObjectList):
# TODO(jaypipes): Convert this to an inner join once all
# root_provider_id values are NOT NULL
rp_to_root = sa.outerjoin(rp, root_rp,
rp_to_root = sa.outerjoin(
rp, root_rp,
rp.c.root_provider_id == root_rp.c.id)
rp_to_parent = sa.outerjoin(rp_to_root, parent_rp,
rp_to_parent = sa.outerjoin(
rp_to_root, parent_rp,
rp.c.parent_provider_id == parent_rp.c.id)
query = sa.select(cols).select_from(rp_to_parent)
@ -1490,7 +1499,8 @@ class ResourceProviderList(common_obj.ObjectList):
# TODO(jaypipes): Remove this OR condition when root_provider_id
# is not nullable in the database and all resource provider records
# have populated the root provider ID.
where_cond = sa.or_(rp.c.id == root_id,
where_cond = sa.or_(
rp.c.id == root_id,
rp.c.root_provider_id == root_id)
query = query.where(where_cond)
@ -1549,13 +1559,15 @@ class ResourceProviderList(common_obj.ObjectList):
# comes from the above filters
# First JOIN between inventories and RPs is here
inv_join = sa.join(rp_to_parent, _INV_TBL,
inv_join = sa.join(
rp_to_parent,
_INV_TBL,
rp.c.id == _INV_TBL.c.resource_provider_id)
# Now, below is the LEFT JOIN for getting the allocations usage
usage = _usage_select(list(resources))
usage_join = sa.outerjoin(inv_join, usage,
sa.and_(
usage_join = sa.outerjoin(
inv_join, usage, sa.and_(
usage.c.resource_provider_id == (
_INV_TBL.c.resource_provider_id),
usage.c.resource_class_id == _INV_TBL.c.resource_class_id))
@ -1810,7 +1822,7 @@ class ResourceClass(object):
# Never delete any standard resource class.
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
raise exception.ResourceClassCannotDeleteStandard(
resource_class=self.name)
resource_class=self.name)
self._destroy(self._context, self.id, self.name)
rc_cache.RC_CACHE.clear()
@ -1821,12 +1833,12 @@ class ResourceClass(object):
# Don't delete the resource class if it is referred to in the
# inventories table.
num_inv = context.session.query(models.Inventory).filter(
models.Inventory.resource_class_id == _id).count()
models.Inventory.resource_class_id == _id).count()
if num_inv:
raise exception.ResourceClassInUse(resource_class=name)
res = context.session.query(models.ResourceClass).filter(
models.ResourceClass.id == _id).delete()
models.ResourceClass.id == _id).delete()
if not res:
raise exception.NotFound()
@ -1842,7 +1854,7 @@ class ResourceClass(object):
# Never update any standard resource class.
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
raise exception.ResourceClassCannotUpdateStandard(
resource_class=self.name)
resource_class=self.name)
self._save(self._context, self.id, self.name, updates)
rc_cache.RC_CACHE.clear()
@ -1986,11 +1998,13 @@ class TraitList(common_obj.ObjectList):
models.Trait.name.like(six.text_type(filters['prefix'] + '%')))
if 'associated' in filters:
if filters['associated']:
query = query.join(models.ResourceProviderTrait,
query = query.join(
models.ResourceProviderTrait,
models.Trait.id == models.ResourceProviderTrait.trait_id
).distinct()
else:
query = query.outerjoin(models.ResourceProviderTrait,
query = query.outerjoin(
models.ResourceProviderTrait,
models.Trait.id == models.ResourceProviderTrait.trait_id
).filter(models.ResourceProviderTrait.trait_id == null())
@ -2019,9 +2033,9 @@ class AllocationRequestResource(object):
self.amount = amount
def __eq__(self, other):
return (self.resource_provider.id == other.resource_provider.id) and (
self.resource_class == other.resource_class) and (
self.amount == other.amount)
return ((self.resource_provider.id == other.resource_provider.id) and
(self.resource_class == other.resource_class) and
(self.amount == other.amount))
def __hash__(self):
return hash((self.resource_provider.id,
@ -2302,7 +2316,7 @@ def _get_provider_ids_for_traits_and_aggs(ctx, required_traits,
@db_api.placement_context_manager.reader
def _get_provider_ids_matching(ctx, resources, required_traits,
forbidden_traits, member_of, tree_root_id):
forbidden_traits, member_of, tree_root_id):
"""Returns a list of tuples of (internal provider ID, root provider ID)
that have available inventory to satisfy all the supplied requests for
resources. If no providers match, the empty list is returned.
@ -2637,21 +2651,23 @@ def _get_trees_matching_all(ctx, resources, required_traits, forbidden_traits,
# process if tree_root_id is provided via the ?in_tree=<rp_uuid>
# queryparam, because it restricts resources from another tree.
rc_provs_with_inv = _anchors_for_sharing_providers(
ctx, sharing_providers, get_id=True)
ctx, sharing_providers, get_id=True)
provs_with_inv_rc.add_rps(rc_provs_with_inv, rc_id)