From 57b0bb374963bdbf0aef910feaccb8f536641c41 Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Thu, 12 Apr 2018 10:57:24 +0800 Subject: [PATCH] Add rules column to instance_group_policy table. This adds the rules column to instance_group_policy table. The ''Text'' column "rules" which is a dict, it can be applied to the policy, and represents the rules for specific policy. Related to blueprint complex-anti-affinity-policies Change-Id: I61ffb5ddb2d808bfef4e60088f4524bd98e0474e --- .../060_instance_group_policy_add_rules.py | 26 +++++++++++++++++++ nova/db/sqlalchemy/api_models.py | 1 + .../functional/db/api/test_migrations.py | 3 +++ 3 files changed, 30 insertions(+) create mode 100644 nova/db/sqlalchemy/api_migrations/migrate_repo/versions/060_instance_group_policy_add_rules.py diff --git a/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/060_instance_group_policy_add_rules.py b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/060_instance_group_policy_add_rules.py new file mode 100644 index 0000000000..116432110d --- /dev/null +++ b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/060_instance_group_policy_add_rules.py @@ -0,0 +1,26 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import Column +from sqlalchemy import MetaData +from sqlalchemy import Table +from sqlalchemy import Text + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + policies = Table('instance_group_policy', meta, autoload=True) + + if not hasattr(policies.c, 'rules'): + policies.create_column(Column('rules', Text)) diff --git a/nova/db/sqlalchemy/api_models.py b/nova/db/sqlalchemy/api_models.py index 56bd27d44a..8fed954a03 100644 --- a/nova/db/sqlalchemy/api_models.py +++ b/nova/db/sqlalchemy/api_models.py @@ -417,6 +417,7 @@ class InstanceGroupPolicy(API_BASE): policy = Column(String(255)) group_id = Column(Integer, ForeignKey('instance_groups.id'), nullable=False) + rules = Column(Text) class InstanceGroup(API_BASE): diff --git a/nova/tests/functional/db/api/test_migrations.py b/nova/tests/functional/db/api/test_migrations.py index 475cc4c2d7..1ad5efe377 100644 --- a/nova/tests/functional/db/api/test_migrations.py +++ b/nova/tests/functional/db/api/test_migrations.py @@ -713,6 +713,9 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin): self.assertEqual(1, len(result)) self.assertEqual(0, result[0]['generation']) + def _check_060(self, engine, data): + self.assertColumnExists(engine, 'instance_group_policy', 'rules') + class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk, test_base.DbTestCase,