From df9a73237caf5f84859c80562fdda53fa3ede036 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 12 Feb 2024 11:52:23 +0100 Subject: [PATCH] Wait for TFTP downloads The /fetch_boot_file API is used to download TFTP files. The HttpDownload task is implemented as a thread. Previously it was fired off and there was no way to see the result. This implements code that waits for some time before telling the client the task is still running. There is no way for the client to find out if it really did finish. --- modules/tftp/server.rb | 9 +++++---- modules/tftp/tftp_api.rb | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/tftp/server.rb b/modules/tftp/server.rb index 98218d8bd..2476ba78b 100644 --- a/modules/tftp/server.rb +++ b/modules/tftp/server.rb @@ -165,10 +165,11 @@ def self.fetch_boot_file(dst, src) def self.choose_protocol_and_fetch(src, destination) case URI(src).scheme when 'http', 'https', 'ftp' - ::Proxy::HttpDownload.new(src.to_s, destination.to_s, - connect_timeout: Proxy::TFTP::Plugin.settings.tftp_connect_timeout, - verify_server_cert: Proxy::TFTP::Plugin.settings.verify_server_cert).start - + thread = ::Proxy::HttpDownload.new(src.to_s, destination.to_s, + connect_timeout: Proxy::TFTP::Plugin.settings.tftp_connect_timeout, + verify_server_cert: Proxy::TFTP::Plugin.settings.verify_server_cert) + thread.start + thread when 'nfs' logger.debug "NFS as a protocol for installation medium detected." else diff --git a/modules/tftp/tftp_api.rb b/modules/tftp/tftp_api.rb index 1bc6276c7..3fc175a27 100644 --- a/modules/tftp/tftp_api.rb +++ b/modules/tftp/tftp_api.rb @@ -35,7 +35,16 @@ def create_default(variant) end post "/fetch_boot_file" do - log_halt(400, "TFTP: Failed to fetch boot file: ") { Proxy::TFTP.fetch_boot_file(params[:prefix], params[:path]) } + log_halt(400, "TFTP: Failed to fetch boot file: ") do + result = Proxy::TFTP.fetch_boot_file(params[:prefix], params[:path]) + + # fetch_boot_file may start a thread + # This waits for a bit before telling the client we've accepted it + # TODO: implement a mechanism to poll for completion + if result.respond_to(:join) + 202 unless result.join(5) + end + end end post "/:variant/create_default" do |variant|