Validate the selected node ready to do the deploy

As we use node_cache for scheduler, node state maybe already
changed when we selected it, so adding a validation before we
really do the deploy.

Change-Id: I031ac5aaf049f549470e012df0ece25381a42b6a
This commit is contained in:
Zhenguo Niu 2016-10-06 13:04:27 +08:00
parent 28325f9e7b
commit 86ec85f335
3 changed files with 50 additions and 3 deletions

View File

@ -84,6 +84,11 @@ def destroy_node(node_uuid):
ironic_states.DELETED)
def validate_node(node_uuid):
ironicclient = ironic.IronicClientWrapper()
ironicclient.call("node.validate", node_uuid)
def get_node_list(**kwargs):
"""Helper function to return the list of nodes.

View File

@ -27,6 +27,7 @@ from nimble.conf import CONF
from nimble.engine.baremetal import ironic
from nimble.engine.baremetal import ironic_states
from nimble.engine import base_manager
from nimble.engine import status
MANAGER_TOPIC = 'nimble.engine_manager'
@ -95,7 +96,7 @@ class EngineManager(base_manager.BaseEngineManager):
# job is done
LOG.debug("Ironic node %(node)s is now ACTIVE",
dict(node=node.uuid))
instance.status = ironic_states.ACTIVE
instance.status = status.ACTIVE
instance.save()
raise loopingcall.LoopingCallDone()
@ -152,19 +153,32 @@ class EngineManager(base_manager.BaseEngineManager):
request_spec,
self.node_cache)
if top_node is None:
instance.status = 'error'
instance.status = status.ERROR
instance.save()
raise exception.NoValidNode(
_('No valid node is found with request spec %s') %
request_spec)
instance.node_uuid = top_node.to_dict()['node']
# validate we are ready to do the deploy
validate_chk = ironic.validate_node(instance.node_uuid)
if (not validate_chk.deploy.get('result')
or not validate_chk.power.get('result')):
instance.status = status.ERROR
instance.save()
raise exception.ValidationError(_(
"Ironic node: %(id)s failed to validate."
" (deploy: %(deploy)s, power: %(power)s)")
% {'id': instance.node_uuid,
'deploy': validate_chk.deploy,
'power': validate_chk.power})
network_info = self._build_networks(context, instance,
requested_networks)
instance.network_info = network_info
instance.status = 'building'
instance.status = status.BUILDING
instance.save()
self._build_instance(context, instance)

28
nimble/engine/status.py Normal file
View File

@ -0,0 +1,28 @@
# Copyright 2016 Huawei Technologies Co.,LTD.
# 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.
"""Possible status for instances.
Compute instance status represent the state of an instance as it pertains to
a user or administrator.
"""
# Instance is running
ACTIVE = 'active'
# Instance only exists in DB
BUILDING = 'building'
ERROR = 'error'