jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/puppet/extra/puppet-classifier b/puppet/extra/puppet-classifier
index a2b7b52..8346aeb 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 not isinstance(manifest, dict):
+        raise ValueError('Manifest document must be a mapping.')
+    if not isinstance(manifest.get('classes'), list):
+        raise ValueError('Manifest document must define a "classes" key that '
+                         'has a list of classes as its value.')
+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: merged
Gerrit-Change-Id: If1c751625a972e94ab22b1671e36f78d3392b19f
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to