def test_create_internal_incorrect_integer_data(self, *args): set_module_args(dict( name='foo', delete_data_group_file=False, internal=True, type='integer', records_src="{0}/data-group-string.txt".format(fixture_path), separator=':=', state='present', partition='Common', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) with pytest.raises(F5ModuleError) as ex: mm0.exec_module() assert "When specifying an 'integer' type, the value to the left of the separator must be a number." == str(ex.value)
def test_create_internal_incorrect_integer_data(self, *args): set_module_args( dict(name='foo', delete_data_group_file=False, internal=True, type='integer', records_src="{0}/data-group-string.txt".format(fixture_path), separator=':=', state='present', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) with pytest.raises(F5ModuleError) as ex: mm0.exec_module() assert "When specifying an 'integer' type, the value to the left of the separator must be a number." == str( ex.value)
def test_create_internal_datagroup_type_address(self, *args): set_module_args(dict( name='foo', delete_data_group_file=False, internal=True, type='address', records_src="{0}/data-group-address.txt".format(fixture_path), separator=':=', state='present', partition='Common', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True
def test_remove_data_group_remove_file(self, *args): set_module_args(dict( name='foo', delete_data_group_file=True, internal=False, state='absent', partition='Common', 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, ) # Override methods in the specific type of manager mm1 = ExternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[True, False]) mm1.remove_from_device = Mock(return_value=True) mm1.external_file_exists = Mock(return_value=True) mm1.remove_data_group_file_from_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True
def test_create_internal_datagroup_type_address(self, *args): set_module_args(dict( name='foo', delete_data_group_file=False, internal=True, type='address', records_src="{0}/data-group-address.txt".format(fixture_path), separator=':=', state='present', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True
def test_remove_data_group_remove_file(self, *args): set_module_args(dict( name='foo', delete_data_group_file=True, internal=False, state='absent', 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, ) # Override methods in the specific type of manager mm1 = ExternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[True, False]) mm1.remove_from_device = Mock(return_value=True) mm1.external_file_exists = Mock(return_value=True) mm1.remove_data_group_file_from_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True
def test_create_internal_datagroup_type_address_list(self, *args): set_module_args(dict( name='foo', delete_data_group_file=False, internal=True, type='address', records=[ dict( key='10.0.0.0/8', value='Network1' ), dict( key='172.16.0.0/12', value='Network2' ), dict( key='192.168.20.1/16', value='Network3' ), dict( key='192.168.20.1', value='Host1' ), dict( key='172.16.1.1', value='Host2' ) ], separator=':=', state='present', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True
def test_create_internal_datagroup_type_address_list(self, *args): set_module_args(dict( name='foo', delete_data_group_file=False, internal=True, type='address', records=[ dict( key='10.0.0.0/8', value='Network1' ), dict( key='172.16.0.0/12', value='Network2' ), dict( key='192.168.20.1/16', value='Network3' ), dict( key='192.168.20.1', value='Host1' ), dict( key='172.16.1.1', value='Host2' ) ], separator=':=', state='present', partition='Common', 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, ) # Override methods in the specific type of manager mm1 = InternalManager(module=module, params=module.params) mm1.exists = Mock(side_effect=[False, True]) mm1.create_on_device = Mock(return_value=True) # Override methods to force specific logic in the module to happen mm0 = ModuleManager(module=module) mm0.get_manager = Mock(return_value=mm1) results = mm0.exec_module() assert results['changed'] is True