From cd1ff016efa7a27de7f825e64d14f87140290a51 Mon Sep 17 00:00:00 2001 From: Wojciech Wypior Date: Tue, 19 Mar 2019 15:57:57 +0100 Subject: [PATCH] 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 --- .../network/f5/_bigip_iapplx_package.py | 1 + ..._iapplx_package.py => bigip_lx_package.py} | 55 ++++++++----------- ...lx_package.py => test_bigip_lx_package.py} | 38 +++++++++---- 3 files changed, 52 insertions(+), 42 deletions(-) create mode 120000 lib/ansible/modules/network/f5/_bigip_iapplx_package.py rename lib/ansible/modules/network/f5/{bigip_iapplx_package.py => bigip_lx_package.py} (89%) rename test/units/modules/network/f5/{test_bigip_iapplx_package.py => test_bigip_lx_package.py} (64%) diff --git a/lib/ansible/modules/network/f5/_bigip_iapplx_package.py b/lib/ansible/modules/network/f5/_bigip_iapplx_package.py new file mode 120000 index 0000000000..45a77871e2 --- /dev/null +++ b/lib/ansible/modules/network/f5/_bigip_iapplx_package.py @@ -0,0 +1 @@ +bigip_lx_package.py \ No newline at end of file diff --git a/lib/ansible/modules/network/f5/bigip_iapplx_package.py b/lib/ansible/modules/network/f5/bigip_lx_package.py similarity index 89% rename from lib/ansible/modules/network/f5/bigip_iapplx_package.py rename to lib/ansible/modules/network/f5/bigip_lx_package.py index e9269cb944..a64cc53070 100644 --- a/lib/ansible/modules/network/f5/bigip_iapplx_package.py +++ b/lib/ansible/modules/network/f5/bigip_lx_package.py @@ -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__': diff --git a/test/units/modules/network/f5/test_bigip_iapplx_package.py b/test/units/modules/network/f5/test_bigip_lx_package.py similarity index 64% rename from test/units/modules/network/f5/test_bigip_iapplx_package.py rename to test/units/modules/network/f5/test_bigip_lx_package.py index c05a0b7ef1..d98c8014bb 100644 --- a/test/units/modules/network/f5/test_bigip_iapplx_package.py +++ b/test/units/modules/network/f5/test_bigip_lx_package.py @@ -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', - server='localhost', - user='admin' + 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()