From 372a2376b81d5e20996f6032054bd5be11423581 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Tue, 2 Aug 2016 11:26:17 +0530 Subject: [PATCH] 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 --- doc/source/developing_guides/schedulerhints.rst | 4 ++-- heat/common/config.py | 10 +++++----- heat/engine/resources/scheduler_hints.py | 16 +++++++++++++++- heat/tests/aws/test_instance.py | 2 +- heat/tests/openstack/cinder/test_volume.py | 2 +- heat/tests/openstack/nova/test_server.py | 6 ++++-- heat_integrationtests/pre_test_hook.sh | 1 + 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/doc/source/developing_guides/schedulerhints.rst b/doc/source/developing_guides/schedulerhints.rst index 890c75df0e..44b14ebf4d 100644 --- a/doc/source/developing_guides/schedulerhints.rst +++ b/doc/source/developing_guides/schedulerhints.rst @@ -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 ------- diff --git a/heat/common/config.py b/heat/common/config.py index 8cdaf2e6c3..8ed804aa39 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -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' diff --git a/heat/engine/resources/scheduler_hints.py b/heat/engine/resources/scheduler_hints.py index cb8cc10bb4..38217504d6 100644 --- a/heat/engine/resources/scheduler_hints.py +++ b/heat/engine/resources/scheduler_hints.py @@ -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 diff --git a/heat/tests/aws/test_instance.py b/heat/tests/aws/test_instance.py index e20d8e8dbb..ff868a28b7 100644 --- a/heat/tests/aws/test_instance.py +++ b/heat/tests/aws/test_instance.py @@ -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'}, diff --git a/heat/tests/openstack/cinder/test_volume.py b/heat/tests/openstack/cinder/test_volume.py index ba0b338e3c..bf2ee4dd94 100644 --- a/heat/tests/openstack/cinder/test_volume.py +++ b/heat/tests/openstack/cinder/test_volume.py @@ -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) diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 2f6373b02d..9a0a229d86 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -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} diff --git a/heat_integrationtests/pre_test_hook.sh b/heat_integrationtests/pre_test_hook.sh index 3bf701b44d..828fc91b0c 100755 --- a/heat_integrationtests/pre_test_hook.sh +++ b/heat_integrationtests/pre_test_hook.sh @@ -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