def test_factory_should_return_corresponding_platform(self): ftd_platform = FtdPlatformFactory.create(FtdModel.FTD_ASA5508_X, dict(DEFAULT_MODULE_PARAMS)) assert type(ftd_platform) is FtdAsa5500xPlatform ftd_platform = FtdPlatformFactory.create(FtdModel.FTD_2130, dict(DEFAULT_MODULE_PARAMS)) assert type(ftd_platform) is Ftd2100Platform
def main(): fields = dict(device_hostname=dict(type='str', required=True), device_username=dict(type='str', required=False, default='admin'), device_password=dict(type='str', required=True, no_log=True), device_sudo_password=dict(type='str', required=False, no_log=True), device_new_password=dict(type='str', required=False, no_log=True), device_ip=dict(type='str', required=False), device_netmask=dict(type='str', required=False), device_gateway=dict(type='str', required=False), device_model=dict(type='str', required=False, choices=FtdModel.supported_models()), dns_server=dict(type='str', required=False), search_domains=dict(type='str', required=False, default='cisco.com'), console_ip=dict(type='str', required=True), console_port=dict(type='str', required=True), console_username=dict(type='str', required=True), console_password=dict(type='str', required=True, no_log=True), rommon_file_location=dict(type='str', required=True), image_file_location=dict(type='str', required=True), image_version=dict(type='str', required=True), force_install=dict(type='bool', required=False, default=False)) module = AnsibleModule(argument_spec=fields) assert_kick_is_installed(module) use_local_connection = module._socket_path is None if use_local_connection: check_required_params_for_local_connection(module, module.params) platform_model = module.params['device_model'] check_that_model_is_supported(module, platform_model) else: connection = Connection(module._socket_path) resource = BaseConfigurationResource(connection, module.check_mode) system_info = get_system_info(resource) platform_model = module.params['device_model'] or system_info[ 'platformModel'] check_that_model_is_supported(module, platform_model) check_that_update_is_needed(module, system_info) check_management_and_dns_params(resource, module.params) ftd_platform = FtdPlatformFactory.create(platform_model, module.params) ftd_platform.install_ftd_image(module.params) module.exit_json( changed=True, msg='Successfully installed FTD image %s on the firewall device.' % module.params["image_version"])
def test_install_ftd_image_should_call_kp_module(self, asa5500x_mock, module_params): ftd = FtdPlatformFactory.create(FtdModel.FTD_ASA5508_X, module_params) ftd.install_ftd_image(module_params) assert asa5500x_mock.called assert asa5500x_mock.return_value.ssh_console.called ftd_line = asa5500x_mock.return_value.ssh_console.return_value assert ftd_line.rommon_to_new_image.called assert ftd_line.disconnect.called
def test_install_ftd_image_should_call_kp_module(self, kp_mock, module_params): ftd = FtdPlatformFactory.create(FtdModel.FTD_2110, module_params) ftd.install_ftd_image(module_params) assert kp_mock.called assert kp_mock.return_value.ssh_console.called ftd_line = kp_mock.return_value.ssh_console.return_value assert ftd_line.baseline_fp2k_ftd.called assert ftd_line.disconnect.called
def test_install_ftd_image_should_call_disconnect_when_install_fails( self, asa5500x_mock, module_params): ftd_line = asa5500x_mock.return_value.ssh_console.return_value ftd_line.rommon_to_new_image.side_effect = Exception( 'Something went wrong') ftd = FtdPlatformFactory.create(FtdModel.FTD_ASA5516_X, module_params) with pytest.raises(Exception): ftd.install_ftd_image(module_params) assert ftd_line.rommon_to_new_image.called assert ftd_line.disconnect.called
def test_install_ftd_image_should_call_disconnect_when_install_fails( self, kp_mock, module_params): ftd_line = kp_mock.return_value.ssh_console.return_value ftd_line.baseline_fp2k_ftd.side_effect = Exception( 'Something went wrong') ftd = FtdPlatformFactory.create(FtdModel.FTD_2120, module_params) with pytest.raises(Exception): ftd.install_ftd_image(module_params) assert ftd_line.baseline_fp2k_ftd.called assert ftd_line.disconnect.called
def test_factory_should_raise_error_with_not_supported_model(self): with pytest.raises(ValueError) as ex: FtdPlatformFactory.create('nonExistingModel', dict(DEFAULT_MODULE_PARAMS)) assert "FTD model 'nonExistingModel' is not supported by this module." == ex.value.args[ 0]