mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
deprecates the old package name bigip_iapplx_package (#53988)
Refactors main() function and module manager in multiple modules in line with recent changes Adds variable types to docs Refactors unit tests to remove deprecated parameters
This commit is contained in:
parent
309f7e59a3
commit
cd1ff016ef
3 changed files with 52 additions and 42 deletions
1
lib/ansible/modules/network/f5/_bigip_iapplx_package.py
Symbolic link
1
lib/ansible/modules/network/f5/_bigip_iapplx_package.py
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bigip_lx_package.py
|
|
@ -14,24 +14,26 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: bigip_iapplx_package
|
module: bigip_lx_package
|
||||||
short_description: Manages Javascript iApp packages on a BIG-IP
|
short_description: Manages Javascript LX packages on a BIG-IP
|
||||||
description:
|
description:
|
||||||
- Manages Javascript iApp packages on a BIG-IP. This module will allow
|
- Manages Javascript LX packages on a BIG-IP. This module will allow
|
||||||
you to deploy iAppLX packages to the BIG-IP and manage their lifecycle.
|
you to deploy LX packages to the BIG-IP and manage their lifecycle.
|
||||||
version_added: 2.5
|
version_added: 2.5
|
||||||
options:
|
options:
|
||||||
package:
|
package:
|
||||||
description:
|
description:
|
||||||
- The iAppLX package that you want to upload or remove. When C(state) is C(present),
|
- The LX package that you want to upload or remove. When C(state) is C(present),
|
||||||
and you intend to use this module in a C(role), it is recommended that you use
|
and you intend to use this module in a C(role), it is recommended that you use
|
||||||
the C({{ role_path }}) variable. An example is provided in the C(EXAMPLES) section.
|
the C({{ role_path }}) variable. An example is provided in the C(EXAMPLES) section.
|
||||||
- When C(state) is C(absent), it is not necessary for the package to exist on the
|
- When C(state) is C(absent), it is not necessary for the package to exist on the
|
||||||
Ansible controller. If the full path to the package is provided, the fileame will
|
Ansible controller. If the full path to the package is provided, the fileame will
|
||||||
specifically be cherry picked from it to properly remove the package.
|
specifically be cherry picked from it to properly remove the package.
|
||||||
|
type: path
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Whether the iAppLX package should exist or not.
|
- Whether the LX package should exist or not.
|
||||||
|
type: str
|
||||||
default: present
|
default: present
|
||||||
choices:
|
choices:
|
||||||
- present
|
- present
|
||||||
|
@ -43,6 +45,7 @@ notes:
|
||||||
This command is already present on RedHat based systems.
|
This command is already present on RedHat based systems.
|
||||||
- Requires BIG-IP >= 12.1.0 because the required functionality is missing
|
- Requires BIG-IP >= 12.1.0 because the required functionality is missing
|
||||||
on versions earlier than that.
|
on versions earlier than that.
|
||||||
|
- The module name C(bigip_iapplx_package) has been deprecated in favor of C(bigip_lx_package).
|
||||||
requirements:
|
requirements:
|
||||||
- Requires BIG-IP >= 12.1.0
|
- Requires BIG-IP >= 12.1.0
|
||||||
- The 'rpm' tool installed on the Ansible controller
|
- The 'rpm' tool installed on the Ansible controller
|
||||||
|
@ -54,7 +57,7 @@ author:
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Install AS3
|
- name: Install AS3
|
||||||
bigip_iapplx_package:
|
bigip_lx_package:
|
||||||
package: f5-appsvcs-3.5.0-3.noarch.rpm
|
package: f5-appsvcs-3.5.0-3.noarch.rpm
|
||||||
provider:
|
provider:
|
||||||
password: secret
|
password: secret
|
||||||
|
@ -62,8 +65,8 @@ EXAMPLES = r'''
|
||||||
user: admin
|
user: admin
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Add an iAppLX package stored in a role
|
- name: Add an LX package stored in a role
|
||||||
bigip_iapplx_package:
|
bigip_lx_package:
|
||||||
package: "{{ roles_path }}/files/MyApp-0.1.0-0001.noarch.rpm'"
|
package: "{{ roles_path }}/files/MyApp-0.1.0-0001.noarch.rpm'"
|
||||||
provider:
|
provider:
|
||||||
password: secret
|
password: secret
|
||||||
|
@ -71,8 +74,8 @@ EXAMPLES = r'''
|
||||||
user: admin
|
user: admin
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Remove an iAppLX package
|
- name: Remove an LX package
|
||||||
bigip_iapplx_package:
|
bigip_lx_package:
|
||||||
package: MyApp-0.1.0-0001.noarch.rpm
|
package: MyApp-0.1.0-0001.noarch.rpm
|
||||||
state: absent
|
state: absent
|
||||||
provider:
|
provider:
|
||||||
|
@ -97,20 +100,14 @@ try:
|
||||||
from library.module_utils.network.f5.bigip import F5RestClient
|
from library.module_utils.network.f5.bigip import F5RestClient
|
||||||
from library.module_utils.network.f5.common import F5ModuleError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
from library.module_utils.network.f5.common import AnsibleF5Parameters
|
from library.module_utils.network.f5.common import AnsibleF5Parameters
|
||||||
from library.module_utils.network.f5.common import cleanup_tokens
|
|
||||||
from library.module_utils.network.f5.common import f5_argument_spec
|
from library.module_utils.network.f5.common import f5_argument_spec
|
||||||
from library.module_utils.network.f5.common import exit_json
|
|
||||||
from library.module_utils.network.f5.common import fail_json
|
|
||||||
from library.module_utils.network.f5.icontrol import tmos_version
|
from library.module_utils.network.f5.icontrol import tmos_version
|
||||||
from library.module_utils.network.f5.icontrol import upload_file
|
from library.module_utils.network.f5.icontrol import upload_file
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ansible.module_utils.network.f5.bigip import F5RestClient
|
from ansible.module_utils.network.f5.bigip import F5RestClient
|
||||||
from ansible.module_utils.network.f5.common import F5ModuleError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
|
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
|
||||||
from ansible.module_utils.network.f5.common import cleanup_tokens
|
|
||||||
from ansible.module_utils.network.f5.common import f5_argument_spec
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
||||||
from ansible.module_utils.network.f5.common import exit_json
|
|
||||||
from ansible.module_utils.network.f5.common import fail_json
|
|
||||||
from ansible.module_utils.network.f5.icontrol import tmos_version
|
from ansible.module_utils.network.f5.icontrol import tmos_version
|
||||||
from ansible.module_utils.network.f5.icontrol import upload_file
|
from ansible.module_utils.network.f5.icontrol import upload_file
|
||||||
|
|
||||||
|
@ -193,7 +190,7 @@ class ReportableChanges(Changes):
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.module = kwargs.get('module', None)
|
self.module = kwargs.get('module', None)
|
||||||
self.client = kwargs.get('client', None)
|
self.client = F5RestClient(**self.module.params)
|
||||||
self.want = ModuleParameters(module=self.module, params=self.module.params)
|
self.want = ModuleParameters(module=self.module, params=self.module.params)
|
||||||
self.changes = UsableChanges()
|
self.changes = UsableChanges()
|
||||||
|
|
||||||
|
@ -235,7 +232,7 @@ class ModuleManager(object):
|
||||||
return True
|
return True
|
||||||
self.remove_from_device()
|
self.remove_from_device()
|
||||||
if self.exists():
|
if self.exists():
|
||||||
raise F5ModuleError("Failed to delete the iAppLX package")
|
raise F5ModuleError("Failed to delete the LX package.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
@ -244,11 +241,11 @@ class ModuleManager(object):
|
||||||
if not os.path.exists(self.want.package):
|
if not os.path.exists(self.want.package):
|
||||||
if self.want.package.startswith('/'):
|
if self.want.package.startswith('/'):
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"The specified iAppLX package was not found at {0}.".format(self.want.package)
|
"The specified LX package was not found at {0}.".format(self.want.package)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"The specified iAppLX package was not found in {0}.".format(os.getcwd())
|
"The specified LX package was not found in {0}.".format(os.getcwd())
|
||||||
)
|
)
|
||||||
self.upload_to_device()
|
self.upload_to_device()
|
||||||
self.create_on_device()
|
self.create_on_device()
|
||||||
|
@ -257,7 +254,7 @@ class ModuleManager(object):
|
||||||
if self.exists():
|
if self.exists():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise F5ModuleError("Failed to create the iApp template")
|
raise F5ModuleError("Failed to install LX package.")
|
||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
exists = False
|
exists = False
|
||||||
|
@ -298,7 +295,7 @@ class ModuleManager(object):
|
||||||
if task['status'] == 'FINISHED':
|
if task['status'] == 'FINISHED':
|
||||||
return task['queryResponse']
|
return task['queryResponse']
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"Failed to find the installed packages on the device"
|
"Failed to find the installed packages on the device."
|
||||||
)
|
)
|
||||||
|
|
||||||
def _wait_for_task(self, path):
|
def _wait_for_task(self, path):
|
||||||
|
@ -452,7 +449,7 @@ class ArgumentSpec(object):
|
||||||
default='present',
|
default='present',
|
||||||
choices=['present', 'absent']
|
choices=['present', 'absent']
|
||||||
),
|
),
|
||||||
package=dict()
|
package=dict(type='path')
|
||||||
)
|
)
|
||||||
self.argument_spec = {}
|
self.argument_spec = {}
|
||||||
self.argument_spec.update(f5_argument_spec)
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
@ -471,16 +468,12 @@ def main():
|
||||||
required_if=spec.required_if
|
required_if=spec.required_if
|
||||||
)
|
)
|
||||||
|
|
||||||
client = F5RestClient(**module.params)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(module=module, client=client)
|
mm = ModuleManager(module=module)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
module.exit_json(**results)
|
||||||
exit_json(module, results, client)
|
|
||||||
except F5ModuleError as ex:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
module.fail_json(msg=str(ex))
|
||||||
fail_json(module, ex, client)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
|
@ -17,9 +17,9 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.modules.bigip_iapp_template import Parameters
|
from library.modules.bigip_lx_package import Parameters
|
||||||
from library.modules.bigip_iapp_template import ModuleManager
|
from library.modules.bigip_lx_package import ModuleManager
|
||||||
from library.modules.bigip_iapp_template import ArgumentSpec
|
from library.modules.bigip_lx_package import ArgumentSpec
|
||||||
|
|
||||||
# In Ansible 2.8, Ansible changed import paths.
|
# In Ansible 2.8, Ansible changed import paths.
|
||||||
from test.units.compat import unittest
|
from test.units.compat import unittest
|
||||||
|
@ -28,9 +28,9 @@ try:
|
||||||
|
|
||||||
from test.units.modules.utils import set_module_args
|
from test.units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ansible.modules.network.f5.bigip_iapp_template import Parameters
|
from ansible.modules.network.f5.bigip_lx_package import Parameters
|
||||||
from ansible.modules.network.f5.bigip_iapp_template import ArgumentSpec
|
from ansible.modules.network.f5.bigip_lx_package import ArgumentSpec
|
||||||
from ansible.modules.network.f5.bigip_iapp_template import ModuleManager
|
from ansible.modules.network.f5.bigip_lx_package import ModuleManager
|
||||||
|
|
||||||
# Ansible 2.8 imports
|
# Ansible 2.8 imports
|
||||||
from units.compat import unittest
|
from units.compat import unittest
|
||||||
|
@ -79,28 +79,44 @@ class TestManager(unittest.TestCase):
|
||||||
self.patcher1 = patch('time.sleep')
|
self.patcher1 = patch('time.sleep')
|
||||||
self.patcher1.start()
|
self.patcher1.start()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.p1 = patch('library.modules.bigip_lx_package.tmos_version')
|
||||||
|
self.m1 = self.p1.start()
|
||||||
|
self.m1.return_value = '12.1.3'
|
||||||
|
except Exception:
|
||||||
|
self.p1 = patch('ansible.modules.network.f5.bigip_lx_package.tmos_version')
|
||||||
|
self.m1 = self.p1.start()
|
||||||
|
self.m1.return_value = '12.1.3'
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.patcher1.stop()
|
self.patcher1.stop()
|
||||||
|
|
||||||
def test_create_iapp_template(self, *args):
|
def test_create_iapp_template(self, *args):
|
||||||
|
package_name = os.path.join(fixture_path, 'MyApp-0.1.0-0001.noarch.rpm')
|
||||||
# Configure the arguments that would be sent to the Ansible module
|
# Configure the arguments that would be sent to the Ansible module
|
||||||
set_module_args(dict(
|
set_module_args(dict(
|
||||||
content='fixtures/MyApp-0.1.0-0001.noarch.rpm',
|
package=package_name,
|
||||||
state='present',
|
state='present',
|
||||||
password='password',
|
provider=dict(
|
||||||
server='localhost',
|
server='localhost',
|
||||||
|
password='password',
|
||||||
user='admin'
|
user='admin'
|
||||||
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode
|
supports_check_mode=self.spec.supports_check_mode,
|
||||||
|
required_if=self.spec.required_if
|
||||||
)
|
)
|
||||||
mm = ModuleManager(module=module)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.exists = Mock(side_effect=[False, True])
|
mm.exists = Mock(side_effect=[False, True])
|
||||||
mm.create_on_device = Mock(return_value=True)
|
mm.create_on_device = Mock(return_value=True)
|
||||||
|
mm.upload_to_device = Mock(return_value=True)
|
||||||
|
mm.enable_iapplx_on_device = Mock(return_value=True)
|
||||||
|
mm.remove_package_file_from_device = Mock(return_value=True)
|
||||||
|
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
|
Loading…
Reference in a new issue