Repository: cloud-custodian/cloud-custodian

Issue:
Schema tightening appears to have broken scheduled rules
This commit: https://github.com/capitalone/cloud-custodian/pull/1638/commits/3068ac2a0c010c2cca739d0618c4de03196feb6e

has disallowed additional properties on the 'mode' attribute. So far this is not bad, but it now means that the non-schema 'schedule' property of mode, used to specify periodicity for lambdas etc, is now illegal:

`
Traceback (most recent call last):
  File "/Users/joelgluth/src/cloud-custodian/bin/custodian", line 11, in <module>
    load_entry_point('c7n', 'console_scripts', 'custodian')()
  File "/Users/joelgluth/src/cloud-custodian/c7n/cli.py", line 398, in main
    command(options)
  File "/Users/joelgluth/src/cloud-custodian/c7n/commands.py", line 56, in _load_policies
    collection = policy_load(options, fp, vars=vars)
  File "/Users/joelgluth/src/cloud-custodian/c7n/policy.py", line 74, in load
    errors[1], errors[0]))
Exception: Failed to validate on policy ensure-tags-ec2
 Additional properties are not allowed ('schedule' was unexpected)

Failed validating u'additionalProperties' in schema[28][u'allOf'][0][u'properties'][u'mode']:
    {u'additionalProperties': False,
     u'properties': {u'dead_letter_config': {u'type': u'object'},
                     u'environment': {u'type': u'object'},
                     u'events': {u'items': {u'oneOf': [{u'type': u'string'},
                                                       {u'properties': {u'event': {u'type': u'string'},
                                                                        u'ids': {u'type': u'string'},
                                                                        u'source': {u'type': u'string'}},
                                                        u'required': [u'event',
                                                                      u'source',
                                                                      u'ids'],
                                                        u'type': u'object'}]},
                                 u'type': u'array'},
                     u'kms_key_arn': {u'type': u'string'},
                     u'memory': {u'type': u'number'},
                     u'role': {u'type': u'string'},
                     u'runtime': {u'enum': [u'python2.7', u'python3.6']},
                     u'tags': {u'type': u'object'},
                     u'timeout': {u'type': u'number'},
                     u'tracing_config': {u'type': u'object'},
                     u'type': {u'enum': [u'cloudtrail',
                                         u'ec2-instance-state',
                                         u'asg-instance-state',
                                         u'config-rule',
                                         u'periodic']}},
     u'required': [u'type'],
     u'type': u'object'}

On instance[u'mode']:
    {'role': 'arn:aws:iam::822426957823:role/cloud-custodian-lambda',
     'schedule': 'rate(1 hour)',
     'type': 'periodic'}
`

We either need to specify 'schedule' in the schema, or go back to allowing extra properties on mode.



Discussion:
Verified this has broken my periodic/schedule based policies which worked prior to updating to trunk this morning.  Reverted the commit and policies worked again.
noted, i'll add a test for this

Resolving patch:
diff --git a/c7n/schema.py b/c7n/schema.py
--- a/c7n/schema.py
+++ b/c7n/schema.py
@@ -210,7 +210,7 @@ def generate(resource_types=()):
                 'runtime': {'enum': ['python2.7', 'python3.6']},
                 'memory': {'type': 'number'},
                 'timeout': {'type': 'number'},
-
+                'schedule': {'type': 'string'},
                 'dead_letter_config': {'type': 'object'},
                 'environment': {'type': 'object'},
                 'kms_key_arn': {'type': 'string'},


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -292,6 +292,7 @@ def test_runtime(self):
                 'resource': 's3',
                 'mode': {
                     'type': 'periodic',
+                    'schedule': 'xyz',
                     'runtime': runtime}}]
             }
         errors_with = lambda r: list(Validator(generate()).iter_errors(data(r)))