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:
parent
d158cbc8a4
commit
849c89d0e5
@ -79,7 +79,7 @@ html_theme = 'openstackdocs'
|
|||||||
# further. For a list of options available for each theme, see the
|
# further. For a list of options available for each theme, see the
|
||||||
# documentation.
|
# documentation.
|
||||||
html_theme_options = {
|
html_theme_options = {
|
||||||
"sidebar_mode": "toc",
|
"sidebar_mode": "toc",
|
||||||
}
|
}
|
||||||
|
|
||||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||||
|
@ -15,14 +15,16 @@
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
api_group = cfg.OptGroup('api',
|
api_group = cfg.OptGroup(
|
||||||
|
'api',
|
||||||
title='API options',
|
title='API options',
|
||||||
help="""
|
help="""
|
||||||
Options under this group are used to define Placement API.
|
Options under this group are used to define Placement API.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
api_opts = [
|
api_opts = [
|
||||||
cfg.StrOpt("auth_strategy",
|
cfg.StrOpt(
|
||||||
|
"auth_strategy",
|
||||||
default="keystone",
|
default="keystone",
|
||||||
choices=("keystone", "noauth2"),
|
choices=("keystone", "noauth2"),
|
||||||
deprecated_group="DEFAULT",
|
deprecated_group="DEFAULT",
|
||||||
|
@ -21,9 +21,10 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
|
|
||||||
ALL_OPTS = [
|
ALL_OPTS = [
|
||||||
cfg.StrOpt('pybasedir',
|
cfg.StrOpt(
|
||||||
default=os.path.abspath(os.path.join(os.path.dirname(__file__),
|
'pybasedir',
|
||||||
'../../')),
|
default=os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(__file__), '../../')),
|
||||||
sample_default='<Path>',
|
sample_default='<Path>',
|
||||||
help="""
|
help="""
|
||||||
The directory where the Placement python modules are installed.
|
The directory where the Placement python modules are installed.
|
||||||
@ -40,7 +41,8 @@ Related options:
|
|||||||
|
|
||||||
* ``state_path``
|
* ``state_path``
|
||||||
"""),
|
"""),
|
||||||
cfg.StrOpt('state_path',
|
cfg.StrOpt(
|
||||||
|
'state_path',
|
||||||
default='$pybasedir',
|
default='$pybasedir',
|
||||||
help="""
|
help="""
|
||||||
The top-level directory for maintaining state used in Placement.
|
The top-level directory for maintaining state used in Placement.
|
||||||
|
@ -30,159 +30,183 @@ depends_on = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.create_table('allocations',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'allocations',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('consumer_id', sa.String(length=36), nullable=False),
|
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
||||||
sa.Column('resource_class_id', sa.Integer(), nullable=False),
|
sa.Column('consumer_id', sa.String(length=36), nullable=False),
|
||||||
sa.Column('used', sa.Integer(), nullable=False),
|
sa.Column('resource_class_id', sa.Integer(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
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',
|
op.create_index(
|
||||||
'used'], unique=False)
|
'allocations_resource_provider_class_used_idx', 'allocations',
|
||||||
op.create_index('allocations_resource_class_id_idx', 'allocations',
|
['resource_provider_id', 'resource_class_id', 'used'], unique=False)
|
||||||
['resource_class_id'], unique=False)
|
op.create_index(
|
||||||
op.create_index('allocations_consumer_id_idx', 'allocations',
|
'allocations_resource_class_id_idx', 'allocations',
|
||||||
['consumer_id'], unique=False)
|
['resource_class_id'], unique=False)
|
||||||
|
op.create_index(
|
||||||
|
'allocations_consumer_id_idx', 'allocations', ['consumer_id'],
|
||||||
|
unique=False)
|
||||||
|
|
||||||
op.create_table('consumers',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'consumers',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('uuid', sa.String(length=36), nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.Column('project_id', sa.Integer(), nullable=False),
|
sa.Column('uuid', sa.String(length=36), nullable=False),
|
||||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
sa.Column('project_id', sa.Integer(), nullable=False),
|
||||||
sa.Column('generation', sa.Integer(), server_default=sa.text('0'),
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||||
nullable=False),
|
sa.Column('generation', sa.Integer(), server_default=sa.text('0'),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
nullable=False),
|
||||||
sa.UniqueConstraint('uuid', name='uniq_consumers0uuid'),
|
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(
|
||||||
op.create_index('consumers_project_id_uuid_idx', 'consumers',
|
'consumers_project_id_user_id_uuid_idx', 'consumers',
|
||||||
['project_id', 'uuid'], unique=False)
|
['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',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'inventories',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('resource_class_id', sa.Integer(), nullable=False),
|
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
||||||
sa.Column('total', sa.Integer(), nullable=False),
|
sa.Column('resource_class_id', sa.Integer(), nullable=False),
|
||||||
sa.Column('reserved', sa.Integer(), nullable=False),
|
sa.Column('total', sa.Integer(), nullable=False),
|
||||||
sa.Column('min_unit', sa.Integer(), nullable=False),
|
sa.Column('reserved', sa.Integer(), nullable=False),
|
||||||
sa.Column('max_unit', sa.Integer(), nullable=False),
|
sa.Column('min_unit', sa.Integer(), nullable=False),
|
||||||
sa.Column('step_size', sa.Integer(), nullable=False),
|
sa.Column('max_unit', sa.Integer(), nullable=False),
|
||||||
sa.Column('allocation_ratio', sa.Float(), nullable=False),
|
sa.Column('step_size', sa.Integer(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('allocation_ratio', sa.Float(), nullable=False),
|
||||||
sa.UniqueConstraint('resource_provider_id', 'resource_class_id',
|
sa.PrimaryKeyConstraint('id'),
|
||||||
name='uniq_inventories0resource_provider_resource_class'),
|
sa.UniqueConstraint(
|
||||||
)
|
'resource_provider_id', 'resource_class_id',
|
||||||
op.create_index('inventories_resource_class_id_idx', 'inventories',
|
name='uniq_inventories0resource_provider_resource_class'),
|
||||||
['resource_class_id'], unique=False)
|
)
|
||||||
op.create_index('inventories_resource_provider_id_idx', 'inventories',
|
op.create_index(
|
||||||
['resource_provider_id'], unique=False)
|
'inventories_resource_class_id_idx', 'inventories',
|
||||||
op.create_index('inventories_resource_provider_resource_class_idx',
|
['resource_class_id'], unique=False)
|
||||||
'inventories', ['resource_provider_id', 'resource_class_id'],
|
op.create_index(
|
||||||
unique=False)
|
'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',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'placement_aggregates',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('uuid', sa.String(length=36), nullable=True),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('uuid', sa.String(length=36), nullable=True),
|
||||||
sa.UniqueConstraint('uuid', name='uniq_placement_aggregates0uuid')
|
sa.PrimaryKeyConstraint('id'),
|
||||||
)
|
sa.UniqueConstraint('uuid', name='uniq_placement_aggregates0uuid')
|
||||||
|
)
|
||||||
op.create_index(op.f('ix_placement_aggregates_uuid'),
|
op.create_index(op.f('ix_placement_aggregates_uuid'),
|
||||||
'placement_aggregates', ['uuid'], unique=False)
|
'placement_aggregates', ['uuid'], unique=False)
|
||||||
|
|
||||||
op.create_table('projects',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'projects',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('external_id', sa.String(length=255), nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('external_id', sa.String(length=255), nullable=False),
|
||||||
sa.UniqueConstraint('external_id',
|
sa.PrimaryKeyConstraint('id'),
|
||||||
name='uniq_projects0external_id'),
|
sa.UniqueConstraint('external_id', name='uniq_projects0external_id'),
|
||||||
)
|
)
|
||||||
|
|
||||||
op.create_table('resource_classes',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'resource_classes',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('name', sa.String(length=255), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('name', sa.String(length=255), nullable=False),
|
||||||
sa.UniqueConstraint('name', name='uniq_resource_classes0name'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
)
|
sa.UniqueConstraint('name', name='uniq_resource_classes0name'),
|
||||||
|
)
|
||||||
|
|
||||||
op.create_table('resource_provider_aggregates',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'resource_provider_aggregates',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('aggregate_id', sa.Integer(), nullable=False),
|
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('resource_provider_id', 'aggregate_id'),
|
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_index(
|
||||||
|
'resource_provider_aggregates_aggregate_id_idx',
|
||||||
|
'resource_provider_aggregates', ['aggregate_id'], unique=False)
|
||||||
|
|
||||||
op.create_table('resource_providers',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'resource_providers',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('uuid', sa.String(length=36), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('name', sa.Unicode(length=200), nullable=True),
|
sa.Column('uuid', sa.String(length=36), nullable=False),
|
||||||
sa.Column('generation', sa.Integer(), nullable=True),
|
sa.Column('name', sa.Unicode(length=200), nullable=True),
|
||||||
sa.Column('root_provider_id', sa.Integer(), nullable=True),
|
sa.Column('generation', sa.Integer(), nullable=True),
|
||||||
sa.Column('parent_provider_id', sa.Integer(), nullable=True),
|
sa.Column('root_provider_id', sa.Integer(), nullable=True),
|
||||||
sa.ForeignKeyConstraint(['parent_provider_id'],
|
sa.Column('parent_provider_id', sa.Integer(), nullable=True),
|
||||||
['resource_providers.id']),
|
sa.ForeignKeyConstraint(['parent_provider_id'],
|
||||||
sa.ForeignKeyConstraint(['root_provider_id'],
|
['resource_providers.id']),
|
||||||
['resource_providers.id']),
|
sa.ForeignKeyConstraint(['root_provider_id'],
|
||||||
sa.PrimaryKeyConstraint('id'),
|
['resource_providers.id']),
|
||||||
sa.UniqueConstraint('name', name='uniq_resource_providers0name'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
sa.UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
|
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(
|
||||||
op.create_index('resource_providers_parent_provider_id_idx',
|
'resource_providers_name_idx', 'resource_providers', ['name'],
|
||||||
'resource_providers', ['parent_provider_id'], unique=False)
|
unique=False)
|
||||||
op.create_index('resource_providers_root_provider_id_idx',
|
op.create_index(
|
||||||
'resource_providers', ['root_provider_id'], unique=False)
|
'resource_providers_parent_provider_id_idx', 'resource_providers',
|
||||||
op.create_index('resource_providers_uuid_idx', 'resource_providers',
|
['parent_provider_id'], unique=False)
|
||||||
['uuid'], 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',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'traits',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('name', sa.Unicode(length=255), nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('name', sa.Unicode(length=255), nullable=False),
|
||||||
sa.UniqueConstraint('name', name='uniq_traits0name'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
)
|
sa.UniqueConstraint('name', name='uniq_traits0name'),
|
||||||
|
)
|
||||||
|
|
||||||
op.create_table('users',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'users',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('external_id', sa.String(length=255), nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.Column('external_id', sa.String(length=255), nullable=False),
|
||||||
sa.UniqueConstraint('external_id', name='uniq_users0external_id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
)
|
sa.UniqueConstraint('external_id', name='uniq_users0external_id'),
|
||||||
|
)
|
||||||
|
|
||||||
op.create_table('resource_provider_traits',
|
op.create_table(
|
||||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
'resource_provider_traits',
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('trait_id', sa.Integer(), nullable=False),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
sa.Column('trait_id', sa.Integer(), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['resource_provider_id'],
|
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
|
||||||
['resource_providers.id'], ),
|
sa.ForeignKeyConstraint(['resource_provider_id'],
|
||||||
sa.ForeignKeyConstraint(['trait_id'], ['traits.id'], ),
|
['resource_providers.id'], ),
|
||||||
sa.PrimaryKeyConstraint('trait_id', 'resource_provider_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'],
|
op.create_index(
|
||||||
unique=False)
|
'resource_provider_traits_resource_provider_trait_idx',
|
||||||
|
'resource_provider_traits', ['resource_provider_id', 'trait_id'],
|
||||||
|
unique=False)
|
||||||
|
@ -51,15 +51,13 @@ class ResourceProvider(BASE):
|
|||||||
__tablename__ = "resource_providers"
|
__tablename__ = "resource_providers"
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
Index('resource_providers_uuid_idx', 'uuid'),
|
Index('resource_providers_uuid_idx', 'uuid'),
|
||||||
schema.UniqueConstraint('uuid',
|
schema.UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
|
||||||
name='uniq_resource_providers0uuid'),
|
|
||||||
Index('resource_providers_name_idx', 'name'),
|
Index('resource_providers_name_idx', 'name'),
|
||||||
Index('resource_providers_root_provider_id_idx',
|
Index('resource_providers_root_provider_id_idx',
|
||||||
'root_provider_id'),
|
'root_provider_id'),
|
||||||
Index('resource_providers_parent_provider_id_idx',
|
Index('resource_providers_parent_provider_id_idx',
|
||||||
'parent_provider_id'),
|
'parent_provider_id'),
|
||||||
schema.UniqueConstraint('name',
|
schema.UniqueConstraint('name', name='uniq_resource_providers0name')
|
||||||
name='uniq_resource_providers0name')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, nullable=False)
|
id = Column(Integer, primary_key=True, nullable=False)
|
||||||
@ -67,12 +65,12 @@ class ResourceProvider(BASE):
|
|||||||
name = Column(Unicode(200), nullable=True)
|
name = Column(Unicode(200), nullable=True)
|
||||||
generation = Column(Integer, default=0)
|
generation = Column(Integer, default=0)
|
||||||
# Represents the root of the "tree" that the provider belongs to
|
# Represents the root of the "tree" that the provider belongs to
|
||||||
root_provider_id = Column(Integer, ForeignKey('resource_providers.id'),
|
root_provider_id = Column(
|
||||||
nullable=True)
|
Integer, ForeignKey('resource_providers.id'), nullable=True)
|
||||||
# The immediate parent provider of this provider, or NULL if there is no
|
# 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. If parent_provider_id == NULL then root_provider_id == id
|
||||||
parent_provider_id = Column(Integer, ForeignKey('resource_providers.id'),
|
parent_provider_id = Column(
|
||||||
nullable=True)
|
Integer, ForeignKey('resource_providers.id'), nullable=True)
|
||||||
|
|
||||||
|
|
||||||
class Inventory(BASE):
|
class Inventory(BASE):
|
||||||
@ -86,7 +84,8 @@ class Inventory(BASE):
|
|||||||
'resource_class_id'),
|
'resource_class_id'),
|
||||||
Index('inventories_resource_provider_resource_class_idx',
|
Index('inventories_resource_provider_resource_class_idx',
|
||||||
'resource_provider_id', 'resource_class_id'),
|
'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')
|
name='uniq_inventories0resource_provider_resource_class')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ class PlacementDirect(interceptor.RequestsInterceptor):
|
|||||||
# TODO(efried): Figure out why this isn't working:
|
# TODO(efried): Figure out why this isn't working:
|
||||||
# default_microversion='latest' if latest_microversion else None)
|
# default_microversion='latest' if latest_microversion else None)
|
||||||
self._mocked_endpoint = mock.patch(
|
self._mocked_endpoint = mock.patch(
|
||||||
'keystoneauth1.session.Session.get_endpoint',
|
'keystoneauth1.session.Session.get_endpoint',
|
||||||
new=mock.Mock(return_value=self.url))
|
new=mock.Mock(return_value=self.url))
|
||||||
super(PlacementDirect, self).__init__(app, url=self.url)
|
super(PlacementDirect, self).__init__(app, url=self.url)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
@ -206,8 +206,8 @@ class PlacementHandler(object):
|
|||||||
try:
|
try:
|
||||||
if clen and (int(clen) > 0) and not environ.get('CONTENT_TYPE'):
|
if clen and (int(clen) > 0) and not environ.get('CONTENT_TYPE'):
|
||||||
raise webob.exc.HTTPBadRequest(
|
raise webob.exc.HTTPBadRequest(
|
||||||
_('content-type header required when content-length > 0'),
|
_('content-type header required when content-length > 0'),
|
||||||
json_formatter=util.json_error_formatter)
|
json_formatter=util.json_error_formatter)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise webob.exc.HTTPBadRequest(
|
raise webob.exc.HTTPBadRequest(
|
||||||
_('content-length header must be an integer'),
|
_('content-length header must be an integer'),
|
||||||
|
@ -409,9 +409,9 @@ def _set_allocations_for_consumer(req, schema):
|
|||||||
# NOTE(jaypipes): This will only occur 1.28+. The JSONSchema will
|
# NOTE(jaypipes): This will only occur 1.28+. The JSONSchema will
|
||||||
# prevent an empty allocations object from being passed when there is
|
# prevent an empty allocations object from being passed when there is
|
||||||
# no consumer generation, so this is safe to do.
|
# no consumer generation, so this is safe to do.
|
||||||
data_util.ensure_consumer(context, consumer_uuid,
|
data_util.ensure_consumer(
|
||||||
data.get('project_id'), data.get('user_id'),
|
context, consumer_uuid, data.get('project_id'),
|
||||||
data.get('consumer_generation'), want_version)
|
data.get('user_id'), data.get('consumer_generation'), want_version)
|
||||||
allocations = alloc_obj.get_all_by_consumer_id(context, consumer_uuid)
|
allocations = alloc_obj.get_all_by_consumer_id(context, consumer_uuid)
|
||||||
for allocation in allocations:
|
for allocation in allocations:
|
||||||
allocation.used = 0
|
allocation.used = 0
|
||||||
@ -448,9 +448,8 @@ def _set_allocations_for_consumer(req, schema):
|
|||||||
# capacity limits have been exceeded.
|
# capacity limits have been exceeded.
|
||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPBadRequest(
|
raise webob.exc.HTTPBadRequest(
|
||||||
_("Unable to allocate inventory for consumer "
|
_("Unable to allocate inventory for consumer %(consumer_uuid)s: "
|
||||||
"%(consumer_uuid)s: %(error)s") %
|
"%(error)s") % {'consumer_uuid': consumer_uuid, 'error': exc})
|
||||||
{'consumer_uuid': consumer_uuid, 'error': exc})
|
|
||||||
except exception.InvalidInventory as exc:
|
except exception.InvalidInventory as exc:
|
||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Unable to allocate inventory: %(error)s') % {'error': exc})
|
_('Unable to allocate inventory: %(error)s') % {'error': exc})
|
||||||
@ -458,7 +457,7 @@ def _set_allocations_for_consumer(req, schema):
|
|||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Inventory and/or allocations changed while attempting to '
|
_('Inventory and/or allocations changed while attempting to '
|
||||||
'allocate: %(error)s') % {'error': exc},
|
'allocate: %(error)s') % {'error': exc},
|
||||||
comment=errors.CONCURRENT_UPDATE)
|
comment=errors.CONCURRENT_UPDATE)
|
||||||
|
|
||||||
req.response.status = 204
|
req.response.status = 204
|
||||||
req.response.content_type = None
|
req.response.content_type = None
|
||||||
@ -536,7 +535,7 @@ def set_allocations(req):
|
|||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Inventory and/or allocations changed while attempting to '
|
_('Inventory and/or allocations changed while attempting to '
|
||||||
'allocate: %(error)s') % {'error': exc},
|
'allocate: %(error)s') % {'error': exc},
|
||||||
comment=errors.CONCURRENT_UPDATE)
|
comment=errors.CONCURRENT_UPDATE)
|
||||||
|
|
||||||
req.response.status = 204
|
req.response.status = 204
|
||||||
req.response.content_type = None
|
req.response.content_type = None
|
||||||
@ -558,9 +557,9 @@ def delete_allocations(req):
|
|||||||
# activity. In that case, delete_all() will throw a NotFound exception.
|
# activity. In that case, delete_all() will throw a NotFound exception.
|
||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("Allocation for consumer with id %(id)s not found."
|
_("Allocation for consumer with id %(id)s not found. error: "
|
||||||
"error: %(error)s") %
|
"%(error)s") %
|
||||||
{'id': consumer_uuid, 'error': exc})
|
{'id': consumer_uuid, 'error': exc})
|
||||||
else:
|
else:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No allocations for consumer '%(consumer_uuid)s'") %
|
_("No allocations for consumer '%(consumer_uuid)s'") %
|
||||||
|
@ -245,7 +245,7 @@ def delete_inventory(req):
|
|||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_('No inventory of class %(class)s found for delete: %(error)s') %
|
_('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 = req.response
|
||||||
response.status = 204
|
response.status = 204
|
||||||
@ -269,7 +269,7 @@ def get_inventories(req):
|
|||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No resource provider with uuid %(uuid)s found : %(error)s") %
|
_("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)
|
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:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No resource provider with uuid %(uuid)s found : %(error)s") %
|
_("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)
|
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(context, rp)
|
||||||
inventory = inv_list.find(resource_class)
|
inventory = inv_list.find(resource_class)
|
||||||
@ -369,7 +369,7 @@ def set_inventories(req):
|
|||||||
raise webob.exc.HTTPBadRequest(
|
raise webob.exc.HTTPBadRequest(
|
||||||
_('Unable to update inventory for resource provider '
|
_('Unable to update inventory for resource provider '
|
||||||
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
|
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
|
||||||
'error': exc})
|
'error': exc})
|
||||||
|
|
||||||
return _send_inventories(req, resource_provider, inventories)
|
return _send_inventories(req, resource_provider, inventories)
|
||||||
|
|
||||||
@ -398,9 +398,9 @@ def delete_inventories(req):
|
|||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Unable to delete inventory for resource provider '
|
_('Unable to delete inventory for resource provider '
|
||||||
'%(rp_uuid)s because the inventory was updated by '
|
'%(rp_uuid)s because the inventory was updated by '
|
||||||
'another process. Please retry your request.')
|
'another process. Please retry your request.') %
|
||||||
% {'rp_uuid': resource_provider.uuid},
|
{'rp_uuid': resource_provider.uuid},
|
||||||
comment=errors.CONCURRENT_UPDATE)
|
comment=errors.CONCURRENT_UPDATE)
|
||||||
except exception.InventoryInUse as ex:
|
except exception.InventoryInUse as ex:
|
||||||
raise webob.exc.HTTPConflict(ex.format_message(),
|
raise webob.exc.HTTPConflict(ex.format_message(),
|
||||||
comment=errors.INVENTORY_INUSE)
|
comment=errors.INVENTORY_INUSE)
|
||||||
@ -460,6 +460,6 @@ def update_inventory(req):
|
|||||||
raise webob.exc.HTTPBadRequest(
|
raise webob.exc.HTTPBadRequest(
|
||||||
_('Unable to update inventory for resource provider '
|
_('Unable to update inventory for resource provider '
|
||||||
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
|
'%(rp_uuid)s: %(error)s') % {'rp_uuid': resource_provider.uuid,
|
||||||
'error': exc})
|
'error': exc})
|
||||||
|
|
||||||
return _send_inventory(req, resource_provider, inventory)
|
return _send_inventory(req, resource_provider, inventory)
|
||||||
|
@ -70,7 +70,7 @@ def _serialize_providers(environ, resource_providers, want_version):
|
|||||||
provider_data = _serialize_provider(environ, provider, want_version)
|
provider_data = _serialize_provider(environ, provider, want_version)
|
||||||
output.append(provider_data)
|
output.append(provider_data)
|
||||||
last_modified = last_modified or timeutils.utcnow(with_timezone=True)
|
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
|
@wsgi_wrapper.PlacementWsgify
|
||||||
@ -106,8 +106,8 @@ def create_resource_provider(req):
|
|||||||
# Whether exc.columns has one or two entries (in the event
|
# Whether exc.columns has one or two entries (in the event
|
||||||
# of both fields being duplicates) appears to be database
|
# of both fields being duplicates) appears to be database
|
||||||
# dependent, so going with the complete solution here.
|
# dependent, so going with the complete solution here.
|
||||||
duplicate = ', '.join(['%s: %s' % (column, data[column])
|
duplicate = ', '.join(
|
||||||
for column in exc.columns])
|
['%s: %s' % (column, data[column]) for column in exc.columns])
|
||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Conflicting resource provider %(duplicate)s already exists.') %
|
_('Conflicting resource provider %(duplicate)s already exists.') %
|
||||||
{'duplicate': duplicate},
|
{'duplicate': duplicate},
|
||||||
@ -152,10 +152,10 @@ def delete_resource_provider(req):
|
|||||||
_('Unable to delete resource provider %(rp_uuid)s: %(error)s') %
|
_('Unable to delete resource provider %(rp_uuid)s: %(error)s') %
|
||||||
{'rp_uuid': uuid, 'error': exc},
|
{'rp_uuid': uuid, 'error': exc},
|
||||||
comment=errors.PROVIDER_IN_USE)
|
comment=errors.PROVIDER_IN_USE)
|
||||||
except exception.NotFound as exc:
|
except exception.NotFound:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No resource provider with uuid %s found for delete") % uuid)
|
_("No resource provider with uuid %s found for delete") % uuid)
|
||||||
except exception.CannotDeleteParentResourceProvider as exc:
|
except exception.CannotDeleteParentResourceProvider:
|
||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_("Unable to delete parent resource provider %(rp_uuid)s: "
|
_("Unable to delete parent resource provider %(rp_uuid)s: "
|
||||||
"It has child resource providers.") % {'rp_uuid': uuid},
|
"It has child resource providers.") % {'rp_uuid': uuid},
|
||||||
@ -287,7 +287,7 @@ def update_resource_provider(req):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
resource_provider.save()
|
resource_provider.save()
|
||||||
except db_exc.DBDuplicateEntry as exc:
|
except db_exc.DBDuplicateEntry:
|
||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('Conflicting resource provider %(name)s already exists.') %
|
_('Conflicting resource provider %(name)s already exists.') %
|
||||||
{'name': data['name']},
|
{'name': data['name']},
|
||||||
|
@ -192,7 +192,7 @@ def list_traits_for_resource_provider(req):
|
|||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No resource provider with uuid %(uuid)s found: %(error)s") %
|
_("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)
|
traits = rp_obj.TraitList.get_all_by_resource_provider(context, rp)
|
||||||
response_body, last_modified = _serialize_traits(traits, want_version)
|
response_body, last_modified = _serialize_traits(traits, want_version)
|
||||||
|
@ -60,7 +60,7 @@ def list_usages(req):
|
|||||||
except exception.NotFound as exc:
|
except exception.NotFound as exc:
|
||||||
raise webob.exc.HTTPNotFound(
|
raise webob.exc.HTTPNotFound(
|
||||||
_("No resource provider with uuid %(uuid)s found: %(error)s") %
|
_("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)
|
usage = usage_obj.get_all_by_resource_provider_uuid(context, uuid)
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ def ensure_consumer(ctx, consumer_uuid, project_id, user_id,
|
|||||||
raise webob.exc.HTTPConflict(
|
raise webob.exc.HTTPConflict(
|
||||||
_('consumer generation conflict - '
|
_('consumer generation conflict - '
|
||||||
'expected %(expected_gen)s but got %(got_gen)s') %
|
'expected %(expected_gen)s but got %(got_gen)s') %
|
||||||
{
|
{
|
||||||
'expected_gen': consumer.generation,
|
'expected_gen': consumer.generation,
|
||||||
'got_gen': consumer_generation,
|
'got_gen': consumer_generation,
|
||||||
},
|
},
|
||||||
comment=errors.CONCURRENT_UPDATE)
|
comment=errors.CONCURRENT_UPDATE)
|
||||||
# NOTE(jaypipes): The user may have specified a different project and
|
# 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
|
# 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
|
# is the case, go ahead and modify the consumer record with the
|
||||||
|
@ -29,7 +29,7 @@ _QS_REQUIRED = 'required'
|
|||||||
_QS_MEMBER_OF = 'member_of'
|
_QS_MEMBER_OF = 'member_of'
|
||||||
_QS_IN_TREE = 'in_tree'
|
_QS_IN_TREE = 'in_tree'
|
||||||
_QS_KEY_PATTERN = re.compile(
|
_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)))
|
(_QS_RESOURCES, _QS_REQUIRED, _QS_MEMBER_OF, _QS_IN_TREE)))
|
||||||
|
|
||||||
|
|
||||||
@ -144,8 +144,7 @@ class RequestGroup(object):
|
|||||||
for suff, group in by_suffix.items():
|
for suff, group in by_suffix.items():
|
||||||
forbidden = [trait for trait in group.required_traits
|
forbidden = [trait for trait in group.required_traits
|
||||||
if trait.startswith('!')]
|
if trait.startswith('!')]
|
||||||
group.required_traits = (
|
group.required_traits = group.required_traits - set(forbidden)
|
||||||
group.required_traits - set(forbidden))
|
|
||||||
group.forbidden_traits = set([trait.lstrip('!') for trait in
|
group.forbidden_traits = set([trait.lstrip('!') for trait in
|
||||||
forbidden])
|
forbidden])
|
||||||
conflicts = group.forbidden_traits & group.required_traits
|
conflicts = group.forbidden_traits & group.required_traits
|
||||||
|
@ -121,23 +121,25 @@ def _check_capacity_exceeded(ctx, allocs):
|
|||||||
# We then take the results of the above and determine if any of the
|
# We then take the results of the above and determine if any of the
|
||||||
# inventory will have its capacity exceeded.
|
# inventory will have its capacity exceeded.
|
||||||
rc_ids = set([rc_cache.RC_CACHE.id_from_string(a.resource_class)
|
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_uuids = set([a.resource_provider.uuid for a in allocs])
|
||||||
provider_ids = set([a.resource_provider.id for a in allocs])
|
provider_ids = set([a.resource_provider.id for a in allocs])
|
||||||
usage = sa.select([_ALLOC_TBL.c.resource_provider_id,
|
usage = sa.select([_ALLOC_TBL.c.resource_provider_id,
|
||||||
_ALLOC_TBL.c.resource_class_id,
|
_ALLOC_TBL.c.resource_class_id,
|
||||||
sql.func.sum(_ALLOC_TBL.c.used).label('used')])
|
sql.func.sum(_ALLOC_TBL.c.used).label('used')])
|
||||||
usage = usage.where(
|
usage = usage.where(
|
||||||
sa.and_(_ALLOC_TBL.c.resource_class_id.in_(rc_ids),
|
sa.and_(_ALLOC_TBL.c.resource_class_id.in_(rc_ids),
|
||||||
_ALLOC_TBL.c.resource_provider_id.in_(provider_ids)))
|
_ALLOC_TBL.c.resource_provider_id.in_(provider_ids)))
|
||||||
usage = usage.group_by(_ALLOC_TBL.c.resource_provider_id,
|
usage = usage.group_by(_ALLOC_TBL.c.resource_provider_id,
|
||||||
_ALLOC_TBL.c.resource_class_id)
|
_ALLOC_TBL.c.resource_class_id)
|
||||||
usage = sa.alias(usage, name='usage')
|
usage = sa.alias(usage, name='usage')
|
||||||
|
|
||||||
inv_join = sql.join(_RP_TBL, _INV_TBL,
|
inv_join = sql.join(
|
||||||
sql.and_(_RP_TBL.c.id == _INV_TBL.c.resource_provider_id,
|
_RP_TBL, _INV_TBL,
|
||||||
_INV_TBL.c.resource_class_id.in_(rc_ids)))
|
sql.and_(_RP_TBL.c.id == _INV_TBL.c.resource_provider_id,
|
||||||
primary_join = sql.outerjoin(inv_join, usage,
|
_INV_TBL.c.resource_class_id.in_(rc_ids)))
|
||||||
|
primary_join = sql.outerjoin(
|
||||||
|
inv_join, usage,
|
||||||
sql.and_(
|
sql.and_(
|
||||||
_INV_TBL.c.resource_provider_id == usage.c.resource_provider_id,
|
_INV_TBL.c.resource_provider_id == usage.c.resource_provider_id,
|
||||||
_INV_TBL.c.resource_class_id == usage.c.resource_class_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 = sa.select(cols_in_output).select_from(primary_join)
|
||||||
sel = sel.where(
|
sel = sel.where(
|
||||||
sa.and_(_RP_TBL.c.id.in_(provider_ids),
|
sa.and_(_RP_TBL.c.id.in_(provider_ids),
|
||||||
_INV_TBL.c.resource_class_id.in_(rc_ids)))
|
_INV_TBL.c.resource_class_id.in_(rc_ids)))
|
||||||
records = ctx.session.execute(sel)
|
records = ctx.session.execute(sel)
|
||||||
# Create a map keyed by (rp_uuid, res_class) for the records in the DB
|
# Create a map keyed by (rp_uuid, res_class) for the records in the DB
|
||||||
usage_map = {}
|
usage_map = {}
|
||||||
@ -176,8 +178,8 @@ def _check_capacity_exceeded(ctx, allocs):
|
|||||||
class_str = ', '.join([rc_cache.RC_CACHE.string_from_id(rc_id)
|
class_str = ', '.join([rc_cache.RC_CACHE.string_from_id(rc_id)
|
||||||
for rc_id in rc_ids])
|
for rc_id in rc_ids])
|
||||||
provider_str = ', '.join(missing_provs)
|
provider_str = ', '.join(missing_provs)
|
||||||
raise exception.InvalidInventory(resource_class=class_str,
|
raise exception.InvalidInventory(
|
||||||
resource_provider=provider_str)
|
resource_class=class_str, resource_provider=provider_str)
|
||||||
|
|
||||||
res_providers = {}
|
res_providers = {}
|
||||||
rp_resource_class_sum = collections.defaultdict(
|
rp_resource_class_sum = collections.defaultdict(
|
||||||
@ -198,8 +200,8 @@ def _check_capacity_exceeded(ctx, allocs):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
# The resource class at rc_id is not in the usage map.
|
# The resource class at rc_id is not in the usage map.
|
||||||
raise exception.InvalidInventory(
|
raise exception.InvalidInventory(
|
||||||
resource_class=alloc.resource_class,
|
resource_class=alloc.resource_class,
|
||||||
resource_provider=rp_uuid)
|
resource_provider=rp_uuid)
|
||||||
allocation_ratio = usage['allocation_ratio']
|
allocation_ratio = usage['allocation_ratio']
|
||||||
min_unit = usage['min_unit']
|
min_unit = usage['min_unit']
|
||||||
max_unit = usage['max_unit']
|
max_unit = usage['max_unit']
|
||||||
@ -227,7 +229,7 @@ def _check_capacity_exceeded(ctx, allocs):
|
|||||||
used = usage['used'] or 0
|
used = usage['used'] or 0
|
||||||
capacity = (usage['total'] - usage['reserved']) * allocation_ratio
|
capacity = (usage['total'] - usage['reserved']) * allocation_ratio
|
||||||
if (capacity < (used + amount_needed) or
|
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(
|
LOG.warning(
|
||||||
"Over capacity for %(rc)s on resource provider %(rp)s. "
|
"Over capacity for %(rc)s on resource provider %(rp)s. "
|
||||||
"Needed: %(needed)s, Used: %(used)s, Capacity: %(cap)s",
|
"Needed: %(needed)s, Used: %(used)s, Capacity: %(cap)s",
|
||||||
@ -457,10 +459,10 @@ def _set_allocations(context, allocs):
|
|||||||
rp = alloc.resource_provider
|
rp = alloc.resource_provider
|
||||||
rc_id = rc_cache.RC_CACHE.id_from_string(alloc.resource_class)
|
rc_id = rc_cache.RC_CACHE.id_from_string(alloc.resource_class)
|
||||||
ins_stmt = _ALLOC_TBL.insert().values(
|
ins_stmt = _ALLOC_TBL.insert().values(
|
||||||
resource_provider_id=rp.id,
|
resource_provider_id=rp.id,
|
||||||
resource_class_id=rc_id,
|
resource_class_id=rc_id,
|
||||||
consumer_id=consumer_id,
|
consumer_id=consumer_id,
|
||||||
used=alloc.used)
|
used=alloc.used)
|
||||||
res = context.session.execute(ins_stmt)
|
res = context.session.execute(ins_stmt)
|
||||||
alloc.id = res.lastrowid
|
alloc.id = res.lastrowid
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ def _get_current_inventory_resources(ctx, rp):
|
|||||||
:param rp: Resource provider to query inventory for.
|
:param rp: Resource provider to query inventory for.
|
||||||
"""
|
"""
|
||||||
cur_res_sel = sa.select([_INV_TBL.c.resource_class_id]).where(
|
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()
|
existing_resources = ctx.session.execute(cur_res_sel).fetchall()
|
||||||
return set([r[0] for r in existing_resources])
|
return set([r[0] for r in existing_resources])
|
||||||
|
|
||||||
@ -216,10 +216,11 @@ def _delete_inventory_from_provider(ctx, rp, to_delete):
|
|||||||
delete.
|
delete.
|
||||||
"""
|
"""
|
||||||
allocation_query = sa.select(
|
allocation_query = sa.select(
|
||||||
[_ALLOC_TBL.c.resource_class_id.label('resource_class')]).where(
|
[_ALLOC_TBL.c.resource_class_id.label('resource_class')]
|
||||||
sa.and_(_ALLOC_TBL.c.resource_provider_id == rp.id,
|
).where(
|
||||||
_ALLOC_TBL.c.resource_class_id.in_(to_delete))
|
sa.and_(_ALLOC_TBL.c.resource_provider_id == rp.id,
|
||||||
).group_by(_ALLOC_TBL.c.resource_class_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()
|
allocations = ctx.session.execute(allocation_query).fetchall()
|
||||||
if allocations:
|
if allocations:
|
||||||
resource_classes = ', '.join(
|
resource_classes = ', '.join(
|
||||||
@ -228,7 +229,8 @@ def _delete_inventory_from_provider(ctx, rp, to_delete):
|
|||||||
raise exception.InventoryInUse(resource_classes=resource_classes,
|
raise exception.InventoryInUse(resource_classes=resource_classes,
|
||||||
resource_provider=rp.uuid)
|
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_provider_id == rp.id,
|
||||||
_INV_TBL.c.resource_class_id.in_(to_delete)))
|
_INV_TBL.c.resource_class_id.in_(to_delete)))
|
||||||
res = ctx.session.execute(del_stmt)
|
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)
|
rc_str = rc_cache.RC_CACHE.string_from_id(rc_id)
|
||||||
inv_record = inv_list.find(rc_str)
|
inv_record = inv_list.find(rc_str)
|
||||||
ins_stmt = _INV_TBL.insert().values(
|
ins_stmt = _INV_TBL.insert().values(
|
||||||
resource_provider_id=rp.id,
|
resource_provider_id=rp.id,
|
||||||
resource_class_id=rc_id,
|
resource_class_id=rc_id,
|
||||||
total=inv_record.total,
|
total=inv_record.total,
|
||||||
reserved=inv_record.reserved,
|
reserved=inv_record.reserved,
|
||||||
min_unit=inv_record.min_unit,
|
min_unit=inv_record.min_unit,
|
||||||
max_unit=inv_record.max_unit,
|
max_unit=inv_record.max_unit,
|
||||||
step_size=inv_record.step_size,
|
step_size=inv_record.step_size,
|
||||||
allocation_ratio=inv_record.allocation_ratio)
|
allocation_ratio=inv_record.allocation_ratio)
|
||||||
ctx.session.execute(ins_stmt)
|
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_provider_id == rp.id,
|
||||||
_ALLOC_TBL.c.resource_class_id == rc_id))
|
_ALLOC_TBL.c.resource_class_id == rc_id))
|
||||||
allocations = ctx.session.execute(allocation_query).first()
|
allocations = ctx.session.execute(allocation_query).first()
|
||||||
if (allocations
|
if (allocations and
|
||||||
and allocations['usage'] is not None
|
allocations['usage'] is not None and
|
||||||
and allocations['usage'] > inv_record.capacity):
|
allocations['usage'] > inv_record.capacity):
|
||||||
exceeded.append((rp.uuid, rc_str))
|
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_provider_id == rp.id,
|
||||||
_INV_TBL.c.resource_class_id == rc_id)).values(
|
_INV_TBL.c.resource_class_id == rc_id)
|
||||||
total=inv_record.total,
|
).values(
|
||||||
reserved=inv_record.reserved,
|
total=inv_record.total,
|
||||||
min_unit=inv_record.min_unit,
|
reserved=inv_record.reserved,
|
||||||
max_unit=inv_record.max_unit,
|
min_unit=inv_record.min_unit,
|
||||||
step_size=inv_record.step_size,
|
max_unit=inv_record.max_unit,
|
||||||
allocation_ratio=inv_record.allocation_ratio)
|
step_size=inv_record.step_size,
|
||||||
|
allocation_ratio=inv_record.allocation_ratio)
|
||||||
res = ctx.session.execute(upd_stmt)
|
res = ctx.session.execute(upd_stmt)
|
||||||
if not res.rowcount:
|
if not res.rowcount:
|
||||||
raise exception.InventoryWithResourceClassNotFound(
|
raise exception.InventoryWithResourceClassNotFound(
|
||||||
resource_class=rc_str)
|
resource_class=rc_str)
|
||||||
return exceeded
|
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
|
# TODO(jaypipes): Change this to an inner join when we are sure all
|
||||||
# root_provider_id values are NOT NULL
|
# root_provider_id values are NOT NULL
|
||||||
rp_to_root = sa.outerjoin(rpt, root, rpt.c.root_provider_id == root.c.id)
|
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)
|
rpt.c.parent_provider_id == parent.c.id)
|
||||||
cols = [
|
cols = [
|
||||||
rpt.c.id,
|
rpt.c.id,
|
||||||
@ -597,7 +602,8 @@ def _set_aggregates(context, resource_provider, provided_aggregates,
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
for agg_id, agg_uuid in aggs_to_disassociate.items():
|
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.resource_provider_id == rp_id,
|
||||||
_RP_AGG_TBL.c.aggregate_id == agg_id))
|
_RP_AGG_TBL.c.aggregate_id == agg_id))
|
||||||
context.session.execute(del_stmt)
|
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
|
# TODO(jaypipes): Change this to an inner join when we are sure all
|
||||||
# root_provider_id values are NOT NULL
|
# root_provider_id values are NOT NULL
|
||||||
me_to_root = sa.outerjoin(me, root, me.c.root_provider_id == root.c.id)
|
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)
|
me.c.parent_provider_id == parent.c.id)
|
||||||
sel = sa.select(cols).select_from(me_to_parent)
|
sel = sa.select(cols).select_from(me_to_parent)
|
||||||
sel = sel.where(me.c.id.in_(rp_ids))
|
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
|
# TODO(jaypipes): Change this to an inner join when we are sure all
|
||||||
# root_provider_id values are NOT NULL
|
# root_provider_id values are NOT NULL
|
||||||
me_to_root = sa.outerjoin(me, root, me.c.root_provider_id == root.c.id)
|
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)
|
me.c.parent_provider_id == parent.c.id)
|
||||||
sel = sa.select(cols).select_from(me_to_parent)
|
sel = sa.select(cols).select_from(me_to_parent)
|
||||||
sel = sel.where(me.c.uuid == uuid)
|
sel = sel.where(me.c.uuid == uuid)
|
||||||
@ -1094,16 +1102,16 @@ class ResourceProvider(object):
|
|||||||
# Setting parent to ourselves doesn't make any sense
|
# Setting parent to ourselves doesn't make any sense
|
||||||
if parent_uuid == self.uuid:
|
if parent_uuid == self.uuid:
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='create',
|
action='create',
|
||||||
reason=_('parent provider UUID cannot be same as '
|
reason=_('parent provider UUID cannot be same as UUID. '
|
||||||
'UUID. Please set parent provider UUID to '
|
'Please set parent provider UUID to None if '
|
||||||
'None if there is no parent.'))
|
'there is no parent.'))
|
||||||
|
|
||||||
parent_ids = _provider_ids_from_uuid(context, parent_uuid)
|
parent_ids = _provider_ids_from_uuid(context, parent_uuid)
|
||||||
if parent_ids is None:
|
if parent_ids is None:
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='create',
|
action='create',
|
||||||
reason=_('parent provider UUID does not exist.'))
|
reason=_('parent provider UUID does not exist.'))
|
||||||
|
|
||||||
parent_id = parent_ids.id
|
parent_id = parent_ids.id
|
||||||
root_id = parent_ids.root_id
|
root_id = parent_ids.root_id
|
||||||
@ -1140,9 +1148,8 @@ class ResourceProvider(object):
|
|||||||
raise exception.CannotDeleteParentResourceProvider()
|
raise exception.CannotDeleteParentResourceProvider()
|
||||||
|
|
||||||
# Don't delete the resource provider if it has allocations.
|
# Don't delete the resource provider if it has allocations.
|
||||||
rp_allocations = context.session.query(models.Allocation).\
|
rp_allocations = context.session.query(models.Allocation).filter(
|
||||||
filter(models.Allocation.resource_provider_id == _id).\
|
models.Allocation.resource_provider_id == _id).count()
|
||||||
count()
|
|
||||||
if rp_allocations:
|
if rp_allocations:
|
||||||
raise exception.ResourceProviderInUse()
|
raise exception.ResourceProviderInUse()
|
||||||
# Delete any inventory associated with the resource provider
|
# Delete any inventory associated with the resource provider
|
||||||
@ -1152,12 +1159,12 @@ class ResourceProvider(object):
|
|||||||
# Delete any aggregate associations for the resource provider
|
# Delete any aggregate associations for the resource provider
|
||||||
# The name substitution on the next line is needed to satisfy pep8
|
# The name substitution on the next line is needed to satisfy pep8
|
||||||
RPA_model = models.ResourceProviderAggregate
|
RPA_model = models.ResourceProviderAggregate
|
||||||
context.session.query(RPA_model).\
|
context.session.query(RPA_model).filter(
|
||||||
filter(RPA_model.resource_provider_id == _id).delete()
|
RPA_model.resource_provider_id == _id).delete()
|
||||||
# delete any trait associations for the resource provider
|
# delete any trait associations for the resource provider
|
||||||
RPT_model = models.ResourceProviderTrait
|
RPT_model = models.ResourceProviderTrait
|
||||||
context.session.query(RPT_model).\
|
context.session.query(RPT_model).filter(
|
||||||
filter(RPT_model.resource_provider_id == _id).delete()
|
RPT_model.resource_provider_id == _id).delete()
|
||||||
# set root_provider_id to null to make deletion possible
|
# set root_provider_id to null to make deletion possible
|
||||||
context.session.query(models.ResourceProvider).\
|
context.session.query(models.ResourceProvider).\
|
||||||
filter(models.ResourceProvider.id == _id,
|
filter(models.ResourceProvider.id == _id,
|
||||||
@ -1197,14 +1204,14 @@ class ResourceProvider(object):
|
|||||||
# User supplied a parent, let's make sure it exists
|
# User supplied a parent, let's make sure it exists
|
||||||
if parent_ids is None:
|
if parent_ids is None:
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='create',
|
action='create',
|
||||||
reason=_('parent provider UUID does not exist.'))
|
reason=_('parent provider UUID does not exist.'))
|
||||||
if (my_ids.parent_id is not None and
|
if (my_ids.parent_id is not None and
|
||||||
my_ids.parent_id != parent_ids.id):
|
my_ids.parent_id != parent_ids.id):
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='update',
|
action='update',
|
||||||
reason=_('re-parenting a provider is not '
|
reason=_('re-parenting a provider is not currently '
|
||||||
'currently allowed.'))
|
'allowed.'))
|
||||||
if my_ids.parent_uuid is None:
|
if my_ids.parent_uuid is None:
|
||||||
# So the user specifies a parent for an RP that doesn't
|
# So the user specifies a parent for an RP that doesn't
|
||||||
# have one. We have to check that by this new parent we
|
# have one. We have to check that by this new parent we
|
||||||
@ -1229,9 +1236,9 @@ class ResourceProvider(object):
|
|||||||
else:
|
else:
|
||||||
if my_ids.parent_id is not None:
|
if my_ids.parent_id is not None:
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='update',
|
action='update',
|
||||||
reason=_('un-parenting a provider is not '
|
reason=_('un-parenting a provider is not currently '
|
||||||
'currently allowed.'))
|
'allowed.'))
|
||||||
|
|
||||||
db_rp = context.session.query(models.ResourceProvider).filter_by(
|
db_rp = context.session.query(models.ResourceProvider).filter_by(
|
||||||
id=id).first()
|
id=id).first()
|
||||||
@ -1259,8 +1266,8 @@ class ResourceProvider(object):
|
|||||||
# for this resource provider in between the above check for a valid
|
# for this resource provider in between the above check for a valid
|
||||||
# parent provider and here...
|
# parent provider and here...
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='update',
|
action='update',
|
||||||
reason=_('parent provider UUID does not exist.'))
|
reason=_('parent provider UUID does not exist.'))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.placement_context_manager.writer # For online data migration
|
@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
|
# TODO(jaypipes): Convert this to an inner join once all
|
||||||
# root_provider_id values are NOT NULL
|
# 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.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)
|
rp.c.parent_provider_id == parent_rp.c.id)
|
||||||
|
|
||||||
query = sa.select(cols).select_from(rp_to_parent)
|
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
|
# TODO(jaypipes): Remove this OR condition when root_provider_id
|
||||||
# is not nullable in the database and all resource provider records
|
# is not nullable in the database and all resource provider records
|
||||||
# have populated the root provider ID.
|
# 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)
|
rp.c.root_provider_id == root_id)
|
||||||
query = query.where(where_cond)
|
query = query.where(where_cond)
|
||||||
|
|
||||||
@ -1549,13 +1559,15 @@ class ResourceProviderList(common_obj.ObjectList):
|
|||||||
# comes from the above filters
|
# comes from the above filters
|
||||||
|
|
||||||
# First JOIN between inventories and RPs is here
|
# 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)
|
rp.c.id == _INV_TBL.c.resource_provider_id)
|
||||||
|
|
||||||
# Now, below is the LEFT JOIN for getting the allocations usage
|
# Now, below is the LEFT JOIN for getting the allocations usage
|
||||||
usage = _usage_select(list(resources))
|
usage = _usage_select(list(resources))
|
||||||
usage_join = sa.outerjoin(inv_join, usage,
|
usage_join = sa.outerjoin(
|
||||||
sa.and_(
|
inv_join, usage, sa.and_(
|
||||||
usage.c.resource_provider_id == (
|
usage.c.resource_provider_id == (
|
||||||
_INV_TBL.c.resource_provider_id),
|
_INV_TBL.c.resource_provider_id),
|
||||||
usage.c.resource_class_id == _INV_TBL.c.resource_class_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.
|
# Never delete any standard resource class.
|
||||||
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
|
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
|
||||||
raise exception.ResourceClassCannotDeleteStandard(
|
raise exception.ResourceClassCannotDeleteStandard(
|
||||||
resource_class=self.name)
|
resource_class=self.name)
|
||||||
|
|
||||||
self._destroy(self._context, self.id, self.name)
|
self._destroy(self._context, self.id, self.name)
|
||||||
rc_cache.RC_CACHE.clear()
|
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
|
# Don't delete the resource class if it is referred to in the
|
||||||
# inventories table.
|
# inventories table.
|
||||||
num_inv = context.session.query(models.Inventory).filter(
|
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:
|
if num_inv:
|
||||||
raise exception.ResourceClassInUse(resource_class=name)
|
raise exception.ResourceClassInUse(resource_class=name)
|
||||||
|
|
||||||
res = context.session.query(models.ResourceClass).filter(
|
res = context.session.query(models.ResourceClass).filter(
|
||||||
models.ResourceClass.id == _id).delete()
|
models.ResourceClass.id == _id).delete()
|
||||||
if not res:
|
if not res:
|
||||||
raise exception.NotFound()
|
raise exception.NotFound()
|
||||||
|
|
||||||
@ -1842,7 +1854,7 @@ class ResourceClass(object):
|
|||||||
# Never update any standard resource class.
|
# Never update any standard resource class.
|
||||||
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
|
if self.id < ResourceClass.MIN_CUSTOM_RESOURCE_CLASS_ID:
|
||||||
raise exception.ResourceClassCannotUpdateStandard(
|
raise exception.ResourceClassCannotUpdateStandard(
|
||||||
resource_class=self.name)
|
resource_class=self.name)
|
||||||
self._save(self._context, self.id, self.name, updates)
|
self._save(self._context, self.id, self.name, updates)
|
||||||
rc_cache.RC_CACHE.clear()
|
rc_cache.RC_CACHE.clear()
|
||||||
|
|
||||||
@ -1986,11 +1998,13 @@ class TraitList(common_obj.ObjectList):
|
|||||||
models.Trait.name.like(six.text_type(filters['prefix'] + '%')))
|
models.Trait.name.like(six.text_type(filters['prefix'] + '%')))
|
||||||
if 'associated' in filters:
|
if 'associated' in filters:
|
||||||
if filters['associated']:
|
if filters['associated']:
|
||||||
query = query.join(models.ResourceProviderTrait,
|
query = query.join(
|
||||||
|
models.ResourceProviderTrait,
|
||||||
models.Trait.id == models.ResourceProviderTrait.trait_id
|
models.Trait.id == models.ResourceProviderTrait.trait_id
|
||||||
).distinct()
|
).distinct()
|
||||||
else:
|
else:
|
||||||
query = query.outerjoin(models.ResourceProviderTrait,
|
query = query.outerjoin(
|
||||||
|
models.ResourceProviderTrait,
|
||||||
models.Trait.id == models.ResourceProviderTrait.trait_id
|
models.Trait.id == models.ResourceProviderTrait.trait_id
|
||||||
).filter(models.ResourceProviderTrait.trait_id == null())
|
).filter(models.ResourceProviderTrait.trait_id == null())
|
||||||
|
|
||||||
@ -2019,9 +2033,9 @@ class AllocationRequestResource(object):
|
|||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (self.resource_provider.id == other.resource_provider.id) and (
|
return ((self.resource_provider.id == other.resource_provider.id) and
|
||||||
self.resource_class == other.resource_class) and (
|
(self.resource_class == other.resource_class) and
|
||||||
self.amount == other.amount)
|
(self.amount == other.amount))
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.resource_provider.id,
|
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
|
@db_api.placement_context_manager.reader
|
||||||
def _get_provider_ids_matching(ctx, resources, required_traits,
|
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)
|
"""Returns a list of tuples of (internal provider ID, root provider ID)
|
||||||
that have available inventory to satisfy all the supplied requests for
|
that have available inventory to satisfy all the supplied requests for
|
||||||
resources. If no providers match, the empty list is returned.
|
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>
|
# process if tree_root_id is provided via the ?in_tree=<rp_uuid>
|
||||||
# queryparam, because it restricts resources from another tree.
|
# queryparam, because it restricts resources from another tree.
|
||||||
rc_provs_with_inv = _anchors_for_sharing_providers(
|
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)
|
provs_with_inv_rc.add_rps(rc_provs_with_inv, rc_id)
|
||||||
LOG.debug("considering %d sharing providers with %d %s, "
|
LOG.debug(
|
||||||
"now we've got %d provider trees",
|
"considering %d sharing providers with %d %s, "
|
||||||
len(sharing_providers), amount, rc_name,
|
"now we've got %d provider trees",
|
||||||
len(provs_with_inv_rc.trees))
|
len(sharing_providers), amount, rc_name,
|
||||||
|
len(provs_with_inv_rc.trees))
|
||||||
|
|
||||||
# Adding the resource providers we've got for this resource class,
|
# Adding the resource providers we've got for this resource class,
|
||||||
# filter provs_with_inv to have only trees with enough inventories
|
# filter provs_with_inv to have only trees with enough inventories
|
||||||
# for this resource class. Here "tree" includes sharing providers
|
# for this resource class. Here "tree" includes sharing providers
|
||||||
# in its terminology
|
# in its terminology
|
||||||
provs_with_inv.merge_common_trees(provs_with_inv_rc)
|
provs_with_inv.merge_common_trees(provs_with_inv_rc)
|
||||||
LOG.debug("found %d providers under %d trees after filtering by "
|
LOG.debug(
|
||||||
"previous result",
|
"found %d providers under %d trees after filtering by "
|
||||||
len(provs_with_inv.rps), len(provs_with_inv_rc.trees))
|
"previous result",
|
||||||
|
len(provs_with_inv.rps), len(provs_with_inv_rc.trees))
|
||||||
if not provs_with_inv:
|
if not provs_with_inv:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -2791,8 +2807,8 @@ def _allocation_request_for_provider(ctx, requested_resources, provider):
|
|||||||
# caller needs to identify the other anchors with which it might be
|
# caller needs to identify the other anchors with which it might be
|
||||||
# associated.
|
# associated.
|
||||||
return AllocationRequest(
|
return AllocationRequest(
|
||||||
resource_requests=resource_requests,
|
resource_requests=resource_requests,
|
||||||
anchor_root_provider_uuid=provider.root_provider_uuid)
|
anchor_root_provider_uuid=provider.root_provider_uuid)
|
||||||
|
|
||||||
|
|
||||||
def _check_traits_for_alloc_request(res_requests, summaries, prov_traits,
|
def _check_traits_for_alloc_request(res_requests, summaries, prov_traits,
|
||||||
@ -2897,7 +2913,7 @@ def _alloc_candidates_single_provider(ctx, requested_resources, rp_tuples):
|
|||||||
for rp_id, root_id in rp_tuples:
|
for rp_id, root_id in rp_tuples:
|
||||||
rp_summary = summaries[rp_id]
|
rp_summary = summaries[rp_id]
|
||||||
req_obj = _allocation_request_for_provider(
|
req_obj = _allocation_request_for_provider(
|
||||||
ctx, requested_resources, rp_summary.resource_provider)
|
ctx, requested_resources, rp_summary.resource_provider)
|
||||||
alloc_requests.append(req_obj)
|
alloc_requests.append(req_obj)
|
||||||
# If this is a sharing provider, we have to include an extra
|
# If this is a sharing provider, we have to include an extra
|
||||||
# AllocationRequest for every possible anchor.
|
# AllocationRequest for every possible anchor.
|
||||||
@ -2915,8 +2931,9 @@ def _alloc_candidates_single_provider(ctx, requested_resources, rp_tuples):
|
|||||||
return alloc_requests, list(summaries.values())
|
return alloc_requests, list(summaries.values())
|
||||||
|
|
||||||
|
|
||||||
def _alloc_candidates_multiple_providers(ctx, requested_resources,
|
def _alloc_candidates_multiple_providers(
|
||||||
required_traits, forbidden_traits, rp_candidates):
|
ctx, requested_resources, required_traits, forbidden_traits,
|
||||||
|
rp_candidates):
|
||||||
"""Returns a tuple of (allocation requests, provider summaries) for a
|
"""Returns a tuple of (allocation requests, provider summaries) for a
|
||||||
supplied set of requested resource amounts and tuples of
|
supplied set of requested resource amounts and tuples of
|
||||||
(rp_id, root_id, rc_id). The supplied resource provider trees have
|
(rp_id, root_id, rc_id). The supplied resource provider trees have
|
||||||
@ -3004,8 +3021,9 @@ def _alloc_candidates_multiple_providers(ctx, requested_resources,
|
|||||||
# (ARR(rc1, ss2), ARR(rc2, ss1), ARR(rc3, ss1)),
|
# (ARR(rc1, ss2), ARR(rc2, ss1), ARR(rc3, ss1)),
|
||||||
# (ARR(rc1, ss2), ARR(rc2, ss2), ARR(rc3, ss1))]
|
# (ARR(rc1, ss2), ARR(rc2, ss2), ARR(rc3, ss1))]
|
||||||
for res_requests in itertools.product(*request_groups):
|
for res_requests in itertools.product(*request_groups):
|
||||||
if not _check_traits_for_alloc_request(res_requests,
|
if not _check_traits_for_alloc_request(
|
||||||
summaries, prov_traits, required_traits, forbidden_traits):
|
res_requests, summaries, prov_traits, required_traits,
|
||||||
|
forbidden_traits):
|
||||||
# This combination doesn't satisfy trait constraints
|
# This combination doesn't satisfy trait constraints
|
||||||
continue
|
continue
|
||||||
root_alloc_reqs.add(
|
root_alloc_reqs.add(
|
||||||
@ -3226,7 +3244,7 @@ def _merge_candidates(candidates, group_policy=None):
|
|||||||
# ...
|
# ...
|
||||||
# }
|
# }
|
||||||
areq_lists_by_anchor = collections.defaultdict(
|
areq_lists_by_anchor = collections.defaultdict(
|
||||||
lambda: collections.defaultdict(list))
|
lambda: collections.defaultdict(list))
|
||||||
# Save off all the provider summaries lists - we'll use 'em later.
|
# Save off all the provider summaries lists - we'll use 'em later.
|
||||||
all_psums = []
|
all_psums = []
|
||||||
# Construct a dict, keyed by resource provider + resource class, of
|
# Construct a dict, keyed by resource provider + resource class, of
|
||||||
@ -3241,7 +3259,7 @@ def _merge_candidates(candidates, group_policy=None):
|
|||||||
all_psums.append(psum)
|
all_psums.append(psum)
|
||||||
for psum_res in psum.resources:
|
for psum_res in psum.resources:
|
||||||
key = _rp_rc_key(
|
key = _rp_rc_key(
|
||||||
psum.resource_provider, psum_res.resource_class)
|
psum.resource_provider, psum_res.resource_class)
|
||||||
psum_res_by_rp_rc[key] = psum_res
|
psum_res_by_rp_rc[key] = psum_res
|
||||||
|
|
||||||
# Create all combinations picking one AllocationRequest from each list
|
# Create all combinations picking one AllocationRequest from each list
|
||||||
@ -3432,21 +3450,21 @@ class AllocationCandidates(object):
|
|||||||
context, required_trait_map)
|
context, required_trait_map)
|
||||||
if not trait_rps:
|
if not trait_rps:
|
||||||
return [], []
|
return [], []
|
||||||
rp_candidates = _get_trees_matching_all(context, resources,
|
rp_candidates = _get_trees_matching_all(
|
||||||
required_trait_map, forbidden_trait_map,
|
context, resources, required_trait_map, forbidden_trait_map,
|
||||||
sharing_providers, member_of, tree_root_id)
|
sharing_providers, member_of, tree_root_id)
|
||||||
return _alloc_candidates_multiple_providers(context, resources,
|
return _alloc_candidates_multiple_providers(
|
||||||
required_trait_map, forbidden_trait_map, rp_candidates)
|
context, resources, required_trait_map, forbidden_trait_map,
|
||||||
|
rp_candidates)
|
||||||
|
|
||||||
# Either we are processing a single-RP request group, or there are no
|
# Either we are processing a single-RP request group, or there are no
|
||||||
# sharing providers that (help) satisfy the request. Get a list of
|
# sharing providers that (help) satisfy the request. Get a list of
|
||||||
# tuples of (internal provider ID, root provider ID) that have ALL
|
# tuples of (internal provider ID, root provider ID) that have ALL
|
||||||
# the requested resources and more efficiently construct the
|
# the requested resources and more efficiently construct the
|
||||||
# allocation requests.
|
# allocation requests.
|
||||||
rp_tuples = _get_provider_ids_matching(context, resources,
|
rp_tuples = _get_provider_ids_matching(
|
||||||
required_trait_map,
|
context, resources, required_trait_map, forbidden_trait_map,
|
||||||
forbidden_trait_map, member_of,
|
member_of, tree_root_id)
|
||||||
tree_root_id)
|
|
||||||
return _alloc_candidates_single_provider(context, resources, rp_tuples)
|
return _alloc_candidates_single_provider(context, resources, rp_tuples)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -3493,7 +3511,7 @@ class AllocationCandidates(object):
|
|||||||
# `candidates` dict is guaranteed to contain entries for all suffixes,
|
# `candidates` dict is guaranteed to contain entries for all suffixes,
|
||||||
# or we would have short-circuited above.
|
# or we would have short-circuited above.
|
||||||
alloc_request_objs, summary_objs = _merge_candidates(
|
alloc_request_objs, summary_objs = _merge_candidates(
|
||||||
candidates, group_policy=group_policy)
|
candidates, group_policy=group_policy)
|
||||||
|
|
||||||
return cls._limit_results(context, alloc_request_objs, summary_objs,
|
return cls._limit_results(context, alloc_request_objs, summary_objs,
|
||||||
limit)
|
limit)
|
||||||
|
@ -35,7 +35,7 @@ class RequestLog(object):
|
|||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
LOG.debug('Starting request: %s "%s %s"',
|
LOG.debug('Starting request: %s "%s %s"',
|
||||||
environ['REMOTE_ADDR'], environ['REQUEST_METHOD'],
|
environ['REMOTE_ADDR'], environ['REQUEST_METHOD'],
|
||||||
self._get_uri(environ))
|
self._get_uri(environ))
|
||||||
# Set the accept header if it is not otherwise set or is '*/*'. This
|
# Set the accept header if it is not otherwise set or is '*/*'. This
|
||||||
# ensures that error responses will be in JSON.
|
# ensures that error responses will be in JSON.
|
||||||
accept = environ.get('HTTP_ACCEPT')
|
accept = environ.get('HTTP_ACCEPT')
|
||||||
@ -48,8 +48,8 @@ class RequestLog(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_uri(environ):
|
def _get_uri(environ):
|
||||||
req_uri = (environ.get('SCRIPT_NAME', '')
|
req_uri = (environ.get('SCRIPT_NAME', '') +
|
||||||
+ environ.get('PATH_INFO', ''))
|
environ.get('PATH_INFO', ''))
|
||||||
if environ.get('QUERY_STRING'):
|
if environ.get('QUERY_STRING'):
|
||||||
req_uri += '?' + environ['QUERY_STRING']
|
req_uri += '?' + environ['QUERY_STRING']
|
||||||
return req_uri
|
return req_uri
|
||||||
@ -76,12 +76,12 @@ class RequestLog(object):
|
|||||||
if size is None:
|
if size is None:
|
||||||
size = '-'
|
size = '-'
|
||||||
log_format = {
|
log_format = {
|
||||||
'REMOTE_ADDR': environ.get('REMOTE_ADDR', '-'),
|
'REMOTE_ADDR': environ.get('REMOTE_ADDR', '-'),
|
||||||
'REQUEST_METHOD': environ['REQUEST_METHOD'],
|
'REQUEST_METHOD': environ['REQUEST_METHOD'],
|
||||||
'REQUEST_URI': req_uri,
|
'REQUEST_URI': req_uri,
|
||||||
'status': status.split(None, 1)[0],
|
'status': status.split(None, 1)[0],
|
||||||
'bytes': size,
|
'bytes': size,
|
||||||
'microversion': environ.get(
|
'microversion': environ.get(
|
||||||
microversion.MICROVERSION_ENVIRON, '-'),
|
microversion.MICROVERSION_ENVIRON, '-'),
|
||||||
}
|
}
|
||||||
LOG.info(self.format, log_format)
|
LOG.info(self.format, log_format)
|
||||||
|
@ -28,6 +28,6 @@ GET_USAGES_SCHEMA_1_9 = {
|
|||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"project_id"
|
"project_id"
|
||||||
],
|
],
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
}
|
}
|
||||||
|
@ -369,17 +369,17 @@ class TestAllocationListCreateDelete(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# First create a allocation to consume full_rp's resource.
|
# First create a allocation to consume full_rp's resource.
|
||||||
alloc_list = [
|
alloc_list = [
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=full_rp,
|
resource_provider=full_rp,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=12),
|
used=12),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=full_rp,
|
resource_provider=full_rp,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=1024)
|
used=1024)
|
||||||
]
|
]
|
||||||
alloc_obj.replace_all(self.ctx, alloc_list)
|
alloc_obj.replace_all(self.ctx, alloc_list)
|
||||||
|
|
||||||
# Create a consumer representing the second instance
|
# Create a consumer representing the second instance
|
||||||
@ -391,27 +391,27 @@ class TestAllocationListCreateDelete(tb.PlacementDbBaseTestCase):
|
|||||||
# Create an allocation list consisting of valid requests and an invalid
|
# Create an allocation list consisting of valid requests and an invalid
|
||||||
# request exceeding the memory full_rp can provide.
|
# request exceeding the memory full_rp can provide.
|
||||||
alloc_list = [
|
alloc_list = [
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst2_consumer,
|
consumer=inst2_consumer,
|
||||||
resource_provider=empty_rp,
|
resource_provider=empty_rp,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=12),
|
used=12),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst2_consumer,
|
consumer=inst2_consumer,
|
||||||
resource_provider=empty_rp,
|
resource_provider=empty_rp,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=512),
|
used=512),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst2_consumer,
|
consumer=inst2_consumer,
|
||||||
resource_provider=full_rp,
|
resource_provider=full_rp,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=12),
|
used=12),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst2_consumer,
|
consumer=inst2_consumer,
|
||||||
resource_provider=full_rp,
|
resource_provider=full_rp,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=512),
|
used=512),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertRaises(exception.InvalidAllocationCapacityExceeded,
|
self.assertRaises(exception.InvalidAllocationCapacityExceeded,
|
||||||
alloc_obj.replace_all, self.ctx, alloc_list)
|
alloc_obj.replace_all, self.ctx, alloc_list)
|
||||||
@ -449,17 +449,17 @@ class TestAllocationListCreateDelete(tb.PlacementDbBaseTestCase):
|
|||||||
inst_consumer.create()
|
inst_consumer.create()
|
||||||
|
|
||||||
alloc_list = [
|
alloc_list = [
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=rp1,
|
resource_provider=rp1,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=12),
|
used=12),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=rp1,
|
resource_provider=rp1,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=1024)
|
used=1024)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Make sure the right exception happens when the retry loop expires.
|
# Make sure the right exception happens when the retry loop expires.
|
||||||
with mock.patch.object(alloc_obj, 'RP_CONFLICT_RETRY_COUNT', 0):
|
with mock.patch.object(alloc_obj, 'RP_CONFLICT_RETRY_COUNT', 0):
|
||||||
|
@ -149,9 +149,9 @@ class ProviderDBHelperTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
empty_root_id = None
|
empty_root_id = None
|
||||||
|
|
||||||
# Run it!
|
# Run it!
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
empty_req_traits, empty_forbidden_traits, empty_agg,
|
self.ctx, resources, empty_req_traits, empty_forbidden_traits,
|
||||||
empty_root_id)
|
empty_agg, empty_root_id)
|
||||||
|
|
||||||
# We should get all the incl_* RPs
|
# We should get all the incl_* RPs
|
||||||
expected = [incl_biginv_noalloc, incl_extra_full]
|
expected = [incl_biginv_noalloc, incl_extra_full]
|
||||||
@ -165,39 +165,44 @@ class ProviderDBHelperTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# _get_provider_ids_matching()'s required_traits and forbidden_traits
|
# _get_provider_ids_matching()'s required_traits and forbidden_traits
|
||||||
# arguments maps, keyed by trait name, of the trait internal ID
|
# arguments maps, keyed by trait name, of the trait internal ID
|
||||||
req_traits = {os_traits.HW_CPU_X86_AVX2: avx2_t.id}
|
req_traits = {os_traits.HW_CPU_X86_AVX2: avx2_t.id}
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
req_traits, empty_forbidden_traits, empty_agg, empty_root_id)
|
self.ctx, resources, req_traits, empty_forbidden_traits, empty_agg,
|
||||||
|
empty_root_id)
|
||||||
|
|
||||||
self.assertEqual([], res)
|
self.assertEqual([], res)
|
||||||
|
|
||||||
# Next let's set the required trait to an excl_* RPs.
|
# Next let's set the required trait to an excl_* RPs.
|
||||||
# This should result in no results returned as well.
|
# This should result in no results returned as well.
|
||||||
excl_big_md_noalloc.set_traits([avx2_t])
|
excl_big_md_noalloc.set_traits([avx2_t])
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
req_traits, empty_forbidden_traits, empty_agg, empty_root_id)
|
self.ctx, resources, req_traits, empty_forbidden_traits, empty_agg,
|
||||||
|
empty_root_id)
|
||||||
self.assertEqual([], res)
|
self.assertEqual([], res)
|
||||||
|
|
||||||
# OK, now add the trait to one of the incl_* providers and verify that
|
# OK, now add the trait to one of the incl_* providers and verify that
|
||||||
# provider now shows up in our results
|
# provider now shows up in our results
|
||||||
incl_biginv_noalloc.set_traits([avx2_t])
|
incl_biginv_noalloc.set_traits([avx2_t])
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
req_traits, empty_forbidden_traits, empty_agg, empty_root_id)
|
self.ctx, resources, req_traits, empty_forbidden_traits, empty_agg,
|
||||||
|
empty_root_id)
|
||||||
|
|
||||||
rp_ids = [r[0] for r in res]
|
rp_ids = [r[0] for r in res]
|
||||||
self.assertEqual([incl_biginv_noalloc.id], rp_ids)
|
self.assertEqual([incl_biginv_noalloc.id], rp_ids)
|
||||||
|
|
||||||
# Let's see if the tree_root_id filter works
|
# Let's see if the tree_root_id filter works
|
||||||
root_id = incl_biginv_noalloc.id
|
root_id = incl_biginv_noalloc.id
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
empty_req_traits, empty_forbidden_traits, empty_agg, root_id)
|
self.ctx, resources, empty_req_traits, empty_forbidden_traits,
|
||||||
|
empty_agg, root_id)
|
||||||
rp_ids = [r[0] for r in res]
|
rp_ids = [r[0] for r in res]
|
||||||
self.assertEqual([incl_biginv_noalloc.id], rp_ids)
|
self.assertEqual([incl_biginv_noalloc.id], rp_ids)
|
||||||
|
|
||||||
# We don't get anything if the specified tree doesn't satisfy the
|
# We don't get anything if the specified tree doesn't satisfy the
|
||||||
# requirements in the first place
|
# requirements in the first place
|
||||||
root_id = excl_allused.id
|
root_id = excl_allused.id
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
empty_req_traits, empty_forbidden_traits, empty_agg, root_id)
|
self.ctx, resources, empty_req_traits, empty_forbidden_traits,
|
||||||
|
empty_agg, root_id)
|
||||||
self.assertEqual([], res)
|
self.assertEqual([], res)
|
||||||
|
|
||||||
def test_get_provider_ids_matching_with_multiple_forbidden(self):
|
def test_get_provider_ids_matching_with_multiple_forbidden(self):
|
||||||
@ -219,8 +224,9 @@ class ProviderDBHelperTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
member_of = [[uuids.agg1]]
|
member_of = [[uuids.agg1]]
|
||||||
empty_root_id = None
|
empty_root_id = None
|
||||||
|
|
||||||
res = rp_obj._get_provider_ids_matching(self.ctx, resources,
|
res = rp_obj._get_provider_ids_matching(
|
||||||
empty_req_traits, forbidden_traits, member_of, empty_root_id)
|
self.ctx, resources, empty_req_traits, forbidden_traits, member_of,
|
||||||
|
empty_root_id)
|
||||||
self.assertEqual({(rp1.id, rp1.id)}, set(res))
|
self.assertEqual({(rp1.id, rp1.id)}, set(res))
|
||||||
|
|
||||||
def test_get_provider_ids_having_all_traits(self):
|
def test_get_provider_ids_having_all_traits(self):
|
||||||
@ -1089,8 +1095,8 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
for cn in (cn1, cn2, cn3):
|
for cn in (cn1, cn2, cn3):
|
||||||
tb.set_traits(cn, os_traits.HW_CPU_X86_AVX2)
|
tb.set_traits(cn, os_traits.HW_CPU_X86_AVX2)
|
||||||
|
|
||||||
alloc_cands = self._get_allocation_candidates(requests={'':
|
alloc_cands = self._get_allocation_candidates(
|
||||||
placement_lib.RequestGroup(
|
requests={'': placement_lib.RequestGroup(
|
||||||
use_same_provider=False,
|
use_same_provider=False,
|
||||||
resources=self.requested_resources,
|
resources=self.requested_resources,
|
||||||
required_traits=set([os_traits.HW_CPU_X86_AVX2]),
|
required_traits=set([os_traits.HW_CPU_X86_AVX2]),
|
||||||
@ -1137,16 +1143,15 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
tb.set_traits(cn3, os_traits.HW_CPU_X86_AVX2,
|
tb.set_traits(cn3, os_traits.HW_CPU_X86_AVX2,
|
||||||
os_traits.STORAGE_DISK_SSD)
|
os_traits.STORAGE_DISK_SSD)
|
||||||
|
|
||||||
alloc_cands = self._get_allocation_candidates(
|
alloc_cands = self._get_allocation_candidates({
|
||||||
{'':
|
'': placement_lib.RequestGroup(
|
||||||
placement_lib.RequestGroup(
|
|
||||||
use_same_provider=False,
|
use_same_provider=False,
|
||||||
resources=self.requested_resources,
|
resources=self.requested_resources,
|
||||||
required_traits=set([
|
required_traits=set([
|
||||||
os_traits.HW_CPU_X86_AVX2, os_traits.STORAGE_DISK_SSD
|
os_traits.HW_CPU_X86_AVX2, os_traits.STORAGE_DISK_SSD
|
||||||
]),
|
]),
|
||||||
)}
|
)
|
||||||
)
|
})
|
||||||
|
|
||||||
# There should be only cn3 in the returned allocation candidates
|
# There should be only cn3 in the returned allocation candidates
|
||||||
expected = [
|
expected = [
|
||||||
@ -1273,9 +1278,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# CUSTOM_RAID traits.
|
# CUSTOM_RAID traits.
|
||||||
# expected = []
|
# expected = []
|
||||||
expected = [
|
expected = [
|
||||||
[('cn', orc.VCPU, 1),
|
[('cn', orc.VCPU, 1),
|
||||||
('cn', orc.MEMORY_MB, 64),
|
('cn', orc.MEMORY_MB, 64),
|
||||||
('ss', orc.DISK_GB, 1500)],
|
('ss', orc.DISK_GB, 1500)],
|
||||||
]
|
]
|
||||||
self._validate_allocation_requests(expected, alloc_cands)
|
self._validate_allocation_requests(expected, alloc_cands)
|
||||||
|
|
||||||
@ -2213,18 +2218,18 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# function with the required trait no longer has any inventory.
|
# function with the required trait no longer has any inventory.
|
||||||
self.allocate_from_provider(pf1, orc.SRIOV_NET_VF, 8)
|
self.allocate_from_provider(pf1, orc.SRIOV_NET_VF, 8)
|
||||||
|
|
||||||
alloc_cands = self._get_allocation_candidates(
|
alloc_cands = self._get_allocation_candidates({
|
||||||
{'':
|
'':
|
||||||
placement_lib.RequestGroup(
|
placement_lib.RequestGroup(
|
||||||
use_same_provider=False,
|
use_same_provider=False,
|
||||||
resources={
|
resources={
|
||||||
orc.VCPU: 2,
|
orc.VCPU: 2,
|
||||||
orc.MEMORY_MB: 256,
|
orc.MEMORY_MB: 256,
|
||||||
orc.SRIOV_NET_VF: 1,
|
orc.SRIOV_NET_VF: 1,
|
||||||
},
|
},
|
||||||
required_traits=[os_traits.HW_NIC_OFFLOAD_GENEVE],
|
required_traits=[os_traits.HW_NIC_OFFLOAD_GENEVE],
|
||||||
)}
|
)
|
||||||
)
|
})
|
||||||
|
|
||||||
self._validate_allocation_requests([], alloc_cands)
|
self._validate_allocation_requests([], alloc_cands)
|
||||||
self._validate_provider_summary_resources({}, alloc_cands)
|
self._validate_provider_summary_resources({}, alloc_cands)
|
||||||
@ -2263,8 +2268,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# Before we even set up any providers, verify that the short-circuits
|
# Before we even set up any providers, verify that the short-circuits
|
||||||
# work to return empty lists
|
# work to return empty lists
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
self.assertEqual([], trees)
|
self.assertEqual([], trees)
|
||||||
|
|
||||||
# We are setting up 3 trees of providers that look like this:
|
# We are setting up 3 trees of providers that look like this:
|
||||||
@ -2307,8 +2313,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# has inventory we will use...
|
# has inventory we will use...
|
||||||
tb.set_traits(cn, os_traits.HW_NIC_OFFLOAD_GENEVE)
|
tb.set_traits(cn, os_traits.HW_NIC_OFFLOAD_GENEVE)
|
||||||
|
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
# trees is an instance of `RPCandidateList`.
|
# trees is an instance of `RPCandidateList`.
|
||||||
# extract root provider ids from here.
|
# extract root provider ids from here.
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
@ -2325,8 +2332,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# Let's see if the tree_root_id filter works
|
# Let's see if the tree_root_id filter works
|
||||||
tree_root_id = self.get_provider_id_by_name('cn1')
|
tree_root_id = self.get_provider_id_by_name('cn1')
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
self.assertEqual(1, len(tree_root_ids))
|
self.assertEqual(1, len(tree_root_ids))
|
||||||
|
|
||||||
@ -2349,8 +2357,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
uuids.cn2_numa1_pf1)
|
uuids.cn2_numa1_pf1)
|
||||||
self.allocate_from_provider(cn2_pf1, orc.SRIOV_NET_VF, 8)
|
self.allocate_from_provider(cn2_pf1, orc.SRIOV_NET_VF, 8)
|
||||||
|
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
self.assertEqual(2, len(tree_root_ids))
|
self.assertEqual(2, len(tree_root_ids))
|
||||||
|
|
||||||
@ -2378,8 +2387,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
req_traits = {
|
req_traits = {
|
||||||
geneve_t.name: geneve_t.id,
|
geneve_t.name: geneve_t.id,
|
||||||
}
|
}
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
self.assertEqual(1, len(tree_root_ids))
|
self.assertEqual(1, len(tree_root_ids))
|
||||||
|
|
||||||
@ -2409,8 +2419,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
geneve_t.name: geneve_t.id,
|
geneve_t.name: geneve_t.id,
|
||||||
avx2_t.name: avx2_t.id,
|
avx2_t.name: avx2_t.id,
|
||||||
}
|
}
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
self.assertEqual(0, len(tree_root_ids))
|
self.assertEqual(0, len(tree_root_ids))
|
||||||
|
|
||||||
@ -2422,8 +2433,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
forbidden_traits = {
|
forbidden_traits = {
|
||||||
avx2_t.name: avx2_t.id,
|
avx2_t.name: avx2_t.id,
|
||||||
}
|
}
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
tree_root_ids = trees.trees
|
tree_root_ids = trees.trees
|
||||||
self.assertEqual(1, len(tree_root_ids))
|
self.assertEqual(1, len(tree_root_ids))
|
||||||
|
|
||||||
@ -2461,8 +2473,9 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
uuids.cn3_numa1_pf1)
|
uuids.cn3_numa1_pf1)
|
||||||
self.allocate_from_provider(cn3_pf1, orc.SRIOV_NET_VF, 8)
|
self.allocate_from_provider(cn3_pf1, orc.SRIOV_NET_VF, 8)
|
||||||
|
|
||||||
trees = rp_obj._get_trees_matching_all(self.ctx, resources, req_traits,
|
trees = rp_obj._get_trees_matching_all(
|
||||||
forbidden_traits, sharing, member_of, tree_root_id)
|
self.ctx, resources, req_traits, forbidden_traits, sharing,
|
||||||
|
member_of, tree_root_id)
|
||||||
self.assertEqual([], trees)
|
self.assertEqual([], trees)
|
||||||
|
|
||||||
def test_simple_tree_with_shared_provider(self):
|
def test_simple_tree_with_shared_provider(self):
|
||||||
@ -2528,16 +2541,15 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
tb.set_traits(ss1, 'MISC_SHARES_VIA_AGGREGATE')
|
tb.set_traits(ss1, 'MISC_SHARES_VIA_AGGREGATE')
|
||||||
tb.set_traits(ss2, 'MISC_SHARES_VIA_AGGREGATE')
|
tb.set_traits(ss2, 'MISC_SHARES_VIA_AGGREGATE')
|
||||||
|
|
||||||
alloc_cands = self._get_allocation_candidates(
|
alloc_cands = self._get_allocation_candidates({
|
||||||
{'': placement_lib.RequestGroup(
|
'': placement_lib.RequestGroup(
|
||||||
use_same_provider=False,
|
use_same_provider=False,
|
||||||
resources={
|
resources={
|
||||||
orc.VCPU: 2,
|
orc.VCPU: 2,
|
||||||
orc.SRIOV_NET_VF: 1,
|
orc.SRIOV_NET_VF: 1,
|
||||||
orc.DISK_GB: 1500,
|
orc.DISK_GB: 1500,
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
# cn2 is not in the allocation candidates because it doesn't have
|
# cn2 is not in the allocation candidates because it doesn't have
|
||||||
# enough DISK_GB resource with shared providers.
|
# enough DISK_GB resource with shared providers.
|
||||||
@ -2572,8 +2584,8 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# Now add required traits to the mix and verify we still get the
|
# Now add required traits to the mix and verify we still get the
|
||||||
# inventory of SRIOV_NET_VF.
|
# inventory of SRIOV_NET_VF.
|
||||||
alloc_cands = self._get_allocation_candidates(
|
alloc_cands = self._get_allocation_candidates({
|
||||||
{'': placement_lib.RequestGroup(
|
'': placement_lib.RequestGroup(
|
||||||
use_same_provider=False,
|
use_same_provider=False,
|
||||||
resources={
|
resources={
|
||||||
orc.VCPU: 2,
|
orc.VCPU: 2,
|
||||||
@ -2581,8 +2593,7 @@ class AllocationCandidatesTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
orc.DISK_GB: 1500,
|
orc.DISK_GB: 1500,
|
||||||
},
|
},
|
||||||
required_traits=[os_traits.HW_NIC_OFFLOAD_GENEVE])
|
required_traits=[os_traits.HW_NIC_OFFLOAD_GENEVE])
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
# cn1_numa0_pf0 is not in the allocation candidates because it
|
# cn1_numa0_pf0 is not in the allocation candidates because it
|
||||||
# doesn't have the required trait.
|
# doesn't have the required trait.
|
||||||
|
@ -146,8 +146,8 @@ class PlacementDbBaseTestCase(base.TestCase):
|
|||||||
consumer_id = alloc_dict.pop('consumer_id')
|
consumer_id = alloc_dict.pop('consumer_id')
|
||||||
consumer = ensure_consumer(
|
consumer = ensure_consumer(
|
||||||
self.ctx, self.user_obj, self.project_obj, consumer_id)
|
self.ctx, self.user_obj, self.project_obj, consumer_id)
|
||||||
alloc = alloc_obj.Allocation(resource_provider=rp,
|
alloc = alloc_obj.Allocation(
|
||||||
consumer=consumer, **alloc_dict)
|
resource_provider=rp, consumer=consumer, **alloc_dict)
|
||||||
alloc_obj.replace_all(self.ctx, [alloc])
|
alloc_obj.replace_all(self.ctx, [alloc])
|
||||||
return rp, alloc
|
return rp, alloc
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ ALLOC_TBL = rp_obj._ALLOC_TBL
|
|||||||
|
|
||||||
class ConsumerTestCase(tb.PlacementDbBaseTestCase):
|
class ConsumerTestCase(tb.PlacementDbBaseTestCase):
|
||||||
def test_non_existing_consumer(self):
|
def test_non_existing_consumer(self):
|
||||||
self.assertRaises(exception.ConsumerNotFound,
|
self.assertRaises(
|
||||||
|
exception.ConsumerNotFound,
|
||||||
consumer_obj.Consumer.get_by_uuid, self.ctx,
|
consumer_obj.Consumer.get_by_uuid, self.ctx,
|
||||||
uuids.non_existing_consumer)
|
uuids.non_existing_consumer)
|
||||||
|
|
||||||
|
@ -189,9 +189,9 @@ class PostgresqlOpportunisticFixture(
|
|||||||
|
|
||||||
|
|
||||||
class TestMigrationsSQLite(MigrationCheckersMixin,
|
class TestMigrationsSQLite(MigrationCheckersMixin,
|
||||||
WalkVersionsMixin,
|
WalkVersionsMixin,
|
||||||
test_fixtures.OpportunisticDBTestMixin,
|
test_fixtures.OpportunisticDBTestMixin,
|
||||||
test_base.BaseTestCase):
|
test_base.BaseTestCase):
|
||||||
FIXTURE = SQLiteOpportunisticFixture
|
FIXTURE = SQLiteOpportunisticFixture
|
||||||
|
|
||||||
|
|
||||||
@ -233,6 +233,6 @@ class ModelsMigrationsSyncMysql(_TestModelsMigrations,
|
|||||||
|
|
||||||
|
|
||||||
class ModelsMigrationsSyncPostgresql(_TestModelsMigrations,
|
class ModelsMigrationsSyncPostgresql(_TestModelsMigrations,
|
||||||
test_fixtures.OpportunisticDBTestMixin,
|
test_fixtures.OpportunisticDBTestMixin,
|
||||||
test_base.BaseTestCase):
|
test_base.BaseTestCase):
|
||||||
FIXTURE = PostgresqlOpportunisticFixture
|
FIXTURE = PostgresqlOpportunisticFixture
|
||||||
|
@ -339,10 +339,9 @@ class ReshapeTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# Reduce the amount of storage to 2000, from 100000.
|
# Reduce the amount of storage to 2000, from 100000.
|
||||||
new_ss_inv = rp_obj.InventoryList(objects=[
|
new_ss_inv = rp_obj.InventoryList(objects=[
|
||||||
rp_obj.Inventory(
|
rp_obj.Inventory(
|
||||||
resource_provider=ss_threadB,
|
resource_provider=ss_threadB, resource_class='DISK_GB',
|
||||||
resource_class='DISK_GB', total=2000, reserved=0,
|
total=2000, reserved=0, max_unit=1000, min_unit=1, step_size=1,
|
||||||
max_unit=1000, min_unit=1, step_size=1,
|
allocation_ratio=1.0)])
|
||||||
allocation_ratio=1.0)])
|
|
||||||
ss_threadB.set_inventory(new_ss_inv)
|
ss_threadB.set_inventory(new_ss_inv)
|
||||||
# Double check our storage provider's generation is now greater than
|
# Double check our storage provider's generation is now greater than
|
||||||
# the original storage provider record being sent to reshape()
|
# the original storage provider record being sent to reshape()
|
||||||
|
@ -40,8 +40,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
self.ctx, [])
|
self.ctx, [])
|
||||||
|
|
||||||
def test_create_resource_provider_requires_uuid(self):
|
def test_create_resource_provider_requires_uuid(self):
|
||||||
resource_provider = rp_obj.ResourceProvider(
|
resource_provider = rp_obj.ResourceProvider(context=self.ctx)
|
||||||
context = self.ctx)
|
|
||||||
self.assertRaises(exception.ObjectActionError,
|
self.assertRaises(exception.ObjectActionError,
|
||||||
resource_provider.create)
|
resource_provider.create)
|
||||||
|
|
||||||
@ -645,7 +644,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
saved_generation = rp.generation
|
saved_generation = rp.generation
|
||||||
|
|
||||||
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
self.assertEqual(2, len(new_inv_list))
|
self.assertEqual(2, len(new_inv_list))
|
||||||
resource_classes = [inv.resource_class for inv in new_inv_list]
|
resource_classes = [inv.resource_class for inv in new_inv_list]
|
||||||
self.assertIn(orc.VCPU, resource_classes)
|
self.assertIn(orc.VCPU, resource_classes)
|
||||||
@ -660,7 +659,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
saved_generation = rp.generation
|
saved_generation = rp.generation
|
||||||
|
|
||||||
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
self.assertEqual(1, len(new_inv_list))
|
self.assertEqual(1, len(new_inv_list))
|
||||||
resource_classes = [inv.resource_class for inv in new_inv_list]
|
resource_classes = [inv.resource_class for inv in new_inv_list]
|
||||||
self.assertNotIn(orc.VCPU, resource_classes)
|
self.assertNotIn(orc.VCPU, resource_classes)
|
||||||
@ -669,14 +668,14 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# update existing disk inv to new settings
|
# update existing disk inv to new settings
|
||||||
disk_inv = rp_obj.Inventory(
|
disk_inv = rp_obj.Inventory(
|
||||||
resource_provider=rp,
|
resource_provider=rp,
|
||||||
resource_class=orc.DISK_GB,
|
resource_class=orc.DISK_GB,
|
||||||
total=2048,
|
total=2048,
|
||||||
reserved=15,
|
reserved=15,
|
||||||
min_unit=10,
|
min_unit=10,
|
||||||
max_unit=100,
|
max_unit=100,
|
||||||
step_size=10,
|
step_size=10,
|
||||||
allocation_ratio=1.0)
|
allocation_ratio=1.0)
|
||||||
rp.update_inventory(disk_inv)
|
rp.update_inventory(disk_inv)
|
||||||
|
|
||||||
# generation has bumped
|
# generation has bumped
|
||||||
@ -684,7 +683,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
saved_generation = rp.generation
|
saved_generation = rp.generation
|
||||||
|
|
||||||
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
self.assertEqual(1, len(new_inv_list))
|
self.assertEqual(1, len(new_inv_list))
|
||||||
self.assertEqual(2048, new_inv_list[0].total)
|
self.assertEqual(2048, new_inv_list[0].total)
|
||||||
|
|
||||||
@ -696,7 +695,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
saved_generation = rp.generation
|
saved_generation = rp.generation
|
||||||
|
|
||||||
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
new_inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
result = new_inv_list.find(orc.DISK_GB)
|
result = new_inv_list.find(orc.DISK_GB)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
self.assertRaises(exception.NotFound, rp.delete_inventory,
|
self.assertRaises(exception.NotFound, rp.delete_inventory,
|
||||||
@ -704,13 +703,13 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
|
|
||||||
# check inventory list is empty
|
# check inventory list is empty
|
||||||
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
self.assertEqual(0, len(inv_list))
|
self.assertEqual(0, len(inv_list))
|
||||||
|
|
||||||
# add some inventory
|
# add some inventory
|
||||||
rp.add_inventory(vcpu_inv)
|
rp.add_inventory(vcpu_inv)
|
||||||
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
inv_list = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp)
|
self.ctx, rp)
|
||||||
self.assertEqual(1, len(inv_list))
|
self.assertEqual(1, len(inv_list))
|
||||||
|
|
||||||
# generation has bumped
|
# generation has bumped
|
||||||
@ -803,7 +802,7 @@ class ResourceProviderTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# Get inventories for the first resource provider and validate
|
# Get inventories for the first resource provider and validate
|
||||||
# the inventory records have a matching resource provider
|
# the inventory records have a matching resource provider
|
||||||
got_inv = rp_obj.InventoryList.get_all_by_resource_provider(
|
got_inv = rp_obj.InventoryList.get_all_by_resource_provider(
|
||||||
self.ctx, rp1)
|
self.ctx, rp1)
|
||||||
for inv in got_inv:
|
for inv in got_inv:
|
||||||
self.assertEqual(rp1.id, inv.resource_provider.id)
|
self.assertEqual(rp1.id, inv.resource_provider.id)
|
||||||
|
|
||||||
@ -855,14 +854,12 @@ class ResourceProviderListTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
# given it has enough disk but we also need to make sure that the
|
# given it has enough disk but we also need to make sure that the
|
||||||
# first RP is not acceptable because of the VCPU request
|
# first RP is not acceptable because of the VCPU request
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, {'resources': {orc.VCPU: 2,
|
self.ctx, {'resources': {orc.VCPU: 2, orc.DISK_GB: 1022}})
|
||||||
orc.DISK_GB: 1022}})
|
|
||||||
self.assertEqual(1, len(resource_providers))
|
self.assertEqual(1, len(resource_providers))
|
||||||
# Now, we are asking for both disk and VCPU resources that all the RPs
|
# Now, we are asking for both disk and VCPU resources that all the RPs
|
||||||
# can't accept (as the 2nd RP is having a reserved size)
|
# can't accept (as the 2nd RP is having a reserved size)
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, {'resources': {orc.VCPU: 2,
|
self.ctx, {'resources': {orc.VCPU: 2, orc.DISK_GB: 1024}})
|
||||||
orc.DISK_GB: 1024}})
|
|
||||||
self.assertEqual(0, len(resource_providers))
|
self.assertEqual(0, len(resource_providers))
|
||||||
|
|
||||||
# We also want to verify that asking for a specific RP can also be
|
# We also want to verify that asking for a specific RP can also be
|
||||||
@ -914,25 +911,25 @@ class ResourceProviderListTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
self.assertNotIn('rp_name_4', names)
|
self.assertNotIn('rp_name_4', names)
|
||||||
|
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, filters={'member_of':
|
self.ctx,
|
||||||
[[uuidsentinel.agg_a, uuidsentinel.agg_b]]})
|
filters={'member_of': [[uuidsentinel.agg_a, uuidsentinel.agg_b]]})
|
||||||
self.assertEqual(2, len(resource_providers))
|
self.assertEqual(2, len(resource_providers))
|
||||||
|
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, filters={'member_of':
|
self.ctx,
|
||||||
[[uuidsentinel.agg_a, uuidsentinel.agg_b]],
|
filters={'member_of': [[uuidsentinel.agg_a, uuidsentinel.agg_b]],
|
||||||
'name': u'rp_name_1'})
|
'name': u'rp_name_1'})
|
||||||
self.assertEqual(1, len(resource_providers))
|
self.assertEqual(1, len(resource_providers))
|
||||||
|
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, filters={'member_of':
|
self.ctx,
|
||||||
[[uuidsentinel.agg_a, uuidsentinel.agg_b]],
|
filters={'member_of': [[uuidsentinel.agg_a, uuidsentinel.agg_b]],
|
||||||
'name': u'barnabas'})
|
'name': u'barnabas'})
|
||||||
self.assertEqual(0, len(resource_providers))
|
self.assertEqual(0, len(resource_providers))
|
||||||
|
|
||||||
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
resource_providers = rp_obj.ResourceProviderList.get_all_by_filters(
|
||||||
self.ctx, filters={'member_of':
|
self.ctx,
|
||||||
[[uuidsentinel.agg_1, uuidsentinel.agg_2]]})
|
filters={'member_of': [[uuidsentinel.agg_1, uuidsentinel.agg_2]]})
|
||||||
self.assertEqual(0, len(resource_providers))
|
self.assertEqual(0, len(resource_providers))
|
||||||
|
|
||||||
def test_get_all_by_required(self):
|
def test_get_all_by_required(self):
|
||||||
@ -1132,8 +1129,9 @@ class TestResourceProviderAggregates(tb.PlacementDbBaseTestCase):
|
|||||||
[(s5.id, rp.id) for rp in (r1, r2, s1, s5)]
|
[(s5.id, rp.id) for rp in (r1, r2, s1, s5)]
|
||||||
)
|
)
|
||||||
self.assertItemsEqual(
|
self.assertItemsEqual(
|
||||||
expected, rp_obj._anchors_for_sharing_providers(self.ctx,
|
expected,
|
||||||
[s1.id, s2.id, s3.id, s4.id, s5.id], get_id=True))
|
rp_obj._anchors_for_sharing_providers(
|
||||||
|
self.ctx, [s1.id, s2.id, s3.id, s4.id, s5.id], get_id=True))
|
||||||
|
|
||||||
|
|
||||||
class TestAllocation(tb.PlacementDbBaseTestCase):
|
class TestAllocation(tb.PlacementDbBaseTestCase):
|
||||||
@ -1216,27 +1214,27 @@ class TestAllocation(tb.PlacementDbBaseTestCase):
|
|||||||
# scheduler has selected cn_dest as the target host and created a
|
# scheduler has selected cn_dest as the target host and created a
|
||||||
# "doubled-up" allocation for the duration of the move operation
|
# "doubled-up" allocation for the duration of the move operation
|
||||||
alloc_list = [
|
alloc_list = [
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_source,
|
resource_provider=cn_source,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=1),
|
used=1),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_source,
|
resource_provider=cn_source,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=256),
|
used=256),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_dest,
|
resource_provider=cn_dest,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=1),
|
used=1),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_dest,
|
resource_provider=cn_dest,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=256),
|
used=256),
|
||||||
]
|
]
|
||||||
alloc_obj.replace_all(self.ctx, alloc_list)
|
alloc_obj.replace_all(self.ctx, alloc_list)
|
||||||
|
|
||||||
src_allocs = alloc_obj.get_all_by_resource_provider(
|
src_allocs = alloc_obj.get_all_by_resource_provider(
|
||||||
@ -1260,17 +1258,17 @@ class TestAllocation(tb.PlacementDbBaseTestCase):
|
|||||||
# removes any resources that refer to itself and saves the allocation
|
# removes any resources that refer to itself and saves the allocation
|
||||||
# back to placement
|
# back to placement
|
||||||
new_alloc_list = [
|
new_alloc_list = [
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_dest,
|
resource_provider=cn_dest,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
used=1),
|
used=1),
|
||||||
alloc_obj.Allocation(
|
alloc_obj.Allocation(
|
||||||
consumer=inst_consumer,
|
consumer=inst_consumer,
|
||||||
resource_provider=cn_dest,
|
resource_provider=cn_dest,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
used=256),
|
used=256),
|
||||||
]
|
]
|
||||||
alloc_obj.replace_all(self.ctx, new_alloc_list)
|
alloc_obj.replace_all(self.ctx, new_alloc_list)
|
||||||
|
|
||||||
src_allocs = alloc_obj.get_all_by_resource_provider(
|
src_allocs = alloc_obj.get_all_by_resource_provider(
|
||||||
@ -1600,7 +1598,8 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
self.assertEqual(t.name, 'CUSTOM_TRAIT_A')
|
self.assertEqual(t.name, 'CUSTOM_TRAIT_A')
|
||||||
|
|
||||||
def test_trait_get_non_existed_trait(self):
|
def test_trait_get_non_existed_trait(self):
|
||||||
self.assertRaises(exception.TraitNotFound,
|
self.assertRaises(
|
||||||
|
exception.TraitNotFound,
|
||||||
rp_obj.Trait.get_by_name, self.ctx, 'CUSTOM_TRAIT_A')
|
rp_obj.Trait.get_by_name, self.ctx, 'CUSTOM_TRAIT_A')
|
||||||
|
|
||||||
def test_bug_1760322(self):
|
def test_bug_1760322(self):
|
||||||
@ -1652,12 +1651,14 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
t.name = name
|
t.name = name
|
||||||
t.create()
|
t.create()
|
||||||
|
|
||||||
traits = rp_obj.TraitList.get_all(self.ctx,
|
traits = rp_obj.TraitList.get_all(
|
||||||
|
self.ctx,
|
||||||
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
||||||
self._assert_traits(['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B'], traits)
|
self._assert_traits(['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B'], traits)
|
||||||
|
|
||||||
def test_traits_get_all_with_non_existed_name(self):
|
def test_traits_get_all_with_non_existed_name(self):
|
||||||
traits = rp_obj.TraitList.get_all(self.ctx,
|
traits = rp_obj.TraitList.get_all(
|
||||||
|
self.ctx,
|
||||||
filters={'name_in': ['CUSTOM_TRAIT_X', 'CUSTOM_TRAIT_Y']})
|
filters={'name_in': ['CUSTOM_TRAIT_X', 'CUSTOM_TRAIT_Y']})
|
||||||
self.assertEqual(0, len(traits))
|
self.assertEqual(0, len(traits))
|
||||||
|
|
||||||
@ -1668,15 +1669,15 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
t.name = name
|
t.name = name
|
||||||
t.create()
|
t.create()
|
||||||
|
|
||||||
traits = rp_obj.TraitList.get_all(self.ctx,
|
traits = rp_obj.TraitList.get_all(
|
||||||
filters={'prefix': 'CUSTOM'})
|
self.ctx, filters={'prefix': 'CUSTOM'})
|
||||||
self._assert_traits(
|
self._assert_traits(
|
||||||
['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B', 'CUSTOM_TRAIT_C'],
|
['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B', 'CUSTOM_TRAIT_C'],
|
||||||
traits)
|
traits)
|
||||||
|
|
||||||
def test_traits_get_all_with_non_existed_prefix(self):
|
def test_traits_get_all_with_non_existed_prefix(self):
|
||||||
traits = rp_obj.TraitList.get_all(self.ctx,
|
traits = rp_obj.TraitList.get_all(
|
||||||
filters={"prefix": "NOT_EXISTED"})
|
self.ctx, filters={"prefix": "NOT_EXISTED"})
|
||||||
self.assertEqual(0, len(traits))
|
self.assertEqual(0, len(traits))
|
||||||
|
|
||||||
def test_set_traits_for_resource_provider(self):
|
def test_set_traits_for_resource_provider(self):
|
||||||
@ -1693,8 +1694,8 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
generation = rp.generation
|
generation = rp.generation
|
||||||
|
|
||||||
trait_names.remove('CUSTOM_TRAIT_A')
|
trait_names.remove('CUSTOM_TRAIT_A')
|
||||||
updated_traits = rp_obj.TraitList.get_all(self.ctx,
|
updated_traits = rp_obj.TraitList.get_all(
|
||||||
filters={'name_in': trait_names})
|
self.ctx, filters={'name_in': trait_names})
|
||||||
self._assert_traits(trait_names, updated_traits)
|
self._assert_traits(trait_names, updated_traits)
|
||||||
tb.set_traits(rp, *trait_names)
|
tb.set_traits(rp, *trait_names)
|
||||||
rp_traits = rp_obj.TraitList.get_all_by_resource_provider(self.ctx, rp)
|
rp_traits = rp_obj.TraitList.get_all_by_resource_provider(self.ctx, rp)
|
||||||
@ -1748,13 +1749,14 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
t.name = name
|
t.name = name
|
||||||
t.create()
|
t.create()
|
||||||
|
|
||||||
associated_traits = rp_obj.TraitList.get_all(self.ctx,
|
associated_traits = rp_obj.TraitList.get_all(
|
||||||
|
self.ctx,
|
||||||
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
||||||
rp1.set_traits(associated_traits)
|
rp1.set_traits(associated_traits)
|
||||||
rp2.set_traits(associated_traits)
|
rp2.set_traits(associated_traits)
|
||||||
self._assert_traits(['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B'],
|
self._assert_traits(
|
||||||
rp_obj.TraitList.get_all(self.ctx,
|
['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B'],
|
||||||
filters={'associated': True}))
|
rp_obj.TraitList.get_all(self.ctx, filters={'associated': True}))
|
||||||
|
|
||||||
def test_traits_get_all_with_associated_false(self):
|
def test_traits_get_all_with_associated_false(self):
|
||||||
rp1 = self._create_provider('fake_resource_provider1')
|
rp1 = self._create_provider('fake_resource_provider1')
|
||||||
@ -1765,13 +1767,14 @@ class ResourceProviderTraitTestCase(tb.PlacementDbBaseTestCase):
|
|||||||
t.name = name
|
t.name = name
|
||||||
t.create()
|
t.create()
|
||||||
|
|
||||||
associated_traits = rp_obj.TraitList.get_all(self.ctx,
|
associated_traits = rp_obj.TraitList.get_all(
|
||||||
|
self.ctx,
|
||||||
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
filters={'name_in': ['CUSTOM_TRAIT_A', 'CUSTOM_TRAIT_B']})
|
||||||
rp1.set_traits(associated_traits)
|
rp1.set_traits(associated_traits)
|
||||||
rp2.set_traits(associated_traits)
|
rp2.set_traits(associated_traits)
|
||||||
self._assert_traits_in(['CUSTOM_TRAIT_C'],
|
self._assert_traits_in(
|
||||||
rp_obj.TraitList.get_all(self.ctx,
|
['CUSTOM_TRAIT_C'],
|
||||||
filters={'associated': False}))
|
rp_obj.TraitList.get_all(self.ctx, filters={'associated': False}))
|
||||||
|
|
||||||
|
|
||||||
class SharedProviderTestCase(tb.PlacementDbBaseTestCase):
|
class SharedProviderTestCase(tb.PlacementDbBaseTestCase):
|
||||||
|
@ -52,10 +52,9 @@ class TestCommandParsers(testtools.TestCase):
|
|||||||
('db_sync', ['db', 'sync']),
|
('db_sync', ['db', 'sync']),
|
||||||
('db_stamp', ['db', 'stamp', 'b4ed3a175331']),
|
('db_stamp', ['db', 'stamp', 'b4ed3a175331']),
|
||||||
('db_online_data_migrations',
|
('db_online_data_migrations',
|
||||||
['db', 'online_data_migrations']),
|
['db', 'online_data_migrations'])]:
|
||||||
]:
|
with mock.patch('placement.cmd.manage.DbCommands.' +
|
||||||
with mock.patch('placement.cmd.manage.DbCommands.'
|
command) as mock_command:
|
||||||
+ command) as mock_command:
|
|
||||||
self.conf(args, default_config_files=[])
|
self.conf(args, default_config_files=[])
|
||||||
self.conf.command.func()
|
self.conf.command.func()
|
||||||
mock_command.assert_called_once_with()
|
mock_command.assert_called_once_with()
|
||||||
|
@ -72,16 +72,16 @@ class TestAllocationListNoDB(base.TestCase):
|
|||||||
@mock.patch('placement.objects.allocation.'
|
@mock.patch('placement.objects.allocation.'
|
||||||
'_get_allocations_by_provider_id',
|
'_get_allocations_by_provider_id',
|
||||||
return_value=[_ALLOCATION_DB])
|
return_value=[_ALLOCATION_DB])
|
||||||
def test_get_all_by_resource_provider(self, mock_get_allocations_from_db,
|
def test_get_all_by_resource_provider(
|
||||||
mock_create_consumers):
|
self, mock_get_allocations_from_db, mock_create_consumers):
|
||||||
rp = rp_obj.ResourceProvider(self.context,
|
rp = rp_obj.ResourceProvider(self.context,
|
||||||
id=_RESOURCE_PROVIDER_ID,
|
id=_RESOURCE_PROVIDER_ID,
|
||||||
uuid=uuids.resource_provider)
|
uuid=uuids.resource_provider)
|
||||||
allocations = alloc_obj.get_all_by_resource_provider(self.context, rp)
|
allocations = alloc_obj.get_all_by_resource_provider(self.context, rp)
|
||||||
|
|
||||||
self.assertEqual(1, len(allocations))
|
self.assertEqual(1, len(allocations))
|
||||||
mock_get_allocations_from_db.assert_called_once_with(self.context,
|
mock_get_allocations_from_db.assert_called_once_with(
|
||||||
rp.id)
|
self.context, rp.id)
|
||||||
self.assertEqual(_ALLOCATION_DB['used'], allocations[0].used)
|
self.assertEqual(_ALLOCATION_DB['used'], allocations[0].used)
|
||||||
self.assertEqual(_ALLOCATION_DB['created_at'],
|
self.assertEqual(_ALLOCATION_DB['created_at'],
|
||||||
allocations[0].created_at)
|
allocations[0].created_at)
|
||||||
@ -96,7 +96,7 @@ class TestAllocationListNoDB(base.TestCase):
|
|||||||
'_get_allocations_by_consumer_uuid',
|
'_get_allocations_by_consumer_uuid',
|
||||||
return_value=[_ALLOCATION_BY_CONSUMER_DB])
|
return_value=[_ALLOCATION_BY_CONSUMER_DB])
|
||||||
def test_get_all_by_consumer_id(self, mock_get_allocations_from_db,
|
def test_get_all_by_consumer_id(self, mock_get_allocations_from_db,
|
||||||
mock_create_consumer):
|
mock_create_consumer):
|
||||||
allocations = alloc_obj.get_all_by_consumer_id(
|
allocations = alloc_obj.get_all_by_consumer_id(
|
||||||
self.context, uuids.consumer)
|
self.context, uuids.consumer)
|
||||||
|
|
||||||
|
@ -195,7 +195,8 @@ class TestInventoryList(base.TestCase):
|
|||||||
def test_find(self):
|
def test_find(self):
|
||||||
rp = resource_provider.ResourceProvider(
|
rp = resource_provider.ResourceProvider(
|
||||||
self.context, uuid=uuids.rp_uuid)
|
self.context, uuid=uuids.rp_uuid)
|
||||||
inv_list = resource_provider.InventoryList(objects=[
|
inv_list = resource_provider.InventoryList(
|
||||||
|
objects=[
|
||||||
resource_provider.Inventory(
|
resource_provider.Inventory(
|
||||||
resource_provider=rp,
|
resource_provider=rp,
|
||||||
resource_class=orc.VCPU,
|
resource_class=orc.VCPU,
|
||||||
@ -204,7 +205,7 @@ class TestInventoryList(base.TestCase):
|
|||||||
resource_provider=rp,
|
resource_provider=rp,
|
||||||
resource_class=orc.MEMORY_MB,
|
resource_class=orc.MEMORY_MB,
|
||||||
total=10240),
|
total=10240),
|
||||||
])
|
])
|
||||||
|
|
||||||
found = inv_list.find(orc.MEMORY_MB)
|
found = inv_list.find(orc.MEMORY_MB)
|
||||||
self.assertIsNotNone(found)
|
self.assertIsNotNone(found)
|
||||||
|
@ -20,8 +20,8 @@ class TestRPCandidateList(testtools.TestCase):
|
|||||||
super(TestRPCandidateList, self).setUp()
|
super(TestRPCandidateList, self).setUp()
|
||||||
self.rp_candidates = rp_candidates.RPCandidateList()
|
self.rp_candidates = rp_candidates.RPCandidateList()
|
||||||
self.rps_rc1 = set([
|
self.rps_rc1 = set([
|
||||||
('rp1', 'root1'), ('rp2', 'root1'), ('ss1', 'root1'),
|
('rp1', 'root1'), ('rp2', 'root1'), ('ss1', 'root1'),
|
||||||
('rp3', 'root'), ('ss1', 'root')])
|
('rp3', 'root'), ('ss1', 'root')])
|
||||||
self.rp_candidates.add_rps(self.rps_rc1, 'rc_1')
|
self.rp_candidates.add_rps(self.rps_rc1, 'rc_1')
|
||||||
|
|
||||||
def test_property(self):
|
def test_property(self):
|
||||||
|
@ -39,8 +39,9 @@ class DeployTest(testtools.TestCase):
|
|||||||
auth_token_opts = auth_token.AUTH_TOKEN_OPTS[0][1]
|
auth_token_opts = auth_token.AUTH_TOKEN_OPTS[0][1]
|
||||||
conf_fixture.register_opts(auth_token_opts, group='keystone_authtoken')
|
conf_fixture.register_opts(auth_token_opts, group='keystone_authtoken')
|
||||||
www_authenticate_uri = 'http://example.com/identity'
|
www_authenticate_uri = 'http://example.com/identity'
|
||||||
conf_fixture.config(www_authenticate_uri=www_authenticate_uri,
|
conf_fixture.config(
|
||||||
group='keystone_authtoken')
|
www_authenticate_uri=www_authenticate_uri,
|
||||||
|
group='keystone_authtoken')
|
||||||
# ensure that the auth_token middleware is chosen
|
# ensure that the auth_token middleware is chosen
|
||||||
conf_fixture.config(auth_strategy='keystone', group='api')
|
conf_fixture.config(auth_strategy='keystone', group='api')
|
||||||
# register and default policy opts (referenced by deploy)
|
# register and default policy opts (referenced by deploy)
|
||||||
|
@ -62,5 +62,4 @@ class TestFaultWrapper(testtools.TestCase):
|
|||||||
def test_fault_log(self, mocked_log):
|
def test_fault_log(self, mocked_log):
|
||||||
self.fail_app(self.environ, self.start_response_mock)
|
self.fail_app(self.environ, self.start_response_mock)
|
||||||
mocked_log.exception.assert_called_once_with(
|
mocked_log.exception.assert_called_once_with(
|
||||||
'Placement API unexpected error: %s',
|
'Placement API unexpected error: %s', mock.ANY)
|
||||||
mock.ANY)
|
|
||||||
|
@ -147,7 +147,8 @@ class MicroversionSequentialTest(testtools.TestCase):
|
|||||||
previous_min_version = microversion_parse.parse_version_string(
|
previous_min_version = microversion_parse.parse_version_string(
|
||||||
'%s.%s' % (previous_min_version.major,
|
'%s.%s' % (previous_min_version.major,
|
||||||
previous_min_version.minor - 1))
|
previous_min_version.minor - 1))
|
||||||
self.assertEqual(previous_min_version, method[1],
|
self.assertEqual(
|
||||||
|
previous_min_version, method[1],
|
||||||
"The microversions aren't sequential in the mehtod %s" %
|
"The microversions aren't sequential in the mehtod %s" %
|
||||||
method_name)
|
method_name)
|
||||||
previous_min_version = method[0]
|
previous_min_version = method[0]
|
||||||
|
@ -155,7 +155,7 @@ class QueryParamsSchemaTestCase(testtools.TestCase):
|
|||||||
'type': 'object',
|
'type': 'object',
|
||||||
'properties': {
|
'properties': {
|
||||||
'foo': {'type': 'string'}
|
'foo': {'type': 'string'}
|
||||||
},
|
},
|
||||||
'additionalProperties': False}
|
'additionalProperties': False}
|
||||||
req = webob.Request.blank('/test?foo=%88')
|
req = webob.Request.blank('/test?foo=%88')
|
||||||
error = self.assertRaises(webob.exc.HTTPBadRequest,
|
error = self.assertRaises(webob.exc.HTTPBadRequest,
|
||||||
@ -624,11 +624,11 @@ class TestParseQsRequestGroups(testtools.TestCase):
|
|||||||
'CUSTOM_PHYSNET_PROD',
|
'CUSTOM_PHYSNET_PROD',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
pl.RequestGroup(
|
pl.RequestGroup(
|
||||||
resources={
|
resources={
|
||||||
'CUSTOM_MAGIC': 123,
|
'CUSTOM_MAGIC': 123,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
self.assertRequestGroupsEqual(expected, self.do_parse(qs))
|
self.assertRequestGroupsEqual(expected, self.do_parse(qs))
|
||||||
|
|
||||||
@ -762,8 +762,8 @@ class TestParseQsRequestGroups(testtools.TestCase):
|
|||||||
'Conflicting required and forbidden traits found '
|
'Conflicting required and forbidden traits found '
|
||||||
'in the following traits keys: required: (CUSTOM_PHYSNET1)')
|
'in the following traits keys: required: (CUSTOM_PHYSNET1)')
|
||||||
|
|
||||||
exc = self.assertRaises(webob.exc.HTTPBadRequest, self.do_parse, qs,
|
exc = self.assertRaises(
|
||||||
version=(1, 22))
|
webob.exc.HTTPBadRequest, self.do_parse, qs, version=(1, 22))
|
||||||
self.assertEqual(expected_message, six.text_type(exc))
|
self.assertEqual(expected_message, six.text_type(exc))
|
||||||
|
|
||||||
def test_forbidden_two_groups(self):
|
def test_forbidden_two_groups(self):
|
||||||
@ -960,7 +960,7 @@ class RunOnceTests(testtools.TestCase):
|
|||||||
mock_clean = mock.Mock()
|
mock_clean = mock.Mock()
|
||||||
|
|
||||||
@util.run_once("already ran once", self.fake_logger,
|
@util.run_once("already ran once", self.fake_logger,
|
||||||
cleanup=mock_clean)
|
cleanup=mock_clean)
|
||||||
def f():
|
def f():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -975,7 +975,7 @@ class RunOnceTests(testtools.TestCase):
|
|||||||
mock_clean = mock.Mock()
|
mock_clean = mock.Mock()
|
||||||
|
|
||||||
@util.run_once("already ran once", self.fake_logger,
|
@util.run_once("already ran once", self.fake_logger,
|
||||||
cleanup=mock_clean)
|
cleanup=mock_clean)
|
||||||
def f():
|
def f():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -989,7 +989,7 @@ class RunOnceTests(testtools.TestCase):
|
|||||||
mock_clean = mock.Mock(side_effect=ValueError())
|
mock_clean = mock.Mock(side_effect=ValueError())
|
||||||
|
|
||||||
@util.run_once("already ran once", self.fake_logger,
|
@util.run_once("already ran once", self.fake_logger,
|
||||||
cleanup=mock_clean)
|
cleanup=mock_clean)
|
||||||
def f():
|
def f():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def setup_logging(config):
|
|||||||
'routes=INFO',
|
'routes=INFO',
|
||||||
]
|
]
|
||||||
logging.set_defaults(default_log_levels=logging.get_default_log_levels() +
|
logging.set_defaults(default_log_levels=logging.get_default_log_levels() +
|
||||||
extra_log_level_defaults)
|
extra_log_level_defaults)
|
||||||
logging.setup(config, 'placement')
|
logging.setup(config, 'placement')
|
||||||
py_logging.captureWarnings(True)
|
py_logging.captureWarnings(True)
|
||||||
|
|
||||||
|
17
tox.ini
17
tox.ini
@ -146,21 +146,10 @@ envdir = {toxworkdir}/shared
|
|||||||
commands = bandit -r placement -x tests -n 5 -ll
|
commands = bandit -r placement -x tests -n 5 -ll
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# E125 is deliberately excluded. See
|
|
||||||
# https://github.com/jcrocholl/pep8/issues/126. It's just wrong.
|
|
||||||
#
|
|
||||||
# Most of the whitespace related rules (E12* and E131) are excluded
|
|
||||||
# because while they are often useful guidelines, strict adherence to
|
|
||||||
# them ends up causing some really odd code formatting and forced
|
|
||||||
# extra line breaks. Updating code to enforce these will be a hard sell.
|
|
||||||
#
|
|
||||||
# H405 is another one that is good as a guideline, but sometimes
|
|
||||||
# multiline doc strings just don't have a natural summary
|
|
||||||
# line. Rejecting code for this reason is wrong.
|
|
||||||
#
|
|
||||||
# E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301
|
|
||||||
enable-extensions = H106,H203,H904
|
enable-extensions = H106,H203,H904
|
||||||
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405
|
# H405 is a good guideline, but sometimes multiline doc strings just don't have
|
||||||
|
# a natural summary line. Rejecting code for this reason is wrong.
|
||||||
|
ignore = H405
|
||||||
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,releasenotes
|
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,releasenotes
|
||||||
# To get a list of functions that have a complexity of 15 or more, set
|
# To get a list of functions that have a complexity of 15 or more, set
|
||||||
# max-complexity to 15 and run 'tox -epep8'.
|
# max-complexity to 15 and run 'tox -epep8'.
|
||||||
|
Loading…
Reference in New Issue
Block a user