From 38b57229c9d7d128f3cba3fb386fe5413fdd5a8d Mon Sep 17 00:00:00 2001 From: Telles Nobrega Date: Fri, 24 Jul 2015 09:29:42 -0300 Subject: [PATCH] Increase internal_ip and management_ip column size When using Ipv6 a column size of 15 is no big enough. We need to increase these two columns to 45. Closes-bug: 1470999 Change-Id: I5843878bb441748d80e2d7de02a232cf1d937d88 --- .../versions/025_increase_ip_column_size.py | 36 ++++++++++++++ sahara/db/sqlalchemy/models.py | 4 +- .../unit/conductor/manager/test_clusters.py | 48 +++++++++++++++++++ .../unit/db/migration/test_migrations.py | 11 +++++ 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 sahara/db/migration/alembic_migrations/versions/025_increase_ip_column_size.py diff --git a/sahara/db/migration/alembic_migrations/versions/025_increase_ip_column_size.py b/sahara/db/migration/alembic_migrations/versions/025_increase_ip_column_size.py new file mode 100644 index 00000000..0c424a1a --- /dev/null +++ b/sahara/db/migration/alembic_migrations/versions/025_increase_ip_column_size.py @@ -0,0 +1,36 @@ +# Copyright 2015 Telles Nobrega +# +# 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. + +"""Increase internal_ip and management_ip column size to work with IPv6 + +Revision ID: 025 +Revises: 024 +Create Date: 2015-07-17 09:58:22.128263 + +""" + +# revision identifiers, used by Alembic. +revision = '025' +down_revision = '024' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.alter_column('instances', 'internal_ip', type_=sa.String(45), + nullable=True) + op.alter_column('instances', 'management_ip', type_=sa.String(45), + nullable=True) diff --git a/sahara/db/sqlalchemy/models.py b/sahara/db/sqlalchemy/models.py index 82d5bfa7..69cfab3d 100644 --- a/sahara/db/sqlalchemy/models.py +++ b/sahara/db/sqlalchemy/models.py @@ -152,8 +152,8 @@ class Instance(mb.SaharaBase): node_group_id = sa.Column(sa.String(36), sa.ForeignKey('node_groups.id')) instance_id = sa.Column(sa.String(36)) instance_name = sa.Column(sa.String(80), nullable=False) - internal_ip = sa.Column(sa.String(15)) - management_ip = sa.Column(sa.String(15)) + internal_ip = sa.Column(sa.String(45)) + management_ip = sa.Column(sa.String(45)) volumes = sa.Column(st.JsonListType()) diff --git a/sahara/tests/unit/conductor/manager/test_clusters.py b/sahara/tests/unit/conductor/manager/test_clusters.py index 7b68a7bd..a7587c19 100644 --- a/sahara/tests/unit/conductor/manager/test_clusters.py +++ b/sahara/tests/unit/conductor/manager/test_clusters.py @@ -229,6 +229,14 @@ class ClusterTest(test_base.ConductorManagerTestCase): } return self.api.instance_add(ctx, ng_id, instance) + def _add_instance_ipv6(self, ctx, ng_id, instance_name): + instance = { + "instance_name": instance_name, + "internal_ip": "FE80:0000:0000:0000:0202:B3FF:FE1E:8329", + "management_ip": "FE80:0000:0000:0000:0202:B3FF:FE1E:8329" + } + return self.api.instance_add(ctx, ng_id, instance) + def test_add_instance(self): ctx = context.ctx() cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER) @@ -249,6 +257,27 @@ class ClusterTest(test_base.ConductorManagerTestCase): self.assertEqual("additional_vm", ng["instances"][0]["instance_name"]) + def test_add_instance_ipv6(self): + ctx = context.ctx() + cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER) + _id = cluster_db_obj["id"] + + ng_id = cluster_db_obj["node_groups"][-1]["id"] + count = cluster_db_obj["node_groups"][-1]["count"] + + instance_name = "additional_vm_ipv6" + self._add_instance_ipv6(ctx, ng_id, instance_name) + + cluster_db_obj = self.api.cluster_get(ctx, _id) + for ng in cluster_db_obj["node_groups"]: + if ng["id"] != ng_id: + continue + + ng.pop('tenant_id') + self.assertEqual(count + 1, ng["count"]) + self.assertEqual(instance_name, + ng["instances"][0]["instance_name"]) + def test_update_instance(self): ctx = context.ctx() cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER) @@ -268,6 +297,25 @@ class ClusterTest(test_base.ConductorManagerTestCase): self.assertEqual("1.1.1.1", ng["instances"][0]["management_ip"]) + def test_update_instance_ipv6(self): + ctx = context.ctx() + ip = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329" + cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER) + _id = cluster_db_obj["id"] + + ng_id = cluster_db_obj["node_groups"][-1]["id"] + + instance_id = self._add_instance(ctx, ng_id) + + self.api.instance_update(ctx, instance_id, {"management_ip": ip}) + + cluster_db_obj = self.api.cluster_get(ctx, _id) + for ng in cluster_db_obj["node_groups"]: + if ng["id"] != ng_id: + continue + + self.assertEqual(ip, ng["instances"][0]["management_ip"]) + def test_remove_instance(self): ctx = context.ctx() cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER) diff --git a/sahara/tests/unit/db/migration/test_migrations.py b/sahara/tests/unit/db/migration/test_migrations.py index d460a9c9..ef71f98f 100644 --- a/sahara/tests/unit/db/migration/test_migrations.py +++ b/sahara/tests/unit/db/migration/test_migrations.py @@ -47,6 +47,11 @@ class SaharaMigrationsCheckers(object): for column in columns: self.assertColumnExists(engine, table, column) + def assertColumnType(self, engine, table, column, column_type): + t = db_utils.get_table(engine, table) + column_ref_type = str(t.c[column].type) + self.assertEqual(column_ref_type, column_type) + def assertColumnCount(self, engine, table, columns): t = db_utils.get_table(engine, table) self.assertEqual(len(columns), len(t.columns)) @@ -508,6 +513,12 @@ class SaharaMigrationsCheckers(object): for table in tables: self.assertColumnExists(engine, table, 'shares') + def _check_025(self, engine, data): + self.assertColumnType(engine, 'instances', 'internal_ip', + 'VARCHAR(45)') + self.assertColumnType(engine, 'instances', 'management_ip', + 'VARCHAR(45)') + class TestMigrationsMySQL(SaharaMigrationsCheckers, base.BaseWalkMigrationTestCase,