jenkins-bot has submitted this change and it was merged.
Change subject: Re-vamp Roles file
......................................................................
Re-vamp Roles file
Puppet swallows captures both stdout and stderr of the external node
classifier, making the verbose validation errors emitted by puppet-classifier
tragic and worthless.
This change makes the parsing of the file far more forgiving (it no longer
requires valid YAML input -- any line-oriented list of class names will do) and
it recovers from almost all errors, preferring to emit an empty
roster than to crash.
Change-Id: I2f805dbdead5b6ebde9dce231fef8e16f7f7362a
---
M .gitignore
M puppet/extra/enumerate-roles
M puppet/extra/puppet-classifier
M puppet/manifests/base.pp
4 files changed, 30 insertions(+), 24 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
index 9c23867..0cfab6b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
/no-update
/Vagrantfile-extra.rb
/Roles.yaml
+/Roles
/LocalSettings.php
/mediawiki/
/settings.d
diff --git a/puppet/extra/enumerate-roles b/puppet/extra/enumerate-roles
index 384b5a9..84605f5 100755
--- a/puppet/extra/enumerate-roles
+++ b/puppet/extra/enumerate-roles
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
- This script outputs the source for a starter 'Roles.yaml' file.
+ This script outputs the source for a starter 'Roles' file.
The output enumerates all available optional roles.
"""
diff --git a/puppet/extra/puppet-classifier b/puppet/extra/puppet-classifier
index 953a66c..2cb3924 100755
--- a/puppet/extra/puppet-classifier
+++ b/puppet/extra/puppet-classifier
@@ -7,31 +7,36 @@
for details.
"""
-from __future__ import print_function
+import sys
+reload(sys)
+sys.setdefaultencoding('utf-8')
import io
+import os
+import re
import sys
+import syslog
import yaml
-
-empty = dict(classes=[])
-
+# Migrate Roles.yaml -> Roles
try:
- with io.open('/vagrant/Roles.yaml', encoding='utf-8') as f:
- manifest = yaml.load(f)
- if not isinstance(manifest, dict):
- raise ValueError('Manifest document must be a mapping.')
- if manifest.get('classes') is None:
- manifest['classes'] = []
- if not isinstance(manifest['classes'], list):
- raise ValueError('"classes" must be a list or null.')
+ os.rename('/vagrant/Roles.yaml', '/vagrant/Roles')
+except Exception:
+ pass
+
+
+classes = []
+try:
+ with open('/vagrant/Roles') as f:
+ for line in f:
+ line = re.sub('(^\s*-\s*|[#%].*$)', '', line).strip()
+ if line not in ('', '--', 'classes:'):
+ classes.append(line)
+ assert 1 == 0, 'yay worked'
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))
+ pass
+except Exception as e:
+ syslog.syslog(syslog.LOG_ERR, '{0.__class__.__name__}: {0.args}'.format(e))
+finally:
+ print('classes: %s\n' % classes)
diff --git a/puppet/manifests/base.pp b/puppet/manifests/base.pp
index d75b91f..4d397f0 100644
--- a/puppet/manifests/base.pp
+++ b/puppet/manifests/base.pp
@@ -50,9 +50,9 @@
ensure => present,
}
-exec { 'generate Roles.yaml':
- command => '/vagrant/puppet/extra/enumerate-roles > /vagrant/Roles.yaml',
- creates => '/vagrant/Roles.yaml',
+exec { 'generate roles file':
+ command => '/vagrant/puppet/extra/enumerate-roles > /vagrant/Roles',
+ creates => '/vagrant/Roles',
}
Package['python-pip'] -> Package <| provider == pip |>
--
To view, visit https://gerrit.wikimedia.org/r/75069
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2f805dbdead5b6ebde9dce231fef8e16f7f7362a
Gerrit-PatchSet: 2
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: Spage <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits