Extra Ansible roles to automate TripleO deployments
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zuul_deps.py 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/python
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  11. # implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. DOCUMENTATION = '''
  15. ---
  16. module: zuul_deps
  17. version_added: "2.0"
  18. short_description: Transforms the dependent changes variable from Zuul format into a dictionary
  19. description:
  20. - Transforms the dependent changes variable from Zuul format into a dictionary
  21. options:
  22. host:
  23. description:
  24. - The content of the ZUUL_URL variable
  25. required: True
  26. changes:
  27. description:
  28. - The content of the ZUUL_CHANGES variable
  29. required: True
  30. branch:
  31. description:
  32. - Which branch to transform dependent changes on.
  33. default: None
  34. '''
  35. EXAMPLES = '''
  36. - zuul_deps:
  37. host: https://review.opendev.org
  38. changes: "openstack/tripleo-heat-templates:master:refs/changes/88/296488/1^openstack/instack-undercloud:master:refs/changes/84/315184/5"
  39. '''
  40. def process(host, changes, branch):
  41. """Process the changes from Zuul format"""
  42. output = []
  43. for item in reversed(changes.split("^")):
  44. params = item.split(":")
  45. if branch and branch != params[1]:
  46. continue
  47. if params[0] in [i['project'] for i in output]:
  48. continue
  49. # add URL prefix if only the bare hostname is given
  50. if host.find('://') == -1:
  51. host = ''.join(['https://', host])
  52. output.append({"host": host,
  53. "project": params[0],
  54. "branch": params[1],
  55. "refspec": params[2]})
  56. return {'changed': True,
  57. 'ansible_facts': {'zuul_change_list': output}}
  58. def main():
  59. module = AnsibleModule(
  60. argument_spec=dict(
  61. host=dict(required=True, type='str'),
  62. changes=dict(required=True, type='str'),
  63. branch=dict(default=None, type='str')
  64. )
  65. )
  66. result = process(module.params['host'],
  67. module.params['changes'],
  68. module.params['branch'])
  69. module.exit_json(**result)
  70. # see http://docs.ansible.com/developing_modules.html#common-module-boilerplate
  71. from ansible.module_utils.basic import *
  72. if __name__ == "__main__":
  73. main()