Pep8 fixes for rabbitmq modules (#24590)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-08-10 15:27:11 +05:30 committed by René Moser
parent 85fc4c67ef
commit f7321a87ca
9 changed files with 192 additions and 207 deletions

View file

@ -134,6 +134,7 @@ def main():
if not HAS_REQUESTS: if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`") module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
result = dict(changed=False, name=module.params['name'])
if module.params['destination_type'] == "queue": if module.params['destination_type'] == "queue":
dest_type = "q" dest_type = "q"
@ -145,9 +146,9 @@ def main():
else: else:
props = urllib_parse.quote(module.params['routing_key'], '') props = urllib_parse.quote(module.params['routing_key'], '')
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % ( base_url = "http://%s:%s/api/bindings" % (module.params['login_host'], module.params['login_port'])
module.params['login_host'],
module.params['login_port'], url = "%s/%s/e/%s/%s/%s/%s" % (base_url,
urllib_parse.quote(module.params['vhost'], ''), urllib_parse.quote(module.params['vhost'], ''),
urllib_parse.quote(module.params['name'], ''), urllib_parse.quote(module.params['name'], ''),
dest_type, dest_type,
@ -177,19 +178,16 @@ def main():
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
if module.params['state'] == 'present': if module.params['state'] == 'present':
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s" % ( url = "%s/%s/e/%s/%s/%s" % (
module.params['login_host'], base_url,
module.params['login_port'],
urllib_parse.quote(module.params['vhost'], ''), urllib_parse.quote(module.params['vhost'], ''),
urllib_parse.quote(module.params['name'], ''), urllib_parse.quote(module.params['name'], ''),
dest_type, dest_type,
@ -209,11 +207,9 @@ def main():
r = requests.delete(url, auth=(module.params['login_user'], module.params['login_password'])) r = requests.delete(url, auth=(module.params['login_user'], module.params['login_password']))
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, result['destination'] = module.params['destination']
name = module.params['name'], module.exit_json(**result)
destination = module.params['destination']
)
else: else:
module.fail_json( module.fail_json(
msg="Error creating exchange", msg="Error creating exchange",
@ -222,11 +218,8 @@ def main():
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -135,6 +135,8 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
result = dict(changed=False, name=module.params['name'])
url = "http://%s:%s/api/exchanges/%s/%s" % ( url = "http://%s:%s/api/exchanges/%s/%s" % (
module.params['login_host'], module.params['login_host'],
module.params['login_port'], module.params['login_port'],
@ -179,12 +181,10 @@ def main():
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
@ -206,10 +206,8 @@ def main():
# RabbitMQ 3.6.7 changed this response code from 204 to 201 # RabbitMQ 3.6.7 changed this response code from 204 to 201
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, module.exit_json(**result)
name = module.params['name']
)
else: else:
module.fail_json( module.fail_json(
msg="Error creating exchange", msg="Error creating exchange",
@ -218,11 +216,8 @@ def main():
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -65,7 +65,6 @@ EXAMPLES = """
state: present state: present
""" """
import json import json
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -114,6 +113,7 @@ class RabbitMqParameter(object):
def has_modifications(self): def has_modifications(self):
return self.value != self._value return self.value != self._value
def main(): def main():
arg_spec = dict( arg_spec = dict(
component=dict(required=True), component=dict(required=True),
@ -137,23 +137,26 @@ def main():
state = module.params['state'] state = module.params['state']
node = module.params['node'] node = module.params['node']
result = dict(changed=False)
rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost, node) rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost, node)
changed = False
if rabbitmq_parameter.get(): if rabbitmq_parameter.get():
if state == 'absent': if state == 'absent':
rabbitmq_parameter.delete() rabbitmq_parameter.delete()
changed = True result['changed'] = True
else: else:
if rabbitmq_parameter.has_modifications(): if rabbitmq_parameter.has_modifications():
rabbitmq_parameter.set() rabbitmq_parameter.set()
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_parameter.set() rabbitmq_parameter.set()
changed = True result['changed'] = True
module.exit_json(changed=changed, component=component, name=name, vhost=vhost, state=state)
result['component'] = component
result['name'] = name
result['vhost'] = vhost
result['state'] = state
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -57,11 +57,14 @@ EXAMPLES = '''
''' '''
import os import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
class RabbitMqPlugins(object): class RabbitMqPlugins(object):
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
@ -116,6 +119,7 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
result = dict()
names = module.params['names'].split(',') names = module.params['names'].split(',')
new_only = module.params['new_only'] new_only = module.params['new_only']
state = module.params['state'] state = module.params['state']
@ -142,8 +146,10 @@ def main():
rabbitmq_plugins.disable(plugin) rabbitmq_plugins.disable(plugin)
disabled.append(plugin) disabled.append(plugin)
changed = len(enabled) > 0 or len(disabled) > 0 result['changed'] = len(enabled) > 0 or len(disabled) > 0
module.exit_json(changed=changed, enabled=enabled, disabled=disabled) result['enabled'] = enabled
result['disabled'] = disabled
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -82,10 +82,13 @@ EXAMPLES = '''
tags: tags:
ha-mode: all ha-mode: all
''' '''
import json
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
class RabbitMqPolicy(object): class RabbitMqPolicy(object):
def __init__(self, module, name): def __init__(self, module, name):
self._module = module self._module = module
self._name = name self._name = name
@ -116,14 +119,13 @@ class RabbitMqPolicy(object):
return False return False
def set(self): def set(self):
import json
args = ['set_policy'] args = ['set_policy']
args.append(self._name) args.append(self._name)
args.append(self._pattern) args.append(self._pattern)
args.append(json.dumps(self._tags)) args.append(json.dumps(self._tags))
args.append('--priority') args.append('--priority')
args.append(self._priority) args.append(self._priority)
if (self._apply_to != 'all'): if self._apply_to != 'all':
args.append('--apply-to') args.append('--apply-to')
args.append(self._apply_to) args.append(self._apply_to)
return self._exec(args) return self._exec(args)
@ -153,19 +155,18 @@ def main():
state = module.params['state'] state = module.params['state']
rabbitmq_policy = RabbitMqPolicy(module, name) rabbitmq_policy = RabbitMqPolicy(module, name)
changed = False result = dict(changed=False, name=name, state=state)
if rabbitmq_policy.list(): if rabbitmq_policy.list():
if state == 'absent': if state == 'absent':
rabbitmq_policy.clear() rabbitmq_policy.clear()
changed = True result['changed'] = True
else: else:
changed = False result['changed'] = False
elif state == 'present': elif state == 'present':
rabbitmq_policy.set() rabbitmq_policy.set()
changed = True result['changed'] = True
module.exit_json(changed=changed, name=name, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -163,6 +163,8 @@ def main():
if not HAS_REQUESTS: if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`") module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
result = dict(changed=False, name=module.params['name'])
# Check if queue already exists # Check if queue already exists
r = requests.get(url, auth=(module.params['login_user'], module.params['login_password'])) r = requests.get(url, auth=(module.params['login_user'], module.params['login_password']))
@ -215,7 +217,6 @@ def main():
msg="RabbitMQ RESTAPI doesn't support attribute changes for existing queues", msg="RabbitMQ RESTAPI doesn't support attribute changes for existing queues",
) )
# Copy parameters to arguments as used by RabbitMQ # Copy parameters to arguments as used by RabbitMQ
for k, v in { for k, v in {
'message_ttl': 'x-message-ttl', 'message_ttl': 'x-message-ttl',
@ -229,12 +230,10 @@ def main():
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
@ -254,10 +253,8 @@ def main():
# RabbitMQ 3.6.7 changed this response code from 204 to 201 # RabbitMQ 3.6.7 changed this response code from 204 to 201
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, module.exit_json(**result)
name = module.params['name']
)
else: else:
module.fail_json( module.fail_json(
msg="Error creating queue", msg="Error creating queue",
@ -266,11 +263,8 @@ def main():
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -229,6 +229,7 @@ class RabbitMqUser(object):
def has_permissions_modifications(self): def has_permissions_modifications(self):
return sorted(self._permissions) != sorted(self.permissions) return sorted(self._permissions) != sorted(self.permissions)
def main(): def main():
arg_spec = dict( arg_spec = dict(
user=dict(required=True, aliases=['username', 'name']), user=dict(required=True, aliases=['username', 'name']),
@ -261,7 +262,7 @@ def main():
node = module.params['node'] node = module.params['node']
bulk_permissions = True bulk_permissions = True
if permissions == []: if not permissions:
perm = { perm = {
'vhost': vhost, 'vhost': vhost,
'configure_priv': configure_priv, 'configure_priv': configure_priv,
@ -274,33 +275,33 @@ def main():
rabbitmq_user = RabbitMqUser(module, username, password, tags, permissions, rabbitmq_user = RabbitMqUser(module, username, password, tags, permissions,
node, bulk_permissions=bulk_permissions) node, bulk_permissions=bulk_permissions)
changed = False result = dict(changed=False, user=username, state=state)
if rabbitmq_user.get(): if rabbitmq_user.get():
if state == 'absent': if state == 'absent':
rabbitmq_user.delete() rabbitmq_user.delete()
changed = True result['changed'] = True
else: else:
if force: if force:
rabbitmq_user.delete() rabbitmq_user.delete()
rabbitmq_user.add() rabbitmq_user.add()
rabbitmq_user.get() rabbitmq_user.get()
changed = True result['changed'] = True
if rabbitmq_user.has_tags_modifications(): if rabbitmq_user.has_tags_modifications():
rabbitmq_user.set_tags() rabbitmq_user.set_tags()
changed = True result['changed'] = True
if rabbitmq_user.has_permissions_modifications(): if rabbitmq_user.has_permissions_modifications():
rabbitmq_user.set_permissions() rabbitmq_user.set_permissions()
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_user.add() rabbitmq_user.add()
rabbitmq_user.set_tags() rabbitmq_user.set_tags()
rabbitmq_user.set_permissions() rabbitmq_user.set_permissions()
changed = True result['changed'] = True
module.exit_json(changed=changed, user=username, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -123,24 +123,22 @@ def main():
tracing = module.params['tracing'] tracing = module.params['tracing']
state = module.params['state'] state = module.params['state']
node = module.params['node'] node = module.params['node']
result = dict(changed=False, name=name, state=state)
rabbitmq_vhost = RabbitMqVhost(module, name, tracing, node) rabbitmq_vhost = RabbitMqVhost(module, name, tracing, node)
changed = False
if rabbitmq_vhost.get(): if rabbitmq_vhost.get():
if state == 'absent': if state == 'absent':
rabbitmq_vhost.delete() rabbitmq_vhost.delete()
changed = True result['changed'] = True
else: else:
if rabbitmq_vhost.set_tracing(): if rabbitmq_vhost.set_tracing():
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_vhost.add() rabbitmq_vhost.add()
rabbitmq_vhost.set_tracing() rabbitmq_vhost.set_tracing()
changed = True result['changed'] = True
module.exit_json(changed=changed, name=name, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -216,12 +216,6 @@ lib/ansible/modules/files/replace.py
lib/ansible/modules/files/synchronize.py lib/ansible/modules/files/synchronize.py
lib/ansible/modules/files/tempfile.py lib/ansible/modules/files/tempfile.py
lib/ansible/modules/files/xattr.py lib/ansible/modules/files/xattr.py
lib/ansible/modules/messaging/rabbitmq_binding.py
lib/ansible/modules/messaging/rabbitmq_exchange.py
lib/ansible/modules/messaging/rabbitmq_parameter.py
lib/ansible/modules/messaging/rabbitmq_plugin.py
lib/ansible/modules/messaging/rabbitmq_queue.py
lib/ansible/modules/messaging/rabbitmq_user.py
lib/ansible/modules/monitoring/airbrake_deployment.py lib/ansible/modules/monitoring/airbrake_deployment.py
lib/ansible/modules/monitoring/bigpanda.py lib/ansible/modules/monitoring/bigpanda.py
lib/ansible/modules/monitoring/boundary_meter.py lib/ansible/modules/monitoring/boundary_meter.py