From 94f0cedc98a1e21442633906a43c83b33b7c8702 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Wed, 25 Jul 2018 17:40:21 +0200 Subject: [PATCH] Add automated_clean field This field will define if the automated clean will be enabled on the node. The default will be true, so when automated cleanup is enabled generally, all the nodes will be cleaned. If some node needs to be skipped, automated_cleanup needs to be change to False. Change-Id: I47f4c4097f849472be54d2be81e1440b8f349edb Story: #2002161 Task: #20011 --- .../d2b036ae9378_add_automated_clean_field.py | 31 +++++++++++++++++++ ironic/db/sqlalchemy/models.py | 1 + .../unit/db/sqlalchemy/test_migrations.py | 5 +++ 3 files changed, 37 insertions(+) create mode 100644 ironic/db/sqlalchemy/alembic/versions/d2b036ae9378_add_automated_clean_field.py diff --git a/ironic/db/sqlalchemy/alembic/versions/d2b036ae9378_add_automated_clean_field.py b/ironic/db/sqlalchemy/alembic/versions/d2b036ae9378_add_automated_clean_field.py new file mode 100644 index 00000000000..30a16108bbb --- /dev/null +++ b/ironic/db/sqlalchemy/alembic/versions/d2b036ae9378_add_automated_clean_field.py @@ -0,0 +1,31 @@ +# 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. + +"""Add automated_clean field + +Revision ID: d2b036ae9378 +Revises: 664f85c2f622 +Create Date: 2018-07-25 15:30:20.860792 + +""" + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'd2b036ae9378' +down_revision = '664f85c2f622' + + +def upgrade(): + op.add_column('nodes', sa.Column('automated_clean', sa.Boolean(), + nullable=True)) diff --git a/ironic/db/sqlalchemy/models.py b/ironic/db/sqlalchemy/models.py index a94e9645c97..70dafcc50c9 100644 --- a/ironic/db/sqlalchemy/models.py +++ b/ironic/db/sqlalchemy/models.py @@ -175,6 +175,7 @@ class Node(Base): inspection_finished_at = Column(DateTime, nullable=True) inspection_started_at = Column(DateTime, nullable=True) extra = Column(db_types.JsonEncodedDict) + automated_clean = Column(Boolean, nullable=True) bios_interface = Column(String(255), nullable=True) boot_interface = Column(String(255), nullable=True) diff --git a/ironic/tests/unit/db/sqlalchemy/test_migrations.py b/ironic/tests/unit/db/sqlalchemy/test_migrations.py index dadde2b677c..dd75aa2a4d7 100644 --- a/ironic/tests/unit/db/sqlalchemy/test_migrations.py +++ b/ironic/tests/unit/db/sqlalchemy/test_migrations.py @@ -760,6 +760,11 @@ class MigrationCheckersMixin(object): conductors_tbl.c.id == data['conductor_id']).execute().first() self.assertEqual(conductor['conductor_group'], "") + def _check_d2b036ae9378(self, engine, data): + nodes = db_utils.get_table(engine, 'nodes') + col_names = [column.name for column in nodes.c] + self.assertIn('automated_clean', col_names) + def test_upgrade_and_version(self): with patch_with_engine(self.engine): self.migration_api.upgrade('head')