Ejemplo n.º 1
0
 def test_failure_get_conditions_from_path(self):
     """ Test get conditions from path when things arne't formatted correctly """
     temp_obj = cfnlint.helpers.convert_dict({
         'Resources': {
             'AMIIDLookup': {
                 'Type': 'AWS::Lambda::Function',
                 'Properties': {
                     'Role': {
                         'Fn::If': ['isPrimary', {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}]
                     }
                 }
             },
             'myInstance4': {
                 'Type': 'AWS::EC2::Instance',
                 'Properties': {
                     'InstanceType': {
                         'Fn::If': {
                             'Fn::If': ['isPrimary', 't3.2xlarge', 't3.xlarge']
                         }
                     }
                 }
             }
         }
     })
     template = Template('test.yaml', temp_obj)
     # Gets no condition names when it isn't a valid list
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'AMIIDLookup', 'Properties', 'Role', 'Fn::If',
                 1, 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']]
         ),
         {}
     )
     # Gets no condition names when it isn't really a list
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'myInstance4', 'Properties', 'InstanceType', 'Fn::If', 'Fn::If', 0]
         ),
         {}
     )
Ejemplo n.º 2
0
 def test_get_conditions_from_path(self):
     """ Test is resource available """
     temp_obj = cfnlint.helpers.convert_dict({
         'Resources': {
             'AMIIDLookup': {
                 'Type': 'AWS::Lambda::Function',
                 'Properties': {
                     'Role': {
                         'Fn::If': ['isPrimary', {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}, {'Ref': 'AWS::NoValue'}]
                     }
                 }
             },
             'InstanceProfile': {
                 'Condition': 'isPrimaryAndProduction',
                 'Type': 'AWS::IAM::InstanceProfile',
                 'Properties': {
                     'Path': '/',
                     'Roles': [{'Ref': 'LambdaExecutionRole'}]
                 }
             }
         },
         'Outputs': {
             'lambdaArn': {
                 'Condition': 'isPrimary',
                 'Value': {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}
             }
         }
     })
     template = Template('test.yaml', temp_obj)
     # Gets the condition when in the middle of the Path
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'AMIIDLookup', 'Properties', 'Role', 'Fn::If',
                 1, 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']]
         ),
         {'isPrimary': {True}}
     )
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'AMIIDLookup', 'Properties', 'Role', 'Fn::If']
         ),
         {'isPrimary': {True, False}}
     )
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Outputs', 'lambdaArn', 'Value', 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']]
         ),
         {'isPrimary': {True}}
     )
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'InstanceProfile', 'Properties', 'Roles', 0, 'Ref', 'LambdaExecutionRole']
         ),
         {'isPrimaryAndProduction': {True}}
     )
     self.assertEqual(
         template.get_conditions_from_path(
             template.template,
             ['Resources', 'AMIIDLookup', 'Properties', 'Handler', 'Ref', 'LambdaHandler']
         ),
         {}
     )