Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/72763
Change subject: Perform strict and verbose validation of optional 'Roles.yaml'
file
......................................................................
Perform strict and verbose validation of optional 'Roles.yaml' file
This patch ensures that puppet-classifier fails when it encounters errors in
'Roles.yaml' and that it emits useful error messages. The previous behavior
was to swallow errors and hand over an empty manifest to Puppet. Matt correctly
noted that swallowing errors could lead to the removal of provisioned
configurations and was therefore unsafe.
Change-Id: If1c751625a972e94ab22b1671e36f78d3392b19f
---
M puppet/extra/puppet-classifier
1 file changed, 22 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant
refs/changes/63/72763/1
diff --git a/puppet/extra/puppet-classifier b/puppet/extra/puppet-classifier
index a2b7b52..538405f 100755
--- a/puppet/extra/puppet-classifier
+++ b/puppet/extra/puppet-classifier
@@ -7,13 +7,30 @@
for details.
"""
+from __future__ import print_function
+
import io
+import sys
import yaml
-manifest = dict(classes=[])
+
+empty = dict(classes=[])
+
try:
with io.open('/vagrant/Roles.yaml', encoding='utf-8') as f:
- manifest.update(yaml.load(f))
-except:
- pass
-print(yaml.dump(manifest))
+ manifest = yaml.load(f)
+ if isinstance(manifest, list):
+ manifest = dict(classes=manifest)
+ valid = isinstance(manifest, dict) and isinstance(manifest.get('classes'))
+ assert valid, ('Manifest must be a list of class names or a hash '
+ 'with a "classes" key.')
+except IOError:
+ # OK -- No Roles.yaml file.
+ print(yaml.dump(empty))
+except (AssertionError, TypeError, ValueError, yaml.YAMLError) as e:
+ print('Roles.yaml does not contain a valid YAML manifest.',
+ 'Please fix the file, or delete it to have it regenerated.',
+ 'Error: %s' % e, sep='\n', file=sys.stderr)
+ sys.exit(1)
+else:
+ print(yaml.dump(manifest))
--
To view, visit https://gerrit.wikimedia.org/r/72763
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If1c751625a972e94ab22b1671e36f78d3392b19f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits