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
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
|
@ -82,6 +82,10 @@ EXAMPLES = r'''
|
||||||
- audit
|
- audit
|
||||||
- secure
|
- secure
|
||||||
dest: /tmp/localhost.localdomain.qkview
|
dest: /tmp/localhost.localdomain.qkview
|
||||||
|
provider:
|
||||||
|
password: secret
|
||||||
|
server: lb.mydomain.com
|
||||||
|
user: admin
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -92,6 +96,7 @@ RETURN = r'''
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import ssl
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -272,7 +277,11 @@ class BaseManager(object):
|
||||||
def present(self):
|
def present(self):
|
||||||
if os.path.exists(self.want.dest) and not self.want.force:
|
if os.path.exists(self.want.dest) and not self.want.force:
|
||||||
raise F5ModuleError(
|
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:
|
if self.want.exclude:
|
||||||
choices = ['all', 'audit', 'secure', 'bash_history']
|
choices = ['all', 'audit', 'secure', 'bash_history']
|
||||||
|
@ -455,9 +464,14 @@ class BaseManager(object):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
resp = self.client.api.get(uri, timeout=10)
|
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
|
continue
|
||||||
response = resp.json()
|
|
||||||
if response['_taskState'] == 'FAILED':
|
if response['_taskState'] == 'FAILED':
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"qkview creation task failed unexpectedly."
|
"qkview creation task failed unexpectedly."
|
||||||
|
@ -577,8 +591,9 @@ def main():
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
client = F5RestClient(**module.params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client = F5RestClient(**module.params)
|
|
||||||
mm = ModuleManager(module=module, client=client)
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
|
|
|
@ -14,9 +14,6 @@ from nose.plugins.skip import SkipTest
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
raise SkipTest("F5 Ansible modules require Python >= 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
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -25,9 +22,13 @@ try:
|
||||||
from library.modules.bigip_qkview import MadmLocationManager
|
from library.modules.bigip_qkview import MadmLocationManager
|
||||||
from library.modules.bigip_qkview import BulkLocationManager
|
from library.modules.bigip_qkview import BulkLocationManager
|
||||||
from library.modules.bigip_qkview import ArgumentSpec
|
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
|
# In Ansible 2.8, Ansible changed import paths.
|
||||||
from test.unit.modules.utils import set_module_args
|
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:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_qkview import Parameters
|
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 MadmLocationManager
|
||||||
from ansible.modules.network.f5.bigip_qkview import BulkLocationManager
|
from ansible.modules.network.f5.bigip_qkview import BulkLocationManager
|
||||||
from ansible.modules.network.f5.bigip_qkview import ArgumentSpec
|
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
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
|
Loading…
Reference in a new issue