]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add test cases to test valid and invalid keys in FindInMap
authorSteven Dake <sdake@redhat.com>
Fri, 11 May 2012 21:52:31 +0000 (14:52 -0700)
committerSteven Dake <sdake@redhat.com>
Fri, 11 May 2012 21:52:31 +0000 (14:52 -0700)
Partially Fixes issue #111

Signed-off-by: Steven Dake <sdake@redhat.com>
heat/tests/test_validate.py

index e1ca4d55bfcdb4e471d996e06efb2aa0a63d8c6d..ed46b987d60c9cbf19c74d87d327144fad790b96 100644 (file)
@@ -13,6 +13,7 @@ from nose import with_setup
 from heat.tests.v1_1 import fakes
 from heat.engine import instance as instances
 from heat.engine import volume as volumes
+from heat.engine import manager as managers
 import heat.db as db_api
 from heat.engine import parser
 
@@ -87,6 +88,104 @@ test_template_ref = '''
   }
 }
 '''
+test_template_findinmap_valid = '''
+{
+  "AWSTemplateFormatVersion" : "2010-09-09",
+  "Description" : "test.",
+  "Parameters" : {
+
+    "KeyName" : {
+      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
+      "Type" : "String"
+    }
+  },
+
+  "Resources" : {
+    "WikiDatabase": {
+      "Type": "AWS::EC2::Instance",
+      "Properties": {
+        "ImageId": "image_name",
+        "InstanceType": "m1.large",
+        "KeyName": "test_KeyName"
+      }
+    },
+    "DataVolume" : {
+      "Type" : "AWS::EC2::Volume",
+      "Properties" : {
+        "Size" : "6",
+        "AvailabilityZone" : "nova"
+      }
+    },
+
+    "MountPoint" : {
+      "Type" : "AWS::EC2::VolumeAttachment",
+      "Properties" : {
+        "InstanceId" : { "Ref" : "WikiDatabase" },
+        "VolumeId"  : { "Ref" : "DataVolume" },
+        "Device" : "/dev/vdb"
+      }
+    }
+  }
+}
+'''
+test_template_findinmap_invalid = '''
+{
+  "AWSTemplateFormatVersion" : "2010-09-09",
+  "Description" : "test.",
+  "Parameters" : {
+
+    "KeyName" : {
+      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
+      "Type" : "String"
+    }
+  },
+
+  "Mappings" : {
+    "AWSInstanceType2Arch" : {
+      "t1.micro"    : { "Arch" : "64" },
+      "m1.small"    : { "Arch" : "64" },
+      "m1.medium"   : { "Arch" : "64" },
+      "m1.large"    : { "Arch" : "64" },
+      "m1.xlarge"   : { "Arch" : "64" },
+      "m2.xlarge"   : { "Arch" : "64" },
+      "m2.2xlarge"  : { "Arch" : "64" },
+      "m2.4xlarge"  : { "Arch" : "64" },
+      "c1.medium"   : { "Arch" : "64" },
+      "c1.xlarge"   : { "Arch" : "64" },
+      "cc1.4xlarge" : { "Arch" : "64HVM" },
+      "cc2.8xlarge" : { "Arch" : "64HVM" },
+      "cg1.4xlarge" : { "Arch" : "64HVM" }
+    }
+  },
+  "Resources" : {
+    "WikiDatabase": {
+      "Type": "AWS::EC2::Instance",
+      "Properties": {
+        "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" },
+                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
+        "InstanceType": "m1.large",
+        "KeyName": "test_KeyName"
+      }
+    },
+    "DataVolume" : {
+      "Type" : "AWS::EC2::Volume",
+      "Properties" : {
+        "Size" : "6",
+        "AvailabilityZone" : "nova"
+      }
+    },
+
+    "MountPoint" : {
+      "Type" : "AWS::EC2::VolumeAttachment",
+      "Properties" : {
+        "InstanceId" : { "Ref" : "WikiDatabase" },
+        "VolumeId"  : { "Ref" : "DataVolume" },
+        "Device" : "/dev/vdb"
+      }
+    }
+  }
+}
+'''
 @attr(tag=['unit', 'validate'])
 @attr(speed='fast')
 class validateTest(unittest.TestCase):
@@ -182,6 +281,34 @@ class validateTest(unittest.TestCase):
         res = dict(stack.validate()['ValidateTemplateResult'])
         assert (res['Description'] != 'Successfully validated')
 
+    def test_validate_findinmap_valid(self):
+        t = json.loads(test_template_findinmap_valid)
+        t['Parameters']['KeyName']['Value'] = 'test'
+        params = {}
+        params['KeyStoneCreds'] = None
+
+        self.m.StubOutWithMock(instances.Instance, 'nova')
+        instances.Instance.nova().AndReturn(self.fc)
+        self.m.ReplayAll()
+
+        manager = managers.EngineManager()
+        res = dict(manager.validate_template(None, t, params)['ValidateTemplateResult'])
+        assert (res['Description'] == 'Successfully validated')
+
+    def test_validate_findinmap_invalid(self):
+        t = json.loads(test_template_findinmap_invalid)
+        t['Parameters']['KeyName']['Value'] = 'test'
+        params = {}
+        params['KeyStoneCreds'] = None
+
+        self.m.StubOutWithMock(instances.Instance, 'nova')
+        instances.Instance.nova().AndReturn(self.fc)
+        self.m.ReplayAll()
+
+        manager = managers.EngineManager()
+        res = dict(manager.validate_template(None, t, params)['ValidateTemplateResult'])
+        assert (res['Description'] != 'Successfully validated')
+
     # allows testing of the test directly, shown below
     if __name__ == '__main__':
         sys.argv.append(__file__)