Exemplo n.º 1
0
    def test_duplicate_key(self):
        # try dupes with top level keys
        yaml_validate_options = argparse.Namespace(
            command="c7n.commands.validate",
            config=None,
            configs=["tests/data/test_policies/dup-policies.yml"],
            debug=False,
            subparser="validate",
            verbose=False)

        with self.assertRaises(yaml.YAMLError) as err:
            validate_yaml_policies(yaml_validate_options)
        self.assertTrue('found duplicate key' in str(err.exception))

        # try dupes with policy attributes
        yaml_validate_options = argparse.Namespace(
            command="c7n.commands.validate",
            config=None,
            configs=["tests/data/test_policies/dup-policy-keys.yml"],
            debug=False,
            subparser="validate",
            verbose=False)

        with self.assertRaises(yaml.YAMLError) as err:
            validate_yaml_policies(yaml_validate_options)
        self.assertTrue('found duplicate key' in str(err.exception))
Exemplo n.º 2
0
    def test_duplicate_key(self):
        # try dupes with top level keys
        yaml_validate_options = argparse.Namespace(
            command="c7n.commands.validate",
            config=None,
            configs=[
                "tests/data/test_policies/dup-policies.yml"],
            debug=False,
            subparser="validate",
            verbose=False)

        with self.assertRaises(yaml.YAMLError) as err:
            validate_yaml_policies(yaml_validate_options)
        self.assertTrue('found duplicate key' in str(err.exception))

        # try dupes with policy attributes
        yaml_validate_options = argparse.Namespace(
            command="c7n.commands.validate",
            config=None,
            configs=[
                "tests/data/test_policies/dup-policy-keys.yml"],
            debug=False,
            subparser="validate",
            verbose=False)

        with self.assertRaises(yaml.YAMLError) as err:
            validate_yaml_policies(yaml_validate_options)
        self.assertTrue('found duplicate key' in str(err.exception))
Exemplo n.º 3
0
 def test_failed_validation(self):
     yaml_validate_options = argparse.Namespace(
         command='c7n.commands.validate',
         config=None,
         configs=[
             'tests/data/test_policies/ebs-BADVALIDATION.yml',
             'tests/data/test_policies/ami-GOODVALIDATION.yml'
         ],
         debug=False,
         subparser='validate',
         verbose=False)
     with self.assertRaises((SystemExit, ValueError)) as exit:
         validate_yaml_policies(yaml_validate_options)
     # if there is a bad policy in the batch being validated, there should be an exit 1
     self.assertEqual(exit.exception.code, 1)
     yaml_validate_options.configs.remove(
         'tests/data/test_policies/ebs-BADVALIDATION.yml')
     # if there are only good policy, it should exit none
     self.assertIsNone(validate_yaml_policies(yaml_validate_options))
Exemplo n.º 4
0
 def test_failed_validation(self):
     yaml_validate_options = argparse.Namespace(
         command = 'c7n.commands.validate',
         config  = None,
         configs = [
             'tests/data/test_policies/ebs-BADVALIDATION.yml',
             'tests/data/test_policies/ami-GOODVALIDATION.yml'
         ],
         debug=False,
         subparser='validate',
         verbose=False
     )
     with self.assertRaises(SystemExit) as exit:
         validate_yaml_policies(yaml_validate_options)
     # if there is a bad policy in the batch being validated, there should be an exit 1
     self.assertEqual(exit.exception.code, 1)
     yaml_validate_options.configs.remove('tests/data/test_policies/ebs-BADVALIDATION.yml')
     # if there are only good policy, it should exit none
     self.assertIsNone(validate_yaml_policies(yaml_validate_options))