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
pull/54452/head
Wojciech Wypior 6 years ago committed by John R Barker
parent 309f7e59a3
commit cd1ff016ef

@ -14,24 +14,26 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: bigip_iapplx_package
short_description: Manages Javascript iApp packages on a BIG-IP
module: bigip_lx_package
short_description: Manages Javascript LX packages on a BIG-IP
description:
- Manages Javascript iApp packages on a BIG-IP. This module will allow
you to deploy iAppLX packages to the BIG-IP and manage their lifecycle.
- Manages Javascript LX packages on a BIG-IP. This module will allow
you to deploy LX packages to the BIG-IP and manage their lifecycle.
version_added: 2.5
options:
package:
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
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
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.
type: path
state:
description:
- Whether the iAppLX package should exist or not.
- Whether the LX package should exist or not.
type: str
default: present
choices:
- present
@ -43,6 +45,7 @@ notes:
This command is already present on RedHat based systems.
- Requires BIG-IP >= 12.1.0 because the required functionality is missing
on versions earlier than that.
- The module name C(bigip_iapplx_package) has been deprecated in favor of C(bigip_lx_package).
requirements:
- Requires BIG-IP >= 12.1.0
- The 'rpm' tool installed on the Ansible controller
@ -54,7 +57,7 @@ author:
EXAMPLES = r'''
- name: Install AS3
bigip_iapplx_package:
bigip_lx_package:
package: f5-appsvcs-3.5.0-3.noarch.rpm
provider:
password: secret
@ -62,8 +65,8 @@ EXAMPLES = r'''
user: admin
delegate_to: localhost
- name: Add an iAppLX package stored in a role
bigip_iapplx_package:
- name: Add an LX package stored in a role
bigip_lx_package:
package: "{{ roles_path }}/files/MyApp-0.1.0-0001.noarch.rpm'"
provider:
password: secret
@ -71,8 +74,8 @@ EXAMPLES = r'''
user: admin
delegate_to: localhost
- name: Remove an iAppLX package
bigip_iapplx_package:
- name: Remove an LX package
bigip_lx_package:
package: MyApp-0.1.0-0001.noarch.rpm
state: absent
provider:
@ -97,20 +100,14 @@ try:
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 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 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 upload_file
except ImportError:
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 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 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 upload_file
@ -193,7 +190,7 @@ class ReportableChanges(Changes):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
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.changes = UsableChanges()
@ -235,7 +232,7 @@ class ModuleManager(object):
return True
self.remove_from_device()
if self.exists():
raise F5ModuleError("Failed to delete the iAppLX package")
raise F5ModuleError("Failed to delete the LX package.")
return True
def create(self):
@ -244,11 +241,11 @@ class ModuleManager(object):
if not os.path.exists(self.want.package):
if self.want.package.startswith('/'):
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:
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.create_on_device()
@ -257,7 +254,7 @@ class ModuleManager(object):
if self.exists():
return True
else:
raise F5ModuleError("Failed to create the iApp template")
raise F5ModuleError("Failed to install LX package.")
def exists(self):
exists = False
@ -298,7 +295,7 @@ class ModuleManager(object):
if task['status'] == 'FINISHED':
return task['queryResponse']
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):
@ -452,7 +449,7 @@ class ArgumentSpec(object):
default='present',
choices=['present', 'absent']
),
package=dict()
package=dict(type='path')
)
self.argument_spec = {}
self.argument_spec.update(f5_argument_spec)
@ -471,16 +468,12 @@ def main():
required_if=spec.required_if
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

@ -17,9 +17,9 @@ if sys.version_info < (2, 7):
from ansible.module_utils.basic import AnsibleModule
try:
from library.modules.bigip_iapp_template import Parameters
from library.modules.bigip_iapp_template import ModuleManager
from library.modules.bigip_iapp_template import ArgumentSpec
from library.modules.bigip_lx_package import Parameters
from library.modules.bigip_lx_package import ModuleManager
from library.modules.bigip_lx_package import ArgumentSpec
# In Ansible 2.8, Ansible changed import paths.
from test.units.compat import unittest
@ -28,9 +28,9 @@ try:
from test.units.modules.utils import set_module_args
except ImportError:
from ansible.modules.network.f5.bigip_iapp_template import Parameters
from ansible.modules.network.f5.bigip_iapp_template import ArgumentSpec
from ansible.modules.network.f5.bigip_iapp_template import ModuleManager
from ansible.modules.network.f5.bigip_lx_package import Parameters
from ansible.modules.network.f5.bigip_lx_package import ArgumentSpec
from ansible.modules.network.f5.bigip_lx_package import ModuleManager
# Ansible 2.8 imports
from units.compat import unittest
@ -79,28 +79,44 @@ class TestManager(unittest.TestCase):
self.patcher1 = patch('time.sleep')
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):
self.patcher1.stop()
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
set_module_args(dict(
content='fixtures/MyApp-0.1.0-0001.noarch.rpm',
package=package_name,
state='present',
password='password',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
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)
# Override methods to force specific logic in the module to happen
mm.exists = Mock(side_effect=[False, 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()
Loading…
Cancel
Save