diff options
| author | Devananda van der Veen <devananda.vdv@gmail.com> | 2013-02-10 12:49:53 -0800 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-02-20 11:52:00 -0800 |
| commit | 63285645c72d3a5dcb232b5a129cf99602f2a607 (patch) | |
| tree | d84c4a1c680135df86a62e028daf23ec63ab3d01 /nova/virt | |
| parent | ab9f8667c63d901f37d1662c5204fb2938be44fe (diff) | |
Baremetal driver returns accurate list of instance
Add 'instance_name' to bm_nodes table so that baremetal driver is able
to return the names of all instances it believes are still running.
Previously, baremetal.driver.list_instances was fetching all allocated
instances from baremetal database, then calling VirtAPI to get the
instance name. This would raise an InstanceNotFound exception for
deleted instances. This prevented ComputeManager from ever detecting
a running-but-deleted baremetal instance, and could leave baremetal
instances in an undeletable state.
Fixes bug 1096723.
Change-Id: Ifae532e8e70e97e48c589608cb3c7000bb6a7609
Diffstat (limited to 'nova/virt')
3 files changed, 41 insertions, 13 deletions
diff --git a/nova/virt/baremetal/db/sqlalchemy/migrate_repo/versions/004_add_instance_name_to_bm_nodes.py b/nova/virt/baremetal/db/sqlalchemy/migrate_repo/versions/004_add_instance_name_to_bm_nodes.py new file mode 100644 index 000000000..68fbe0960 --- /dev/null +++ b/nova/virt/baremetal/db/sqlalchemy/migrate_repo/versions/004_add_instance_name_to_bm_nodes.py @@ -0,0 +1,37 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# All Rights Reserved. +# +# 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. + +from sqlalchemy import Column, MetaData, String, Table + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + t = Table('bm_nodes', meta, autoload=True) + name_col = Column('instance_name', String(255)) + t.create_column(name_col) + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + t = Table('bm_nodes', meta, autoload=True) + name_col = Column('instance_name', String(length=255)) + + t.drop_column(name_col) diff --git a/nova/virt/baremetal/db/sqlalchemy/models.py b/nova/virt/baremetal/db/sqlalchemy/models.py index e1a8ebb3a..756376cb7 100644 --- a/nova/virt/baremetal/db/sqlalchemy/models.py +++ b/nova/virt/baremetal/db/sqlalchemy/models.py @@ -37,6 +37,7 @@ class BareMetalNode(BASE, models.NovaBase): uuid = Column(String(36)) service_host = Column(String(255)) instance_uuid = Column(String(36), nullable=True) + instance_name = Column(String(255), nullable=True) cpus = Column(Integer) memory_mb = Column(Integer) local_gb = Column(Integer) diff --git a/nova/virt/baremetal/driver.py b/nova/virt/baremetal/driver.py index b95a3ad61..8dff0a785 100755 --- a/nova/virt/baremetal/driver.py +++ b/nova/virt/baremetal/driver.py @@ -102,6 +102,7 @@ def _update_state(context, node, instance, state): values = {'task_state': state} if not instance: values['instance_uuid'] = None + values['instance_name'] = None db.bm_node_update(context, node['id'], values) @@ -170,19 +171,7 @@ class BareMetalDriver(driver.ComputeDriver): l = [] context = nova_context.get_admin_context() for node in db.bm_node_get_associated(context, service_host=CONF.host): - if not node['instance_uuid']: - # Not currently assigned to an instance. - continue - try: - inst = self.virtapi.instance_get_by_uuid( - context, node['instance_uuid']) - except exception.InstanceNotFound: - # Assigned to an instance that no longer exists. - LOG.warning(_("Node %(id)r assigned to instance %(uuid)r " - "which cannot be found."), - dict(id=node['id'], uuid=node['instance_uuid'])) - continue - l.append(inst['name']) + l.append(node['instance_name']) return l def _require_node(self, instance): @@ -244,6 +233,7 @@ class BareMetalDriver(driver.ComputeDriver): # allocates this node before we begin provisioning it. node = db.bm_node_associate_and_update(context, node_uuid, {'instance_uuid': instance['uuid'], + 'instance_name': instance['hostname'], 'task_state': baremetal_states.BUILDING}) try: |
