def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_gtm_server.module_provisioned'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = True
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_gtm_server.tmos_version'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = '13.0.0'
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_utility_license_assignment.bigiq_version'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = '6.1.0'
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_utility_license_assignment.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = True
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_ssl_ocsp.tmos_version'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = '13.0.0'
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_ssl_ocsp.send_teem'
     )
     self.m3 = self.p3.start()
     self.m3.return_value = True
예제 #4
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_static_route.tmos_version'
     )
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_static_route.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = '14.1.0'
     self.m3 = self.p3.start()
     self.m3.return_value = True
    def setUp(self):
        self.spec = ArgumentSpec()

        self.p1 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_ha_group.tmos_version'
        )
        self.m1 = self.p1.start()
        self.m1.return_value = '13.1.0'
        self.p2 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_ha_group.send_teem'
        )
        self.m2 = self.p2.start()
        self.m2.return_value = True
예제 #6
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.patcher1 = patch('time.sleep')
     self.patcher1.start()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_regkey_pool.bigiq_version'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = '6.1.0'
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_regkey_pool.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = True
 def setUp(self):
     self.spec = ArgumentSpec()
     self.patcher1 = patch('time.sleep')
     self.patcher1.start()
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_httpd.tmos_version'
     )
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_httpd.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = '14.1.0'
     self.m3 = self.p3.start()
     self.m3.return_value = True
예제 #8
0
    def setUp(self):
        self.spec = ArgumentSpec()
        self.patcher1 = patch('time.sleep')
        self.patcher1.start()
        self.p1 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_application_fastl4_tcp.bigiq_version')
        self.p2 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_application_fastl4_tcp.ModuleParameters.template_reference')
        self.p3 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigiq_application_fastl4_tcp.ModuleParameters.default_device_reference')

        self.m1 = self.p1.start()
        self.m2 = self.p2.start()
        self.m3 = self.p3.start()

        self.m1.return_value = '6.1.0'
        self.m2.return_value = Mock(return_value='https://localhost/mgmt/foobar1')
        self.m3.return_value = Mock(return_value='https://localhost/mgmt/foobar3')
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_certificate.send_teem'
     )
     self.m3 = self.p3.start()
     self.m3.return_value = True
예제 #10
0
    def test_create_qkview_default_options(self, *args):
        set_module_args(
            dict(dest='/tmp/foo.qkview',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        # Override methods in the specific type of manager
        tm = MadmLocationManager(module=module, params=module.params)
        tm.exists = Mock(return_value=False)
        tm.execute_on_device = Mock(return_value=True)
        tm._move_qkview_to_download = Mock(return_value=True)
        tm._download_file = Mock(return_value=True)
        tm._delete_qkview = Mock(return_value=True)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.is_version_less_than_14 = Mock(return_value=True)
        mm.get_manager = Mock(return_value=tm)

        with patch('os.path.exists') as mo:
            mo.return_value = True
            results = mm.exec_module()

        assert results['changed'] is False
예제 #11
0
    def test_provision_all_modules(self, *args):
        modules = [
            'afm',
            'am',
            'sam',
            'asm',
            'avr',
            'fps',
            'gtm',
            'lc',
            'ltm',
            'pem',
            'swg',
            'ilx',
            'apm',
            'mgmt',
            'sslo',
            'urldb',
        ]

        for module in modules:
            # Configure the arguments that would be sent to the Ansible module
            set_module_args(
                dict(module=module,
                     provider=dict(server='localhost',
                                   password='******',
                                   user='******')))

            with patch('ansible.module_utils.basic.AnsibleModule.fail_json'
                       ) as mo:
                AnsibleModule(
                    argument_spec=self.spec.argument_spec,
                    supports_check_mode=self.spec.supports_check_mode,
                )
                mo.assert_not_called()
예제 #12
0
    def test_create(self, *args):
        set_module_args(
            dict(name='ssl_csr_1',
                 common_name='ssl_csr_1',
                 key_name='ssl_key_1',
                 dest='/tmp/ssl_csr_1',
                 force=True,
                 state='present',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        # Override methods in the specific type of manager
        mm = ModuleManager(module=module)
        mm.version_is_less_than_14 = Mock(return_value=False)
        mm.exists = Mock(return_value=False)
        mm.file_exists = Mock(return_value=False)
        mm.create_on_device = Mock(return_value=True)
        mm._move_csr_to_download = Mock(return_value=True)
        mm._delete_csr = Mock(return_value=True)
        mm._download_file = Mock(return_value=True)
        mm.remove_from_device = Mock(return_value=True)

        with patch('os.path.exists') as mo:
            mo.return_value = True
            results = mm.exec_module()

        assert results['changed'] is True
예제 #13
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_gtm_monitor_http.module_provisioned'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = True
예제 #14
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_asm_policy_server_technology.module_provisioned'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = True
    def setUp(self):
        self.spec = ArgumentSpec()

        self.p1 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_info.modules_provisioned'
        )
        self.m1 = self.p1.start()
        self.m1.return_value = ['ltm', 'gtm', 'asm']
예제 #16
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_fetch.module_provisioned'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = True
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_fetch.tmos_version'
     )
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_fetch.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = '14.1.0'
     self.m3 = self.p3.start()
     self.m3.return_value = True
예제 #17
0
    def setUp(self):
        self.spec = ArgumentSpec()

        self.p1 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_info.modules_provisioned'
        )
        self.m1 = self.p1.start()
        self.m1.return_value = ['ltm', 'gtm', 'asm']
        self.p2 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_info.tmos_version'
        )
        self.p3 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_info.send_teem'
        )
        self.m2 = self.p2.start()
        self.m2.return_value = '14.1.0'
        self.m3 = self.p3.start()
        self.m3.return_value = True
예제 #18
0
 def setUp(self):
     self.mock_module = patch.multiple(basic.AnsibleModule,
                                       exit_json=exit_json,
                                       fail_json=fail_json)
     self.mock_module.start()
     self.mock_sleep = patch('time.sleep')
     self.mock_sleep.start()
     set_module_args({})
     self.addCleanup(self.mock_module.stop)
     self.addCleanup(self.mock_sleep.stop)
 def setUp(self):
     self.spec = ArgumentSpec()
     self.policy = os.path.join(fixture_path, 'fake_policy.tar.gz')
     self.patcher1 = patch('time.sleep')
     self.patcher1.start()
     self.p1 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_import.module_provisioned'
     )
     self.m1 = self.p1.start()
     self.m1.return_value = True
     self.p2 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_import.tmos_version'
     )
     self.p3 = patch(
         'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_apm_policy_import.send_teem'
     )
     self.m2 = self.p2.start()
     self.m2.return_value = '14.1.0'
     self.m3 = self.p3.start()
     self.m3.return_value = True
예제 #20
0
    def test_create(self, *args):
        set_module_args(
            dict(backup='yes',
                 create_on_missing='yes',
                 dest='/tmp/foo.ucs',
                 force='yes',
                 fail_on_missing='no',
                 src='remote.ucs',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            add_file_common_args=self.spec.add_file_common_args)

        # Override methods to force specific logic in the module to happen
        m1 = V1Manager(module=module)
        m1.exists = Mock(return_value=False)
        m1.create_on_device = Mock(return_value=True)
        m1._get_backup_file = Mock(return_value='/tmp/foo.backup')
        m1.download_from_device = Mock(return_value=True)
        m1._set_checksum = Mock(return_value=12345)
        m1._set_md5sum = Mock(return_value=54321)

        mm = ModuleManager(module=module)
        mm.get_manager = Mock(return_value=m1)
        mm.is_version_v1 = Mock(return_value=True)

        p1 = patch('os.path.exists', return_value=True)
        p1.start()
        p2 = patch('os.path.isdir', return_value=False)
        p2.start()

        results = mm.exec_module()

        p1.stop()
        p2.stop()

        assert results['changed'] is True
예제 #21
0
 def test_invalid_unknown_params(self, *args):
     set_module_args(
         dict(name='test-route',
              state='present',
              foo="bar",
              provider=dict(server='localhost',
                            password='******',
                            user='******')))
     with patch('ansible.module_utils.basic.AnsibleModule.fail_json') as mo:
         mo.return_value = True
         AnsibleModule(argument_spec=self.spec.argument_spec,
                       mutually_exclusive=self.spec.mutually_exclusive,
                       supports_check_mode=self.spec.supports_check_mode)
         assert mo.call_count == 1
    def test_module_parameters_v12(self):
        args = dict(name='foobar',
                    description='baz',
                    active_bonus=20,
                    enable='yes',
                    state='present',
                    pools=[
                        dict(pool_name='fakepool',
                             attribute='percent-up-members',
                             weight=30,
                             minimum_threshold=2,
                             partition='Common')
                    ],
                    trunks=[
                        dict(trunk_name='faketrunk',
                             attribute='percent-up-members',
                             weight=20,
                             minimum_threshold=1)
                    ])

        self.p1 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_device_ha_group.tmos_version'
        )
        self.m1 = self.p1.start()
        self.m1.return_value = '12.1.0'

        p = ModuleParameters(params=args)

        assert p.name == 'foobar'
        assert p.state == 'present'
        assert p.active_bonus == 20
        assert p.enabled is True
        assert p.pools == [{
            'name': '/Common/fakepool',
            'attribute': 'percent-up-members',
            'weight': 30,
            'threshold': 2
        }]
        assert p.trunks == [{
            'name': 'faketrunk',
            'attribute': 'percent-up-members',
            'weight': 20,
            'threshold': 1
        }]

        self.p1.stop()
예제 #23
0
    def test_module_mutual_exclusion(self, *args):
        set_module_args(
            dict(content='foo',
                 module='ltm',
                 name='foo',
                 state='present',
                 src='/path/to/irules/foo.tcl',
                 partition='Common',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        with patch('ansible.module_utils.basic.AnsibleModule.fail_json',
                   unsafe=True) as mo:
            AnsibleModule(
                argument_spec=self.spec.argument_spec,
                supports_check_mode=self.spec.supports_check_mode,
                mutually_exclusive=self.spec.mutually_exclusive,
            )
            mo.assert_called_once()
예제 #24
0
    def test_create_gtm_irule_src(self, *args):
        set_module_args(
            dict(name='foo',
                 module='gtm',
                 src='{0}/create_ltm_irule.tcl'.format(fixture_path),
                 partition='Common',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
        )

        if PY3:
            builtins_name = 'builtins'
        else:
            builtins_name = '__builtin__'

        with patch(builtins_name + '.open',
                   mock_open(read_data='this is my content'),
                   create=True):
            # Override methods in the specific type of manager
            tm = GtmManager(module=module, params=module.params)
            tm.exists = Mock(side_effect=[False, True])
            tm.create_on_device = Mock(return_value=True)

            # Override methods to force specific logic in the module to happen
            mm = ModuleManager(module=module)
            mm.get_manager = Mock(return_value=tm)

            results = mm.exec_module()

        assert results['changed'] is True
        assert results['content'] == 'this is my content'
        assert results['module'] == 'gtm'
        assert results['src'] == '{0}/create_ltm_irule.tcl'.format(
            fixture_path)
        assert len(results.keys()) == 4
예제 #25
0
    def setUp(self):
        self.spec = ArgumentSpec()
        self.p1 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.modules_provisioned'
        )
        self.m1 = self.p1.start()
        self.m1.return_value = ['ltm', 'gtm', 'asm']
        self.p2 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.Parameters._read_current_clientssl_profiles_from_device'
        )
        self.p3 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.Parameters._read_current_serverssl_profiles_from_device'
        )
        self.p4 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.VirtualServerValidator.check_create'
        )
        self.p5 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.VirtualServerValidator.check_update'
        )
        self.m2 = self.p2.start()
        self.m3 = self.p3.start()
        self.m4 = self.p4.start()
        self.m5 = self.p5.start()
        self.m2.return_value = ['asda', 'clientssl', 'cs_foobar.star.local']
        self.m3.return_value = ['baz', 'serverssl', 'ss_foobar.star.local']
        self.m4.return_value = Mock(return_value=True)
        self.m5.return_value = Mock(return_value=True)

        self.p6 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.tmos_version'
        )
        self.p7 = patch(
            'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.send_teem'
        )
        self.m6 = self.p6.start()
        self.m6.return_value = '14.1.0'
        self.m7 = self.p7.start()
        self.m7.return_value = True
예제 #26
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigip_asm_advanced_settings.module_provisioned')
     self.m1 = self.p1.start()
     self.m1.return_value = True
예제 #27
0
 def setUp(self):
     self.spec = ArgumentSpec()
     self.patcher1 = patch('time.sleep')
     self.patcher1.start()
 def setUp(self):
     self.spec = ArgumentSpec()
     self.p1 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigip_firewall_port_list.module_provisioned')
     self.m1 = self.p1.start()
     self.m1.return_value = True