Changeset 9d001db0a579a4224338ea1ec905a4603dadd635
- Timestamp:
- 06/25/08 19:35:14 (7 months ago)
- Author:
- Jonny Lamb <jonnylamb@…>
- Parents:
- 095675ba471b43d0a8fa08f604b71504f76810a7
- Children:
- 225a4625840e9adbbce4cecf55a0f5d453129fd8
- git-committer:
- Jonny Lamb <jonnylamb@jonnylamb.com> / 2008-06-25T18:35:14Z+0100
- Message:
-
Changed API of plugins to provide an outcomes dictionary and use tags.
Signed-off-by: Jonny Lamb <jonnylamb@…>
- Location:
- debexpo
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r095675
|
r9d001d
|
|
| 148 | 148 | |
| 149 | 149 | if hasattr(module, 'plugin'): |
| 150 | | p = getattr(module, 'plugin')(changes=self.changes, \ |
| | 150 | p = getattr(module, 'plugin')(name=plugin, changes=self.changes, \ |
| 151 | 151 | changes_file=self.changes_file, tempdir=self.tempdir, |
| 152 | 152 | user_id=self.user_id) |
-
|
r325bed
|
r9d001d
|
|
| 65 | 65 | return self.result |
| 66 | 66 | |
| 67 | | def passed(self, name, data, severity): |
| | 67 | def passed(self, outcome, data, severity): |
| 68 | 68 | """ |
| 69 | 69 | Adds a PluginResult for a passed test to the result list. |
| 70 | 70 | |
| 71 | | ``name`` |
| 72 | | Name of the plugin. |
| | 71 | ``outcome`` |
| | 72 | Outcome tag of the test. |
| 73 | 73 | |
| 74 | 74 | ``data`` |
| … |
… |
|
| 78 | 78 | Severity of the result. |
| 79 | 79 | """ |
| 80 | | self.result.append(PluginResult(from_plugin=name, outcome=constants.PLUGIN_OUTCOME_PASSED, |
| | 80 | self.result.append(PluginResult(from_plugin=self.name, outcome=outcome, |
| 81 | 81 | data=data, severity=severity)) |
| 82 | 82 | |
| 83 | | def failed(self, name, data, severity): |
| | 83 | def failed(self, outcome, data, severity): |
| 84 | 84 | """ |
| 85 | 85 | Adds a PluginResult for a failed test to the result list. |
| 86 | 86 | |
| 87 | | ``name`` |
| 88 | | Name of the plugin. |
| | 87 | ``outcome`` |
| | 88 | Outcome tag of the test. |
| 89 | 89 | |
| 90 | 90 | ``data`` |
| … |
… |
|
| 95 | 95 | |
| 96 | 96 | """ |
| 97 | | self.result.append(PluginResult(from_plugin=name, outcome=constants.PLUGIN_OUTCOME_FAILED, |
| | 97 | self.result.append(PluginResult(from_plugin=self.name, outcome=outcome, |
| 98 | 98 | data=data, severity=severity)) |
| 99 | 99 | |
| 100 | | def info(self, name, data): |
| | 100 | def info(self, outcome, data): |
| 101 | 101 | """ |
| 102 | 102 | Adds a PluginResult for an info test to the result list. |
| 103 | 103 | |
| 104 | | ``name`` |
| 105 | | Name of the plugin. |
| | 104 | ``outcome`` |
| | 105 | Outcome tag of the test. |
| 106 | 106 | |
| 107 | 107 | ``data`` |
| 108 | 108 | Resulting data from the plugin, like more detail about the process. |
| 109 | 109 | """ |
| 110 | | self.result.append(PluginResult(from_plugin=name, outcome=constants.PLUGIN_OUTCOME_INFO, |
| | 110 | self.result.append(PluginResult(from_plugin=self.name, outcome=outcome, |
| 111 | 111 | data=data, severity=constants.PLUGIN_SEVERITY_INFO)) |
| 112 | 112 | |
| … |
… |
|
| 141 | 141 | Returns whether the test failed. |
| 142 | 142 | """ |
| 143 | | return self.outcome == constants.PLUGIN_OUTCOME_FAILED |
| | 143 | return self.severity > constants.PLUGIN_SEVERITY_INFO |
| 144 | 144 | |
| 145 | 145 | def stop(self): |
-
|
r095675
|
r9d001d
|
|
| 58 | 58 | sum = md5sum(os.path.join(config['debexpo.upload.incoming'], file['name'])) |
| 59 | 59 | |
| 60 | | data = 'Changes file says md5sum is: %s\n' % file['md5sum'] |
| 61 | | data += 'Actual md5sum of file is: %s' % sum |
| | 60 | data = 'Changes file says md5sum of %s is: %s\n' % (file['name'], file['md5sum']) |
| | 61 | data += 'Actual md5sum of %s is: %s' % (file['name'], sum) |
| 62 | 62 | |
| 63 | 63 | if sum != file['md5sum']: |
| 64 | | log.error('%s != %s; test failed' % (sum, file['md5sum'])) |
| 65 | | self.failed(__name__, data, constants.PLUGIN_SEVERITY_ERROR) |
| | 64 | log.error('%s != %s' % (sum, file['md5sum'])) |
| | 65 | self.failed('md5sum-not-match', data, constants.PLUGIN_SEVERITY_ERROR) |
| 66 | 66 | else: |
| 67 | 67 | log.debug('Test passed') |
| 68 | | self.passed(__name__, data, constants.PLUGIN_SEVERITY_INFO) |
| | 68 | self.passed('md5sum-match', None, constants.PLUGIN_SEVERITY_INFO) |
| 69 | 69 | |
| 70 | 70 | plugin = CheckFilesPlugin |
| | 71 | |
| | 72 | outcomes = { |
| | 73 | 'md5sum-not-match' : { 'name' : 'A package source file\'s md5sum does match its changes value' }, |
| | 74 | 'md5sum-match' : { 'name' : 'A package source file\'s md5sum matches its changes value' }, |
| | 75 | } |
-
|
r095675
|
r9d001d
|
|
| 77 | 77 | if self._package_in_descriptions(name, binary_packages): |
| 78 | 78 | log.debug('Bug #%s belongs to this package' % bug) |
| 79 | | self.passed(__name__, 'Bug #%s belongs to this package', constants.PLUGIN_SEVERITY_INFO) |
| | 79 | self.passed('bug-in-package', None, constants.PLUGIN_SEVERITY_INFO) |
| 80 | 80 | else: |
| 81 | 81 | log.error('Bug #%s does not belong to this package' % bug) |
| 82 | | self.failed(__name__, 'Bug #%s does not belong to this package', constants.PLUGIN_SEVERITY_ERROR) |
| | 82 | self.failed('bug-not-in-package', bug, constants.PLUGIN_SEVERITY_ERROR) |
| 83 | 83 | |
| 84 | 84 | except KeyError: |
| … |
… |
|
| 103 | 103 | |
| 104 | 104 | plugin = ClosedBugsPlugin |
| | 105 | |
| | 106 | outcomes = { |
| | 107 | 'bug-not-in-package' : { 'name' : 'A bug closed in this package doesn\'t belong to this package' }, |
| | 108 | 'bug-in-package' : { 'name' : 'A bug closed in this package belongs to this package' }, |
| | 109 | } |
-
|
r095675
|
r9d001d
|
|
| 45 | 45 | log = logging.getLogger(__name__) |
| 46 | 46 | |
| | 47 | fields = ['Homepage', 'Vcs-Browser', 'Vcs-Git', 'Vcs-Svn', 'Vcs-Bzr', 'Vcs-Hg'] |
| | 48 | |
| | 49 | def _gen_outcomes(): |
| | 50 | outcomes = {} |
| | 51 | |
| | 52 | for field in fields: |
| | 53 | for isisnot in ['', '-not']: |
| | 54 | outcomes['%s-is%s-present' % (field.lower(), isisnot)] = \ |
| | 55 | 'The %s field is%s present in debian/control' % (field, isisnot.replace('-', ' ')) |
| | 56 | |
| | 57 | return outcomes |
| | 58 | |
| 47 | 59 | class ControlFieldsPlugin(BasePlugin): |
| 48 | 60 | tests = ['check_control_fields'] |
| … |
… |
|
| 60 | 72 | return |
| 61 | 73 | |
| 62 | | for item in ['Homepage', 'Vcs-Browser', 'Vcs-Git', 'Vcs-Svn', 'Vcs-Bzr', 'Vcs-Hg']: |
| 63 | | |
| 64 | | try: |
| 65 | | self.info(__name__, '%s field is present: %s' % (item, dsc[item])) |
| 66 | | log.debug('%s field is present: %s' % (item, dsc[item])) |
| 67 | | except KeyError: |
| | 74 | for item in fields: |
| | 75 | if item in dsc: |
| | 76 | self.info('%s-is-present' % item.lower(), '%s: %s' % (item, dsc[item])) |
| | 77 | log.debug('%s: %s' % (item, dsc[item])) |
| | 78 | else: |
| | 79 | self.info('%s-is-not-present' % item.lower(), item) |
| 68 | 80 | log.debug('%s field is not present' % item) |
| 69 | 81 | |
| 70 | 82 | plugin = ControlFieldsPlugin |
| | 83 | |
| | 84 | outcomes = _gen_outcomes() |
-
|
r095675
|
r9d001d
|
|
| 60 | 60 | return |
| 61 | 61 | |
| 62 | | diffstat = commands.getoutput('diffstat -p1 -l %s' % difffile) |
| | 62 | diffstat = commands.getoutput('diffstat -p1 %s' % difffile) |
| 63 | 63 | |
| 64 | 64 | dirty = False |
| 65 | 65 | for item in diffstat.split('\n'): |
| 66 | | if not item.startswith('debian/'): |
| | 66 | if not item.startswith(' debian/'): |
| 67 | 67 | dirty = True |
| 68 | 68 | break |
| … |
… |
|
| 70 | 70 | if not dirty: |
| 71 | 71 | log.debug('Diff file %s is clean' % difffile) |
| 72 | | self.passed(__name__, 'Diff file %s is clean' % difffile, constants.PLUGIN_SEVERITY_INFO) |
| | 72 | self.passed('diff-clean', None, constants.PLUGIN_SEVERITY_INFO) |
| 73 | 73 | else: |
| 74 | 74 | log.error('Diff file %s is not clean' % difffile) |
| 75 | | self.failed(__name__, 'Diff file %s is not clean' % difffile, constants.PLUGIN_SEVERITY_ERROR) |
| | 75 | self.failed('diff-dirty', diffstat, constants.PLUGIN_SEVERITY_ERROR) |
| 76 | 76 | |
| 77 | 77 | plugin = DiffCleanPlugin |
| | 78 | |
| | 79 | outcomes = { |
| | 80 | 'diff-clean' : { 'name' : 'The diff.gz file is clean' }, |
| | 81 | 'diff-dirty' : { 'name' : 'The diff.gz file is dirty' }, |
| | 82 | } |
-
|
r095675
|
r9d001d
|
|
| 66 | 66 | if contents.startswith('-----BEGIN PGP SIGNED MESSAGE-----'): |
| 67 | 67 | log.debug('File %s is GPG signed' % filename) |
| 68 | | self.passed(__name__, 'File %s is GPG signed' % filename, constants.PLUGIN_SEVERITY_INFO) |
| | 68 | self.passed('gpg-signed', filename, constants.PLUGIN_SEVERITY_INFO) |
| 69 | 69 | else: |
| 70 | 70 | log.error('File %s is not GPG signed' % filename) |
| 71 | | self.failed(__name__, 'File %s is not GPG signed' % filename, constants.PLUGIN_SEVERITY_ERROR) |
| | 71 | self.failed('not-gpg-signed', filename, constants.PLUGIN_SEVERITY_ERROR) |
| 72 | 72 | |
| 73 | 73 | plugin = GpgSignedPlugin |
| | 74 | |
| | 75 | outcomes = { |
| | 76 | 'gpg-signed' : { 'name' : 'A file is GPG signed' }, |
| | 77 | 'not-gpg-signed' : { 'name' : 'A file is not GPG signed, and it should be' }, |
| | 78 | } |
-
|
r095675
|
r9d001d
|
|
| 61 | 61 | if items and output != '': |
| 62 | 62 | severity = constants.PLUGIN_SEVERITY_WARNING |
| | 63 | outcome = 'lintian-warnings' |
| 63 | 64 | logmessage = log.warning |
| 64 | 65 | for item in items: |
| 65 | 66 | if item.startswith('E:'): |
| 66 | 67 | severity = constants.PLUGIN_SEVERITY_ERROR |
| | 68 | outcome = 'lintian-errors' |
| 67 | 69 | logmessage = log.error |
| 68 | 70 | break |
| 69 | 71 | |
| 70 | | output = 'Package is not Lintian clean\n' + output |
| 71 | 72 | logmessage('Package is not Lintian clean') |
| 72 | | self.failed(__name__, output, severity) |
| | 73 | self.failed(outcome, output, severity) |
| 73 | 74 | else: |
| 74 | 75 | log.debug('Package is Lintian clean') |
| 75 | | self.passed(__name__, 'Package is Lintian clean', constants.PLUGIN_SEVERITY_INFO) |
| | 76 | self.passed('lintian-clean', None, constants.PLUGIN_SEVERITY_INFO) |
| 76 | 77 | |
| 77 | 78 | plugin = LintianPlugin |
| | 79 | |
| | 80 | outcomes = { |
| | 81 | 'lintian-clean' : { 'name' : 'Package is Lintian clean' }, |
| | 82 | 'lintian-warnings' : { 'name' : 'Package has Lintian warnings' }, |
| | 83 | 'lintian-errors' : { 'name' : 'Package has Lintian errors' }, |
| | 84 | } |
-
|
r095675
|
r9d001d
|
|
| 66 | 66 | if user.email == email[1:-1]: |
| 67 | 67 | log.debug('Maintainer email is the same as the uploader') |
| 68 | | self.passed(__name__, 'Maintainer email is the same as the uploader', constants.PLUGIN_SEVERITY_INFO) |
| | 68 | self.passed('maintainer-is-uploader', None, constants.PLUGIN_SEVERITY_INFO) |
| 69 | 69 | else: |
| 70 | 70 | log.warning('%s != %s' % (user.email, email[1:-1])) |
| 71 | | self.failed(__name__, 'Changes file is not GPG signed', constants.PLUGIN_SEVERITY_WARNING) |
| | 71 | self.failed('maintainer-is-not-uploader', '%s != %s' % (user.email, email[1:-1]), |
| | 72 | constants.PLUGIN_SEVERITY_WARNING) |
| 72 | 73 | |
| 73 | | log.warning('Could not get the uploader\'s user details from the database') |
| | 74 | else: |
| | 75 | log.warning('Could not get the uploader\'s user details from the database') |
| 74 | 76 | |
| 75 | 77 | plugin = MaintainerEmailPlugin |
| | 78 | |
| | 79 | outcomes = { |
| | 80 | 'maintainer-is-uploader' : { 'name' : 'The maintainer and uploader emails are the same' }, |
| | 81 | 'maintainer-is-not-uploader' : { 'name' : 'The maintainer and uploader emails are not the same' }, |
| | 82 | } |
-
|
r095675
|
r9d001d
|
|
| 62 | 62 | # package is almost probably in error. |
| 63 | 63 | log.warning('Package is native') |
| 64 | | self.failed(__name__, 'Package is native', constants.PLUGIN_SEVERITY_WARNING) |
| | 64 | self.failed('is-native', None, constants.PLUGIN_SEVERITY_WARNING) |
| 65 | 65 | else: |
| 66 | 66 | log.debug('Package is not native') |
| 67 | | self.passed(__name__, 'Package is not native', constants.PLUGIN_SEVERITY_INFO) |
| | 67 | self.passed('is-not-native', None, constants.PLUGIN_SEVERITY_INFO) |
| 68 | 68 | |
| 69 | 69 | plugin = NativePlugin |
| | 70 | |
| | 71 | outcomes = { |
| | 72 | 'is-native' : { 'name' : 'Package is native' }, |
| | 73 | 'is-not-native' : { 'name' : 'Package is not native' }, |
| | 74 | } |
-
|
r095675
|
r9d001d
|
|
| 70 | 70 | if self._watch_file_present(): |
| 71 | 71 | log.debug('Watch file present') |
| 72 | | self.passed(__name__, 'debian/watch file exists', constants.PLUGIN_SEVERITY_INFO) |
| | 72 | self.passed('watch-file-present', None, constants.PLUGIN_SEVERITY_INFO) |
| 73 | 73 | else: |
| 74 | 74 | log.warning('Watch file not present') |
| 75 | | self.failed(__name__, 'debian/watch does not exist', constants.PLUGIN_SEVERITY_WARNING) |
| | 75 | self.failed('watch-file-not-present', None, constants.PLUGIN_SEVERITY_WARNING) |
| 76 | 76 | |
| 77 | 77 | def check_watch_file_works(self): |
| … |
… |
|
| 84 | 84 | if self._watch_file_works(): |
| 85 | 85 | log.debug('Watch file works') |
| 86 | | self.passed(__name__, 'debian/watch file works', constants.PLUGIN_SEVERITY_INFO) |
| | 86 | self.passed('watch-file-works', None, constants.PLUGIN_SEVERITY_INFO) |
| 87 | 87 | else: |
| 88 | 88 | log.warning('Watch file does not work') |
| 89 | | self.failed(__name__, 'debian/watch file does not work\n' + self.output, constants.PLUGIN_SEVERITY_WARNING) |
| | 89 | self.failed('watch-file-does-not-work', self.output, constants.PLUGIN_SEVERITY_WARNING) |
| 90 | 90 | |
| 91 | 91 | def check_new_upstream(self): |
| … |
… |
|
| 99 | 99 | if self.status == 256: |
| 100 | 100 | log.debug('Package is the latest upstream version') |
| 101 | | self.passed(__name__, 'Package is the latest upstream version', constants.PLUGIN_SEVERITY_INFO) |
| | 101 | self.passed('no-new-upstream-version', None, constants.PLUGIN_SEVERITY_INFO) |
| 102 | 102 | else: |
| 103 | 103 | log.warning('Package is not the latest upstream version') |
| 104 | | self.failed(__name__, 'Package is not the latest upstream version\n' + self.output, constants.PLUGIN_SEVERITY_WARNING) |
| | 104 | self.failed('new-upstream-available', self.output, constants.PLUGIN_SEVERITY_WARNING) |
| 105 | 105 | |
| 106 | 106 | plugin = WatchFilePlugin |
| | 107 | |
| | 108 | outcomes = { |
| | 109 | 'watch-file-present' : { 'name' : 'A watch file is present' }, |
| | 110 | 'watch-file-not-present' : { 'name' : 'A watch file is not present' }, |
| | 111 | 'watch-file-works' : { 'name' : 'The watch file works' }, |
| | 112 | 'watch-file-does-not-work' : { 'name' : 'The watch file does not work' }, |
| | 113 | 'new-upstream-available' : { 'name' : 'A new upstream version is available' }, |
| | 114 | 'no-new-upstream-available' : { 'name' : 'Package is the latest upstream version' }, |
| | 115 | } |