Fixes for bigip_qkview (#48396)

Fixes unit tests for ansible 2.8 and adds more error handling
for qkview generation
This commit is contained in:
Tim Rupp 2018-11-08 21:08:27 -08:00 committed by GitHub
commit 38806e8507
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 13 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# Copyright: (c) 2017, F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@ -82,6 +82,10 @@ EXAMPLES = r'''
- audit
- secure
dest: /tmp/localhost.localdomain.qkview
provider:
password: secret
server: lb.mydomain.com
user: admin
delegate_to: localhost
'''
@ -92,6 +96,7 @@ RETURN = r'''
import os
import re
import socket
import ssl
import time
from ansible.module_utils.basic import AnsibleModule
@ -272,7 +277,11 @@ class BaseManager(object):
def present(self):
if os.path.exists(self.want.dest) and not self.want.force:
raise F5ModuleError(
"The specified 'dest' file already exists"
"The specified 'dest' file already exists."
)
if not os.path.exists(os.path.dirname(self.want.dest)):
raise F5ModuleError(
"The directory of your 'dest' file does not exist."
)
if self.want.exclude:
choices = ['all', 'audit', 'secure', 'bash_history']
@ -455,9 +464,14 @@ class BaseManager(object):
while True:
try:
resp = self.client.api.get(uri, timeout=10)
except socket.timeout:
except (socket.timeout, ssl.SSLError):
continue
try:
response = resp.json()
except ValueError:
# It is possible that the API call can return invalid JSON.
# This invalid JSON appears to be just empty strings.
continue
response = resp.json()
if response['_taskState'] == 'FAILED':
raise F5ModuleError(
"qkview creation task failed unexpectedly."
@ -577,8 +591,9 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
cleanup_tokens(client)