def test_modify_vlans_idempotent(self, *args): set_module_args( dict(name="my-virtual-server", partition="Common", password="******", disabled_vlans=["net1"], server="localhost", state="present", user="******", validate_certs="no")) # Configure the parameters that would be returned by querying the # remote device current = VirtualServerApiParameters( load_fixture('load_ltm_virtual_2.json')) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) # Override methods to force specific logic in the module to happen vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=True) vsm.read_current_from_device = Mock(return_value=current) mm = ModuleManager(client) mm.get_manager = Mock(return_value=vsm) results = mm.exec_module() assert results['changed'] is False
def test_delete_virtual_server(self, *args): set_module_args( dict(all_profiles=['http', 'clientssl'], description="Test Virtual Server", destination="10.10.10.10", name="my-snat-pool", partition="Common", password="******", port="443", server="localhost", snat="Automap", state="absent", user="******", validate_certs="no")) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) # Override methods to force specific logic in the module to happen vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=False) mm = ModuleManager(client) mm.get_manager = Mock(return_value=vsm) results = mm.exec_module() assert results['changed'] is False
def test_enable_vs_that_is_already_enabled(self, *args): set_module_args( dict(all_profiles=['http', 'clientssl'], description="Test Virtual Server", destination="10.10.10.10", name="my-snat-pool", partition="Common", password="******", port="443", server="localhost", snat="Automap", state="absent", user="******", validate_certs="no")) # Configure the parameters that would be returned by querying the # remote device current = VirtualServerParameters(dict(agent_status_traps='disabled')) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) # Override methods to force specific logic in the module to happen vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=False) vsm.update_on_device = Mock(return_value=True) vsm.read_current_from_device = Mock(return_value=current) mm = ModuleManager(client) mm.get_manager = Mock(return_value=vsm) results = mm.exec_module() assert results['changed'] is False
def test_modify_profiles(self, *args): set_module_args( dict(name="my-virtual-server", partition="Common", password="******", profiles=['http', 'clientssl'], server="localhost", state="present", user="******", validate_certs="no")) # Configure the parameters that would be returned by querying the # remote device current = VirtualServerApiParameters( load_fixture('load_ltm_virtual_2.json')) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) # Override methods to force specific logic in the module to happen vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=True) vsm.read_current_from_device = Mock(return_value=current) vsm.update_on_device = Mock(return_value=True) mm = ModuleManager(client) mm.get_manager = Mock(return_value=vsm) results = mm.exec_module() assert results['changed'] is True assert len(results['profiles']) == 2 assert 'name' in results['profiles'][0] assert 'context' in results['profiles'][0] assert results['profiles'][0]['name'] == 'http' assert results['profiles'][0]['context'] == 'all' assert 'name' in results['profiles'][1] assert 'context' in results['profiles'][1] assert results['profiles'][1]['name'] == 'clientssl' assert results['profiles'][1]['context'] == 'clientside'
def test_modify_port_idempotent(self, *args): set_module_args( dict(destination="10.10.10.10", name="my-virtual-server", route_advertisement_state="enabled", partition="Common", password="******", port="443", server="localhost", state="present", user="******", validate_certs="no")) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) vsm_current = VirtualServerApiParameters( load_fixture('load_ltm_virtual_1.json')) vam_current = VirtualAddressParameters( load_fixture('load_ltm_virtual_1_address.json')) vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=True) vsm.read_current_from_device = Mock(return_value=vsm_current) vam = VirtualAddressManager(client) vam.exists = Mock(return_value=True) vam.read_current_from_device = Mock(return_value=vam_current) mm = ModuleManager(client) mm.get_manager = Mock(side_effect=[vsm, vam]) results = mm.exec_module() assert results['changed'] is False
def test_update_virtual_server(self, *args): set_module_args( dict(profiles=[dict(name='http'), dict(name='clientssl')], description="foo virtual", destination="1.1.1.1", name="my-virtual-server", partition="Common", password="******", port="8443", server="localhost", snat="snat-pool1", state="disabled", source='1.2.3.4/32', user="******", validate_certs="no", irules=['irule1', 'irule2'], policies=['policy1', 'policy2'], enabled_vlans=['vlan1', 'vlan2'], pool='my-pool', default_persistence_profile='source_addr', fallback_persistence_profile='dest_addr')) # Configure the parameters that would be returned by querying the # remote device current = VirtualServerApiParameters( load_fixture('load_ltm_virtual_3.json')) client = AnsibleF5Client( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, f5_product_name=self.spec.f5_product_name) # Override methods to force specific logic in the module to happen vsm = VirtualServerManager(client) vsm.exists = Mock(return_value=True) vsm.read_current_from_device = Mock(return_value=current) vsm.update_on_device = Mock(return_value=True) mm = ModuleManager(client) mm.get_manager = Mock(return_value=vsm) results = mm.exec_module() assert results['changed'] is True assert results['source'] == '1.2.3.4/32' assert results['description'] == 'foo virtual' assert results['snat'] == '/Common/snat-pool1' assert results['destination'] == '1.1.1.1' assert results['port'] == 8443 assert results['default_persistence_profile'] == '/Common/source_addr' assert results['fallback_persistence_profile'] == '/Common/dest_addr' # policies assert len(results['policies']) == 2 assert '/Common/policy1' in results['policies'] assert '/Common/policy2' in results['policies'] # irules assert len(results['irules']) == 2 assert '/Common/irule1' in results['irules'] assert '/Common/irule2' in results['irules'] # vlans assert len(results['enabled_vlans']) == 2 assert '/Common/vlan1' in results['enabled_vlans'] assert '/Common/vlan2' in results['enabled_vlans'] # profiles assert len(results['profiles']) == 2 assert 'name' in results['profiles'][0] assert 'context' in results['profiles'][0] assert results['profiles'][0]['name'] == 'http' assert results['profiles'][0]['context'] == 'all' assert 'name' in results['profiles'][1] assert 'context' in results['profiles'][1] assert results['profiles'][1]['name'] == 'clientssl' assert results['profiles'][1]['context'] == 'clientside'