summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtom Lifshitz <alifshit@redhat.com>2017-12-14 11:56:47 -0500
committerMatt Riedemann <mriedem.os@gmail.com>2017-12-18 19:43:54 +0000
commit4f0ff43c79c02689a118dc8100187c19b5c21238 (patch)
tree6d0e3fca93d462cb5290bdf5228a3dbc798212e3
parent684ad9dac2a0f23c84c8e7bee9a70ed8da53bda3 (diff)
Make request_spec.spec MediumText15.1.0
request_spec.instance_group.members is a list of instance UUIDs. It can get so long that it overflows its TEXT column. This patch changes request_spec.spec to MEDIUMTEXT. NOTE(artom): Conflicts in nova/tests/functional/db/api/test_migrations.py because of backport migration renumbering. NOTE(mriedem): Since this is a backport, this contains a release note not found in the original change on master. Change-Id: I6bf0fa19b72887803e77b66698587c2108c9372a Closes-bug: 1738094 (cherry picked from commit 40d74339082fe0eb1ce9216e89cf6e65a39e6968) (cherry picked from commit 9adf97c0132c3e0d34bbb2e33b59c6e5b00bec57)
Notes
Notes (review): Code-Review+2: Matt Riedemann <mriedem.os@gmail.com> Verified+1: IBM PowerKVM CI <kvmpower@linux.vnet.ibm.com> Code-Review+2: Lee Yarwood <lyarwood@redhat.com> Workflow+1: Lee Yarwood <lyarwood@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 19 Dec 2017 10:28:24 +0000 Reviewed-on: https://review.openstack.org/528332 Project: openstack/nova Branch: refs/heads/stable/ocata
-rw-r--r--nova/db/sqlalchemy/api_migrations/migrate_repo/versions/031_request_specs_spec_mediumtext.py25
-rw-r--r--nova/db/sqlalchemy/api_models.py2
-rw-r--r--nova/tests/functional/db/api/test_migrations.py30
-rw-r--r--releasenotes/notes/bug-1738094-request_specs.spec-migration-22d3421ea1536a37.yaml11
4 files changed, 67 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/031_request_specs_spec_mediumtext.py b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/031_request_specs_spec_mediumtext.py
new file mode 100644
index 0000000..e0eef79
--- /dev/null
+++ b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/031_request_specs_spec_mediumtext.py
@@ -0,0 +1,25 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from sqlalchemy import MetaData
14from sqlalchemy import Table
15
16from nova.db.sqlalchemy import api_models
17
18
19def upgrade(migrate_engine):
20 meta = MetaData()
21 meta.bind = migrate_engine
22
23 request_specs = Table('request_specs', meta, autoload=True)
24 if request_specs.c.spec.type != api_models.MediumText():
25 request_specs.c.spec.alter(type=api_models.MediumText())
diff --git a/nova/db/sqlalchemy/api_models.py b/nova/db/sqlalchemy/api_models.py
index e5c5720..586b8b3 100644
--- a/nova/db/sqlalchemy/api_models.py
+++ b/nova/db/sqlalchemy/api_models.py
@@ -168,7 +168,7 @@ class RequestSpec(API_BASE):
168 168
169 id = Column(Integer, primary_key=True) 169 id = Column(Integer, primary_key=True)
170 instance_uuid = Column(String(36), nullable=False) 170 instance_uuid = Column(String(36), nullable=False)
171 spec = Column(Text, nullable=False) 171 spec = Column(MediumText(), nullable=False)
172 172
173 173
174class Flavors(API_BASE): 174class Flavors(API_BASE):
diff --git a/nova/tests/functional/db/api/test_migrations.py b/nova/tests/functional/db/api/test_migrations.py
index b66e262..d0e8c3c 100644
--- a/nova/tests/functional/db/api/test_migrations.py
+++ b/nova/tests/functional/db/api/test_migrations.py
@@ -35,6 +35,7 @@ import mock
35from oslo_db.sqlalchemy import test_base 35from oslo_db.sqlalchemy import test_base
36from oslo_db.sqlalchemy import test_migrations 36from oslo_db.sqlalchemy import test_migrations
37from oslo_db.sqlalchemy import utils as db_utils 37from oslo_db.sqlalchemy import utils as db_utils
38from oslo_serialization import jsonutils
38import sqlalchemy 39import sqlalchemy
39from sqlalchemy.engine import reflection 40from sqlalchemy.engine import reflection
40 41
@@ -43,6 +44,7 @@ from nova.db.sqlalchemy.api_migrations import migrate_repo
43from nova.db.sqlalchemy import api_models 44from nova.db.sqlalchemy import api_models
44from nova.db.sqlalchemy import migration as sa_migration 45from nova.db.sqlalchemy import migration as sa_migration
45from nova import test 46from nova import test
47from nova.test import uuids
46from nova.tests import fixtures as nova_fixtures 48from nova.tests import fixtures as nova_fixtures
47 49
48 50
@@ -578,6 +580,34 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
578 for column in ['created_at', 'updated_at', 'id', 'uuid']: 580 for column in ['created_at', 'updated_at', 'id', 'uuid']:
579 self.assertColumnExists(engine, 'placement_aggregates', column) 581 self.assertColumnExists(engine, 'placement_aggregates', column)
580 582
583 def _pre_upgrade_031(self, engine):
584 request_specs = db_utils.get_table(engine, 'request_specs')
585 # The spec value is a serialized json blob.
586 spec = jsonutils.dumps(
587 {"instance_group": {"id": 42,
588 "members": ["uuid1",
589 "uuid2",
590 "uuid3"]}})
591 fake_request_spec = {
592 'id': 42, 'spec': spec, 'instance_uuid': uuids.instance}
593 request_specs.insert().execute(fake_request_spec)
594
595 def _check_031(self, engine, data):
596 request_specs = db_utils.get_table(engine, 'request_specs')
597 if engine.name == 'mysql':
598 self.assertIsInstance(request_specs.c.spec.type,
599 sqlalchemy.dialects.mysql.MEDIUMTEXT)
600
601 expected_spec = {"instance_group": {"id": 42,
602 "members": ["uuid1",
603 "uuid2",
604 "uuid3"]}}
605 from_db_request_spec = request_specs.select(
606 request_specs.c.id == 42).execute().first()
607 self.assertEqual(uuids.instance, from_db_request_spec['instance_uuid'])
608 db_spec = jsonutils.loads(from_db_request_spec['spec'])
609 self.assertDictEqual(expected_spec, db_spec)
610
581 611
582class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk, 612class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk,
583 test_base.DbTestCase, 613 test_base.DbTestCase,
diff --git a/releasenotes/notes/bug-1738094-request_specs.spec-migration-22d3421ea1536a37.yaml b/releasenotes/notes/bug-1738094-request_specs.spec-migration-22d3421ea1536a37.yaml
new file mode 100644
index 0000000..c333cc9
--- /dev/null
+++ b/releasenotes/notes/bug-1738094-request_specs.spec-migration-22d3421ea1536a37.yaml
@@ -0,0 +1,11 @@
1---
2upgrade:
3 - |
4 This release contains a schema migration for the ``nova_api`` database
5 in order to address bug 1738094:
6
7 https://bugs.launchpad.net/nova/+bug/1738094
8
9 The migration is optional and can be postponed if you have not been
10 affected by the bug. The bug manifests itself through "Data too long for
11 column 'spec'" database errors.