Fix path_in_stack for scheduler hints

Nova expects scheduler_hints to be a DictOfListOfStrings in
the object layer(versioned objects), though there is no
limitation for this in the api layer. Thefore sending a
list of tuples as a scheduler_hint results in error.

This also sets stack_scheduler_hints=true for integration
tests.

Change-Id: Id7575f67657fab86acb22d86807127dda45305d5
Closes-Bug: #1608452
This commit is contained in:
Rabi Mishra 2016-08-02 11:26:17 +05:30
parent b481a126c2
commit 372a2376b8
7 changed files with 29 additions and 12 deletions

View File

@ -29,8 +29,8 @@ The hints
---------
When heat processes a stack, and the feature is enabled, the stack id, root
stack id, stack resource uuid, stack resource name, and the path in the stack
(as a list of tuple, (stackresourcename, stackname)) will be passed by heat
to nova and cinder as scheduler hints.
(as a list of comma delimited strings of stackresourcename and stackname) will
be passed by heat to nova and cinder as scheduler hints.
Purpose
-------

View File

@ -250,11 +250,11 @@ engine_opts = [
' set to the id of the resource\'s parent stack,'
' heat_stack_name will be set to the name of the'
' resource\'s parent stack, heat_path_in_stack will'
' be set to a list of tuples, (stackresourcename,'
' stackname) with list[0] being (None, rootstackname),'
' heat_resource_name will be set to the resource\'s'
' name, and heat_resource_uuid will be set to the'
' resource\'s orchestration id.')),
' be set to a list of comma delimited strings of'
' stackresourcename and stackname with list[0] being'
' \'rootstackname\', heat_resource_name will be set to'
' the resource\'s name, and heat_resource_uuid will be'
' set to the resource\'s orchestration id.')),
cfg.BoolOpt('encrypt_parameters_and_properties',
default=False,
help=_('Encrypt template parameters that were marked as'

View File

@ -26,6 +26,19 @@ class SchedulerHintsMixin(object):
HEAT_RESOURCE_NAME = 'heat_resource_name'
HEAT_RESOURCE_UUID = 'heat_resource_uuid'
@staticmethod
def _path_in_stack(stack):
# Note: scheduler_hints can only be of DictOfListOfStrings.
# Convert the list of tuples to list of delimited strings.
path = []
for parent_res_name, stack_name in stack.path_in_stack():
if parent_res_name is not None:
path.append(','.join([parent_res_name, stack_name]))
else:
path.append(stack_name)
return path
def _scheduler_hints(self, scheduler_hints):
"""Augment scheduler hints with supplemental content."""
if cfg.CONF.stack_scheduler_hints:
@ -35,7 +48,8 @@ class SchedulerHintsMixin(object):
scheduler_hints[self.HEAT_ROOT_STACK_ID] = stack.root_stack_id()
scheduler_hints[self.HEAT_STACK_ID] = stack.id
scheduler_hints[self.HEAT_STACK_NAME] = stack.name
scheduler_hints[self.HEAT_PATH_IN_STACK] = stack.path_in_stack()
scheduler_hints[
self.HEAT_PATH_IN_STACK] = self._path_in_stack(stack)
scheduler_hints[self.HEAT_RESOURCE_NAME] = self.name
scheduler_hints[self.HEAT_RESOURCE_UUID] = self.uuid
return scheduler_hints

View File

@ -615,7 +615,7 @@ class InstancesTest(common.HeatTestCase):
scheduler_hints={shm.HEAT_ROOT_STACK_ID: stack.root_stack_id(),
shm.HEAT_STACK_ID: stack.id,
shm.HEAT_STACK_NAME: stack.name,
shm.HEAT_PATH_IN_STACK: [(None, stack.name)],
shm.HEAT_PATH_IN_STACK: [stack.name],
shm.HEAT_RESOURCE_NAME: instance.name,
shm.HEAT_RESOURCE_UUID: instance.uuid,
'foo': ['spam', 'ham', 'baz'], 'bar': 'eggs'},

View File

@ -988,7 +988,7 @@ class CinderVolumeTest(vt_base.BaseVolumeTest):
scheduler_hints={shm.HEAT_ROOT_STACK_ID: stack.root_stack_id(),
shm.HEAT_STACK_ID: stack.id,
shm.HEAT_STACK_NAME: stack.name,
shm.HEAT_PATH_IN_STACK: [(None, stack.name)],
shm.HEAT_PATH_IN_STACK: [stack.name],
shm.HEAT_RESOURCE_NAME: rsrc.name,
shm.HEAT_RESOURCE_UUID: rsrc.uuid}).AndReturn(fv)
self.cinder_fc.volumes.get(fv.id).AndReturn(fv)

View File

@ -983,7 +983,8 @@ class ServersTest(common.HeatTestCase):
stack_name = 'test_server_w_stack_sched_hints_s'
server_name = 'server_w_stack_sched_hints'
(t, stack) = self._get_test_template(stack_name, server_name)
self.patchobject(stack, 'path_in_stack',
return_value=[('parent', stack.name)])
resource_defns = t.resource_definitions(stack)
server = servers.Server(server_name,
resource_defns['WebServer'], stack)
@ -999,7 +1000,8 @@ class ServersTest(common.HeatTestCase):
scheduler_hints = {shm.HEAT_ROOT_STACK_ID: stack.root_stack_id(),
shm.HEAT_STACK_ID: stack.id,
shm.HEAT_STACK_NAME: stack.name,
shm.HEAT_PATH_IN_STACK: [(None, stack.name)],
shm.HEAT_PATH_IN_STACK: [','.join(['parent',
stack.name])],
shm.HEAT_RESOURCE_NAME: server.name,
shm.HEAT_RESOURCE_UUID: server.uuid}

View File

@ -28,6 +28,7 @@ if [ "$DISABLE_CONVERGENCE" == "true" ] ; then
echo -e 'convergence_engine=false\n' >> $localconf
fi
echo -e 'stack_scheduler_hints=true\n' >> $localconf
echo -e 'notification_driver=messagingv2\n' >> $localconf
echo -e 'hidden_stack_tags=hidden\n' >> $localconf
echo -e 'encrypt_parameters_and_properties=True\n' >> $localconf