diff --git a/roles/build-test-packages/library/jenkins_deps.py b/roles/build-test-packages/library/jenkins_deps.py index f0a4ff68b..ef617794d 100755 --- a/roles/build-test-packages/library/jenkins_deps.py +++ b/roles/build-test-packages/library/jenkins_deps.py @@ -1,4 +1,16 @@ #!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. DOCUMENTATION = ''' --- @@ -40,8 +52,6 @@ EXAMPLES = ''' import json import logging import re -import sys - import requests # we ignore any other host reference @@ -70,7 +80,7 @@ def parse_commit_msg(current_host, msg): break else: logging.warning('Cannot resolve "%s" to a host from the ' - 'ALLOWED HOSTS list', target) + 'ALLOWED HOSTS list', target) continue tags.append({'host': host, 'change_id': change_id, @@ -119,7 +129,7 @@ def get_details(host, change_id, branch, revision): revision = data['current_revision'] if revision not in data['revisions']: return {'fail_msg': ''.join(['warning: cannot find revision ', - revision, ' of change ', change_id, + revision, ' of change ', change_id, ' at ', url])} return {'host': host, 'change_id': str(data['change_id']), @@ -131,7 +141,8 @@ def get_details(host, change_id, branch, revision): def resolve_dep(host, change_id, branch, revision): - ''' + '''Dependency resolution. + Resolve the dependencies in the target commits until there are no more dependent changes. If the branch or revision is None, it can still resolve the dependencies. It only uses the branch when the change_id is ambigiuous @@ -141,6 +152,7 @@ def resolve_dep(host, change_id, branch, revision): project to be added to the output list. Returns a list of dictionaries with the dependent changes. + ''' resolved_ids = [] deps = [] @@ -199,9 +211,9 @@ def main(): ) ) result = resolve_dep(module.params['host'], - module.params['change_id'], - module.params['branch'], - module.params['patchset_rev']) + module.params['change_id'], + module.params['branch'], + module.params['patchset_rev']) module.exit_json(**result) diff --git a/roles/build-test-packages/library/zuul_deps.py b/roles/build-test-packages/library/zuul_deps.py index 401d24162..796131c6a 100755 --- a/roles/build-test-packages/library/zuul_deps.py +++ b/roles/build-test-packages/library/zuul_deps.py @@ -1,4 +1,16 @@ -#!/usr/bin/env python +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. DOCUMENTATION = ''' --- @@ -24,7 +36,6 @@ EXAMPLES = ''' changes: "openstack/tripleo-heat-templates:master:refs/changes/88/296488/1^openstack/instack-undercloud:master:refs/changes/84/315184/5" ''' -import sys def process(host, changes): """Process the changes from Zuul format""" diff --git a/roles/gate-quickstart/library/jenkins_deps.py b/roles/gate-quickstart/library/jenkins_deps.py index 0c88d94dc..09580cbe6 100644 --- a/roles/gate-quickstart/library/jenkins_deps.py +++ b/roles/gate-quickstart/library/jenkins_deps.py @@ -1,4 +1,16 @@ #!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. DOCUMENTATION = ''' --- @@ -40,8 +52,6 @@ EXAMPLES = ''' import json import logging import re -import sys - import requests # we ignore any other host reference @@ -70,7 +80,7 @@ def parse_commit_msg(current_host, msg): break else: logging.warning('Cannot resolve "%s" to a host from the ' - 'ALLOWED HOSTS list', target) + 'ALLOWED HOSTS list', target) continue tags.append({'host': host, 'change_id': change_id, @@ -119,7 +129,7 @@ def get_details(host, change_id, branch, revision): revision = data['current_revision'] if revision not in data['revisions']: return {'fail_msg': ''.join(['warning: cannot find revision ', - revision, ' of change ', change_id, + revision, ' of change ', change_id, ' at ', url])} return {'host': host, 'change_id': str(data['change_id']), @@ -131,7 +141,8 @@ def get_details(host, change_id, branch, revision): def resolve_dep(host, change_id, branch, revision): - ''' + '''Dependency resolution. + Resolve the dependencies in the target commits until there are no more dependent changes. If the branch or revision is None, it can still resolve the dependencies. It only uses the branch when the change_id is ambigiuous @@ -142,6 +153,7 @@ def resolve_dep(host, change_id, branch, revision): Returns a list of dictionaries with the dependent changes. ''' + resolved_ids = [] deps = [] to_resolve = [{'host': host, @@ -199,9 +211,9 @@ def main(): ) ) result = resolve_dep(module.params['host'], - module.params['change_id'], - module.params['branch'], - module.params['patchset_rev']) + module.params['change_id'], + module.params['branch'], + module.params['patchset_rev']) module.exit_json(**result) diff --git a/roles/ovb-manage-stack/library/os_stack.py b/roles/ovb-manage-stack/library/os_stack.py index 78084fb67..33e39a99d 100644 --- a/roles/ovb-manage-stack/library/os_stack.py +++ b/roles/ovb-manage-stack/library/os_stack.py @@ -1,23 +1,22 @@ #!/usr/bin/python -#coding: utf-8 -*- - +# coding: utf-8 -*- +# # (c) 2016, Mathieu Bultel # (c) 2016, Steve Baker # -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# http://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this software. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. -from time import sleep from distutils.version import StrictVersion try: import shade @@ -152,25 +151,27 @@ stack: 'updated_time': null}" ''' + def _create_stack(module, stack, cloud): try: stack = cloud.create_stack(module.params['name'], - template_file=module.params['template'], - environment_files=module.params['environment'], - timeout=module.params['timeout'], - wait=True, - rollback=module.params['rollback'], - **module.params['parameters']) + template_file=module.params['template'], + environment_files=module.params['environment'], + timeout=module.params['timeout'], + wait=True, + rollback=module.params['rollback'], + **module.params['parameters']) stack = cloud.get_stack(stack.id, None) if stack.stack_status == 'CREATE_COMPLETE': return stack else: return False - module.fail_json(msg = "Failure in creating stack: ".format(stack)) + module.fail_json(msg="Failure in creating stack: ".format(stack)) except shade.OpenStackCloudException as e: module.fail_json(msg=str(e)) + def _update_stack(module, stack, cloud): try: stack = cloud.update_stack( @@ -184,11 +185,12 @@ def _update_stack(module, stack, cloud): if stack['stack_status'] == 'UPDATE_COMPLETE': return stack else: - module.fail_json(msg = "Failure in updating stack: %s" % + module.fail_json(msg="Failure in updating stack: %s" % stack['stack_status_reason']) except shade.OpenStackCloudException as e: module.fail_json(msg=str(e)) + def _system_state_change(module, stack, cloud): state = module.params['state'] if state == 'present': @@ -198,6 +200,7 @@ def _system_state_change(module, stack, cloud): return True return False + def main(): argument_spec = openstack_full_argument_spec( @@ -255,8 +258,9 @@ def main(): except shade.OpenStackCloudException as e: module.fail_json(msg=str(e)) + from ansible.module_utils.basic import * from ansible.module_utils.openstack import * + if __name__ == '__main__': main() - diff --git a/roles/overcloud-ssl/library/tls_tht.py b/roles/overcloud-ssl/library/tls_tht.py index 56eefb55a..ded2b049a 100644 --- a/roles/overcloud-ssl/library/tls_tht.py +++ b/roles/overcloud-ssl/library/tls_tht.py @@ -1,20 +1,20 @@ #!/usr/bin/python # coding: utf-8 -*- - +# # (c) 2016, Adriano Petrich # -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# http://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this software. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. DOCUMENTATION = ''' --- diff --git a/tox.ini b/tox.ini index ed0de4a16..070d5af72 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ usedevelop = True install_command = pip install -U {opts} {packages} setenv = VIRTUAL_ENV={envdir} deps = -r{toxinidir}/test-requirements.txt +whitelist_externals = bash [testenv:bindep] # Do not install any requirements. We want this to be fast and work even if @@ -20,25 +21,45 @@ commands = bindep test [testenv:docs] commands = python setup.py build_sphinx -[testenv:linters] -basepython=python2 -whitelist_externals = bash +[testenv:pep8] +commands = + # Run hacking/flake8 check for all python files + bash -c "grep --recursive --binary-files=without-match \ + --files-with-match '^.!.*python$' \ + --exclude-dir .tox \ + --exclude-dir .git \ + --exclude-dir .eggs \ + --exclude-dir *.egg-info \ + --exclude-dir dist \ + --exclude-dir *lib/python* \ + --exclude-dir doc \ + {toxinidir} | xargs flake8 --verbose" + +[testenv:ansible-lint] +basepython=python2 commands = - flake8 bash ci-scripts/ansible-lint.sh [testenv:releasenotes] whitelist_externals = bash commands = bash -c ci-scripts/releasenotes_tox.sh +[testenv:linters] +commands = + {[testenv:pep8]commands} + {[testenv:ansible-lint]commands} + [testenv:venv] commands = {posargs} [flake8] # E123, E125 skipped as they are invalid PEP-8. - +# E402 module level import not at top of file +# E501 line too long +# F403 'from ansible.module_utils.basic import *' used; unable to detect undefined names +# H303 No wildcard (*) import +# H301 one import per line +# F405 ... may be undefined, or defined from star imports: show-source = True -ignore = E123,E125 +ignore = E123,E125,E402,E501,F403,H303,H301,F405 builtins = _ -# TODO(adarazs): reenable flake8 checks on roles after fixing them up -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,roles