From 28ade4a5be5fc0bc5c6b25690b1b15b98b703e5e Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Thu, 3 Apr 2014 18:35:47 +0300 Subject: [PATCH] Allow complex scheduler hints for AWS Instance Nova supports providing several values for the same scheduler hint, in which case the hint value is formed as a list. This functionality was missing in AWS::EC2::Instance resource. Change-Id: Id05e4f2ebe89871c1f27f8d97441f3b6cf469dd3 Closes-Bug: #1297667 --- heat/engine/resources/instance.py | 11 ++++++++++- heat/tests/test_instance.py | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index 3020dd88b0..868a64af42 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -13,6 +13,7 @@ # under the License. from oslo.config import cfg +import six cfg.CONF.import_opt('instance_user', 'heat.common.config') @@ -425,7 +426,15 @@ class Instance(resource.Resource): scheduler_hints = {} if self.properties[self.NOVA_SCHEDULER_HINTS]: for tm in self.properties[self.NOVA_SCHEDULER_HINTS]: - scheduler_hints[tm[self.TAG_KEY]] = tm[self.TAG_VALUE] + # adopted from novaclient shell + hint = tm[self.TAG_KEY] + hint_value = tm[self.TAG_VALUE] + if hint in scheduler_hints: + if isinstance(scheduler_hints[hint], six.string_types): + scheduler_hints[hint] = [scheduler_hints[hint]] + scheduler_hints[hint].append(hint_value) + else: + scheduler_hints[hint] = hint_value else: scheduler_hints = None diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index 3923378c9e..45670cf884 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -52,6 +52,10 @@ wp_template = ''' "ImageId" : "F17-x86_64-gold", "InstanceType" : "m1.large", "KeyName" : "test", + "NovaSchedulerHints" : [{"Key": "foo", "Value": "spam"}, + {"Key": "bar", "Value": "eggs"}, + {"Key": "foo", "Value": "ham"}, + {"Key": "foo", "Value": "baz"}], "UserData" : "wordpress" } } @@ -101,7 +105,8 @@ class InstancesTest(HeatTestCase): instance.name, limit=instance.physical_resource_name_limit), security_groups=None, - userdata=mox.IgnoreArg(), scheduler_hints=None, + userdata=mox.IgnoreArg(), + scheduler_hints={'foo': ['spam', 'ham', 'baz'], 'bar': 'eggs'}, meta=None, nics=None, availability_zone=None).AndReturn( return_server)