]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make sure that Tags on the InstanceGroup get passed to nova
authorAngus Salkeld <asalkeld@redhat.com>
Mon, 15 Jul 2013 01:10:03 +0000 (11:10 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Mon, 15 Jul 2013 05:57:25 +0000 (15:57 +1000)
This is needed by the ceilometer alarmer.

Change-Id: Ia6e744b7dfa9fab518050174bcff0dae50c95040

heat/engine/resources/autoscaling.py
heat/tests/test_server_tags.py

index da937f11079302dd3b9d3c5933fa1db8bd662600..504a19ba0c8e45f81fd68f3a77aa6b56c64a9367 100644 (file)
@@ -130,6 +130,11 @@ class InstanceGroup(resource.Resource):
 
         conf = self.properties['LaunchConfigurationName']
         instance_definition = self.stack.t['Resources'][conf]
+
+        # honour the Tags property in the InstanceGroup and AutoScalingGroup
+        tags = self.properties.data.get('Tags', [])
+        instance_definition['Properties']['Tags'] = tags
+
         return GroupedInstance(name, instance_definition, self.stack)
 
     def _instances(self):
index 30a1dc8868d36a345f9aa8a17ed7833e42fdcb56..fd55c39c03b35cf4dd6b640e7efebd09f21b9ab3 100644 (file)
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
+import mox
 
 from heat.engine import environment
 from heat.tests.v1_1 import fakes
 from heat.engine.resources import instance as instances
+from heat.engine.resources import autoscaling
 from heat.common import template_format
 from heat.engine import parser
 from heat.engine import scheduler
@@ -49,6 +51,40 @@ instance_template = '''
 }
 '''
 
+group_template = '''
+{
+  "AWSTemplateFormatVersion" : "2010-09-09",
+  "Description" : "WordPress",
+  "Parameters" : {
+    "KeyName" : {
+      "Description" : "KeyName",
+      "Type" : "String",
+      "Default" : "test"
+    }
+  },
+  "Resources" : {
+    "Config": {
+      "Type": "AWS::AutoScaling::LaunchConfiguration",
+      "Properties": {
+        "ImageId"      : "CentOS 5.2",
+        "InstanceType" : "256 MB Server",
+        "KeyName"      : "test",
+        "UserData"     : "wordpress"
+      }
+    },
+
+    "WebServer": {
+      "Type": "OS::Heat::InstanceGroup",
+      "Properties": {
+        "AvailabilityZones"      : ["nova"],
+        "LaunchConfigurationName": "Config",
+        "Size"                   : "1"
+      }
+    }
+  }
+}
+'''
+
 
 class ServerTagsTest(HeatTestCase):
     def setUp(self):
@@ -97,3 +133,43 @@ class ServerTagsTest(HeatTestCase):
         # we are just using mock to verify that the tags get through to the
         # nova call.
         self.m.VerifyAll()
+
+    def _setup_test_group(self, intags=None, nova_tags=None):
+        stack_name = 'tag_test'
+        t = template_format.parse(group_template)
+        template = parser.Template(t)
+        stack = parser.Stack(None, stack_name, template,
+                             environment.Environment({'KeyName': 'test'}),
+                             stack_id=uuidutils.generate_uuid())
+
+        t['Resources']['WebServer']['Properties']['Tags'] = intags
+        group = autoscaling.InstanceGroup('WebServer',
+                                          t['Resources']['WebServer'],
+                                          stack)
+
+        self.m.StubOutWithMock(instances.Instance, 'nova')
+        instances.Instance.nova().MultipleTimes().AndReturn(self.fc)
+
+        group.t = group.stack.resolve_runtime_data(group.t)
+
+        # need to resolve the template functions
+        self.m.StubOutWithMock(self.fc.servers, 'create')
+        self.fc.servers.create(
+            image=1, flavor=1, key_name='test',
+            name=mox.IgnoreArg(),
+            security_groups=None,
+            userdata=mox.IgnoreArg(), scheduler_hints=None,
+            meta=nova_tags, nics=None, availability_zone=None).AndReturn(
+                self.fc.servers.list()[1])
+
+        return group
+
+    def test_group_tags(self):
+        tags = [{'Key': 'Food', 'Value': 'yum'}]
+        metadata = dict((tm['Key'], tm['Value']) for tm in tags)
+        group = self._setup_test_group(intags=tags, nova_tags=metadata)
+        self.m.ReplayAll()
+        scheduler.TaskRunner(group.create)()
+        # we are just using mock to verify that the tags get through to the
+        # nova call.
+        self.m.VerifyAll()