mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
f04139bfa3
commit
38806e8507
2 changed files with 33 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -14,9 +14,6 @@ from nose.plugins.skip import SkipTest
|
|||
if sys.version_info < (2, 7):
|
||||
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
||||
|
||||
from units.compat import unittest
|
||||
from units.compat.mock import Mock
|
||||
from units.compat.mock import patch
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
try:
|
||||
|
@ -25,9 +22,13 @@ try:
|
|||
from library.modules.bigip_qkview import MadmLocationManager
|
||||
from library.modules.bigip_qkview import BulkLocationManager
|
||||
from library.modules.bigip_qkview import ArgumentSpec
|
||||
from library.module_utils.network.f5.common import F5ModuleError
|
||||
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||
from test.unit.modules.utils import set_module_args
|
||||
|
||||
# In Ansible 2.8, Ansible changed import paths.
|
||||
from test.units.compat import unittest
|
||||
from test.units.compat.mock import Mock
|
||||
from test.units.compat.mock import patch
|
||||
|
||||
from test.units.modules.utils import set_module_args
|
||||
except ImportError:
|
||||
try:
|
||||
from ansible.modules.network.f5.bigip_qkview import Parameters
|
||||
|
@ -35,8 +36,12 @@ except ImportError:
|
|||
from ansible.modules.network.f5.bigip_qkview import MadmLocationManager
|
||||
from ansible.modules.network.f5.bigip_qkview import BulkLocationManager
|
||||
from ansible.modules.network.f5.bigip_qkview import ArgumentSpec
|
||||
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||
|
||||
# Ansible 2.8 imports
|
||||
from units.compat import unittest
|
||||
from units.compat.mock import Mock
|
||||
from units.compat.mock import patch
|
||||
|
||||
from units.modules.utils import set_module_args
|
||||
except ImportError:
|
||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||
|
|
Loading…
Reference in a new issue