Skip to content

Commit c8488c3

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "db: Add vpmems to instance_extra"
2 parents 27fc32d + 041285d commit c8488c3

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

nova/db/sqlalchemy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,7 @@ def instance_create(context, values):
17331733
'pci_requests': None,
17341734
'vcpu_model': None,
17351735
'trusted_certs': None,
1736+
'vpmems': None,
17361737
})
17371738
instance_ref['extra'].update(values.pop('extra', {}))
17381739
instance_ref.update(values)
@@ -3008,7 +3009,7 @@ def instance_extra_get_by_instance_uuid(context, instance_uuid,
30083009
filter_by(instance_uuid=instance_uuid)
30093010
if columns is None:
30103011
columns = ['numa_topology', 'pci_requests', 'flavor', 'vcpu_model',
3011-
'trusted_certs', 'migration_context']
3012+
'trusted_certs', 'vpmems', 'migration_context']
30123013
for column in columns:
30133014
query = query.options(undefer(column))
30143015
instance_extra = query.first()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
13+
from sqlalchemy import Column
14+
from sqlalchemy import MetaData
15+
from sqlalchemy import Table
16+
from sqlalchemy import Text
17+
18+
19+
BASE_TABLE_NAME = 'instance_extra'
20+
NEW_COLUMN_NAME = 'vpmems'
21+
22+
23+
def upgrade(migrate_engine):
24+
meta = MetaData()
25+
meta.bind = migrate_engine
26+
27+
for prefix in ('', 'shadow_'):
28+
table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
29+
new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
30+
if not hasattr(table.c, NEW_COLUMN_NAME):
31+
table.create_column(new_column)

nova/db/sqlalchemy/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class InstanceExtra(BASE, NovaBase, models.SoftDeleteMixin):
389389
migration_context = orm.deferred(Column(Text))
390390
keypairs = orm.deferred(Column(Text))
391391
trusted_certs = orm.deferred(Column(Text))
392+
vpmems = orm.deferred(Column(Text))
392393
instance = orm.relationship(Instance,
393394
backref=orm.backref('extra',
394395
uselist=False),

nova/tests/unit/db/test_db_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3291,13 +3291,15 @@ def test_instance_extra_update_by_uuid(self):
32913291
db.instance_extra_update_by_uuid(self.ctxt, self.instance['uuid'],
32923292
{'numa_topology': 'changed',
32933293
'trusted_certs': "['123', 'foo']",
3294+
'vpmems': "['vpmem0', 'vpmem1']",
32943295
})
32953296
inst_extra = db.instance_extra_get_by_instance_uuid(
32963297
self.ctxt, self.instance['uuid'])
32973298
self.assertEqual('changed', inst_extra.numa_topology)
32983299
# NOTE(jackie-truong): trusted_certs is stored as a Text type in
32993300
# instance_extra and read as a list of strings
33003301
self.assertEqual("['123', 'foo']", inst_extra.trusted_certs)
3302+
self.assertEqual("['vpmem0', 'vpmem1']", inst_extra.vpmems)
33013303

33023304
def test_instance_extra_update_by_uuid_and_create(self):
33033305
@sqlalchemy_api.pick_context_manager_writer
@@ -3322,12 +3324,13 @@ def test(context):
33223324
def test_instance_extra_get_with_columns(self):
33233325
extra = db.instance_extra_get_by_instance_uuid(
33243326
self.ctxt, self.instance['uuid'],
3325-
columns=['numa_topology', 'vcpu_model', 'trusted_certs'])
3327+
columns=['numa_topology', 'vcpu_model', 'trusted_certs', 'vpmems'])
33263328
self.assertRaises(SQLAlchemyError,
33273329
extra.__getitem__, 'pci_requests')
33283330
self.assertIn('numa_topology', extra)
33293331
self.assertIn('vcpu_model', extra)
33303332
self.assertIn('trusted_certs', extra)
3333+
self.assertIn('vpmems', extra)
33313334

33323335

33333336
class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):

nova/tests/unit/db/test_migrations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@ def _check_397(self, engine, data):
10271027
self.assertColumnExists(
10281028
engine, '%smigrations' % prefix, 'cross_cell_move')
10291029

1030+
def _check_398(self, engine, data):
1031+
self.assertColumnExists(engine, 'instance_extra', 'vpmems')
1032+
self.assertColumnExists(engine, 'shadow_instance_extra', 'vpmems')
1033+
10301034

10311035
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
10321036
test_fixtures.OpportunisticDBTestMixin,

0 commit comments

Comments
 (0)