Add a data migration to fill node.network_interface
This fills node.network_interface based on the default logic that the node update/create calls follow, so that we know network_interface is populated when this code is deployed. Also adds to existing release note about how network_interface is set, to remind people to check the logic and configs to make sure they get the expected result. Change-Id: I09a42c8e54d7782c591415e53fccade972ae8bdb Closes-Bug: #1608511
This commit is contained in:
parent
906af9e101
commit
1514b2a2f6
@ -0,0 +1,44 @@
|
||||
# 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.
|
||||
|
||||
"""Populate node.network_interface
|
||||
|
||||
Revision ID: c14cef6dfedf
|
||||
Revises: dd34e1f1303b
|
||||
Create Date: 2016-08-01 14:05:24.197314
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c14cef6dfedf'
|
||||
down_revision = 'dd34e1f1303b'
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy.sql import table, column, null
|
||||
|
||||
from ironic.conf import CONF
|
||||
|
||||
|
||||
node = table('nodes',
|
||||
column('uuid', String(36)),
|
||||
column('network_interface', String(255)))
|
||||
|
||||
|
||||
def upgrade():
|
||||
network_iface = (CONF.default_network_interface or
|
||||
('flat' if CONF.dhcp.dhcp_provider == 'neutron'
|
||||
else 'noop'))
|
||||
op.execute(
|
||||
node.update().where(
|
||||
node.c.network_interface == null()).values(
|
||||
{'network_interface': network_iface}))
|
@ -34,6 +34,7 @@ For postgres on Ubuntu this can be done with the following commands:
|
||||
|
||||
"""
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
|
||||
from alembic import script
|
||||
@ -440,6 +441,37 @@ class MigrationCheckersMixin(object):
|
||||
self.assertIsInstance(nodes.c.resource_class.type,
|
||||
sqlalchemy.types.String)
|
||||
|
||||
def _pre_upgrade_c14cef6dfedf(self, engine):
|
||||
# add some nodes.
|
||||
nodes = db_utils.get_table(engine, 'nodes')
|
||||
data = [{'uuid': uuidutils.generate_uuid(),
|
||||
'network_interface': None},
|
||||
{'uuid': uuidutils.generate_uuid(),
|
||||
'network_interface': None},
|
||||
{'uuid': uuidutils.generate_uuid(),
|
||||
'network_interface': 'neutron'}]
|
||||
nodes.insert().values(data).execute()
|
||||
return data
|
||||
|
||||
def _check_c14cef6dfedf(self, engine, data):
|
||||
nodes = db_utils.get_table(engine, 'nodes')
|
||||
result = engine.execute(nodes.select())
|
||||
counts = collections.defaultdict(int)
|
||||
|
||||
def _was_inserted(uuid):
|
||||
for row in data:
|
||||
if row['uuid'] == uuid:
|
||||
return True
|
||||
|
||||
for row in result:
|
||||
if _was_inserted(row['uuid']):
|
||||
counts[row['network_interface']] += 1
|
||||
|
||||
# using default config values, we should have 2 flat and one neutron
|
||||
self.assertEqual(2, counts['flat'])
|
||||
self.assertEqual(1, counts['neutron'])
|
||||
self.assertEqual(0, counts[None])
|
||||
|
||||
def test_upgrade_and_version(self):
|
||||
with patch_with_engine(self.engine):
|
||||
self.migration_api.upgrade('head')
|
||||
|
@ -27,3 +27,13 @@ upgrade:
|
||||
set. If it is not set, the network interface is determined by looking at
|
||||
the ``[dhcp]dhcp_provider`` value. If it is ``neutron`` - ``flat`` network
|
||||
interface is the default, ``noop`` otherwise.
|
||||
The network interface will be set for all nodes without network_interface
|
||||
already set via a database migration. This will be set following the logic
|
||||
above. When running database migrations for an existing deployment, it's
|
||||
important to check the above configuration options to ensure the existing
|
||||
nodes will have the expected network_interface. If
|
||||
``[DEFAULT]default_network_interface`` is not set, everything should go as
|
||||
expected. If it is set, ensure that it is set to the value that you wish
|
||||
existing nodes to use.
|
||||
- Note that if ``[DEFAULT]default_network_interface`` is set, it must be set
|
||||
in the configuration file for both the API and conductor hosts.
|
||||
|
Loading…
Reference in New Issue
Block a user