Wget: add skip_exists option and align the Windows signature - #4658
Wget: add skip_exists option and align the Windows signature#4658mcgov (mcgov) wants to merge 2 commits into
Conversation
The merge-base changed after approval.
f6ee330 to
888c5e5
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the Wget.get API to support reusing already-downloaded files via a new skip_exists flag, and updates WindowsWget.get to keep its override signature aligned with the base class. This is intended to avoid repeated downloads of large tarballs in the DPDK SRIOV hot plug test rework series.
Changes:
- Add
skip_exists: bool = FalsetoWget.getand short-circuit when the target path already exists. - Add
skip_exists: bool = FalsetoWindowsWget.getto match the base signature.
Suppressed comments (1)
lisa/base_tools/wget.py:183
- Major:
WindowsWget.getnow acceptsskip_exists, but it isn’t used, so callers will still re-download. Also, the existingoverwrite=Falsebranch checksfile_path(directory) and only logs without returning, so it doesn’t actually prevent overwriting. Add an early return when the targetdownload_pathalready exists and eitherskip_exists=Trueoroverwrite=False.
skip_exists: bool = False,
) -> str:
cached_filename = self._url_file_cache.get(url, None)
if cached_filename:
if force_run:
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
888c5e5 to
47df644
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:74
- When
skip_exists=Trueand the target file already exists, the method returns early (line 72) without updating_url_file_cache. That means subsequentget(url, ...)calls in the same run won’t benefit from the cache and may re-download unlessskip_existsis repeatedly passed. Consider caching the existingdownload_path(or its canonicalls-resolved path) before returning.
download_pure_path = self.node.get_pure_path(download_path)
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
lisa/base_tools/wget.py:180
WindowsWget.getadds theskip_existsparameter for signature alignment, but the implementation never reads it, so callers can’t actually reuse an existing downloaded file on Windows. Also, the current “return if file exists and not overwrite” block doesn’t return, sooverwrite=Falseis effectively ignored. Please honorskip_exists(andoverwrite=False) with an early return whendownload_pathalready exists.
executable: bool = False,
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
) -> str:
47df644 to
8908aad
Compare
8908aad to
84faa3c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:180
WindowsWget.getadds theskip_existsparameter to matchWget.get, but it is never used. As a result, the Windows implementation will still remove and re-download even whenskip_exists=True, so callers can’t rely on the cross-platform behavior implied by the base class signature. Implement an early return when the target file already exists (and optionally populate_url_file_cache).
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
) -> str:
lisa/base_tools/wget.py:74
- When
skip_exists=Trueand the target path already exists, this returns early without updating_url_file_cacheand without applyingexecutable=True(nochmod +x). Callers usingskip_existswithexecutablecan get a non-executable file and future calls won’t benefit from the URL cache. Consider resolving the existing file path (samelslogic as the download path), caching it, and still applyingchmodwhen requested before returning.
This issue also appears on line 176 of the same file.
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:179
- Major:
WindowsWget.get()now acceptsskip_exists, but the parameter is currently unused. As a result, callers cannot actually reuse an already-downloaded file on Windows (the method will still proceed to remove and re-download later). Please add an early check forls.path_exists(download_path)and return the existing path (and optionally update_url_file_cache) whenskip_exists=True(and also whenoverwrite=False, per the existing comment).
executable: bool = False,
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
lisa/base_tools/wget.py:73
- Major: When
skip_existsis true and the target file already exists, this early return returnsdownload_pathwithout updating_url_file_cacheand without normalizing the path the same way the download path does (laterlsoutput is cached/returned). This can lead to inconsistent return values (e.g.,~/relative paths) and repeated downloads on subsequent calls. Consider resolving the existing path with the samelslogic used later, cache it (self._url_file_cache[url] = actual_file_path), and return the normalized path.
download_pure_path = self.node.get_pure_path(download_path)
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
84faa3c to
8404bc3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:72
- Major:
overwrite=Falsestill triggers a re-download when the target path already exists (the code only returns early forskip_exists). Callers that setoverwrite=Falseto avoid re-downloading large artifacts will still hit the network and potentially overwrite the existing file. Consider either treatingoverwrite=Falseas an early-return when the file exists (similar toskip_exists), or clarifying/deprecatingoverwritein favor ofskip_existsto avoid ambiguous API semantics.
# remove existing file and dir to download again.
download_pure_path = self.node.get_pure_path(download_path)
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
lisa/base_tools/wget.py:180
- Major:
WindowsWget.get()now acceptsskip_exists, but the parameter is unused in the method body, so Windows callers cannot actually reuse an existing download (the method always removes and re-downloads). Either implement the same early-return behavior asWget.get()when the destination exists, or removeskip_existsfrom the override if it is intentionally unsupported on Windows.
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
) -> str:
8404bc3 to
74d811f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:74
- When
skip_exists=Trueand the target path already exists, this returns early without updating_url_file_cache[url]and without applyingexecutable=True(the laterchmod +x). This can lead to repeatedexists()checks and surprising behavior where callers request an executable but the existing file keeps non-exec permissions. Consider resolving the existing path withls, caching it, and applyingchmodbefore returning.
# remove existing file and dir to download again.
download_pure_path = self.node.get_pure_path(download_path)
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
lisa/base_tools/wget.py:183
WindowsWget.getnow acceptsskip_exists, but the method doesn’t use it. Also, the existing “not overwrite” branch checksls.path_exists(file_path)(directory) and only logs, so it still removes and re-downloads the file. This makes bothskip_existsandoverwrite=Falseineffective on Windows; consider checkingdownload_pathand returning early when reuse is requested.
skip_exists: bool = False,
) -> str:
cached_filename = self._url_file_cache.get(url, None)
if cached_filename:
if force_run:
74d811f to
cb82307
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:74
overwrite=Falseis not currently honored when the target file already exists: the code only skips pre-removal, but still runswget ... -O {download_path}which will clobber the file. Since callers rely onoverwrite=Falseto avoid re-downloading (e.g. DPDK tarball downloads), consider treatingnot overwritethe same asskip_exists(early-return when the path exists), or pass a no-clobber flag instead.
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
lisa/base_tools/wget.py:180
WindowsWget.get()adds theskip_existsparameter to match the base signature, but it is never used. As a result Windows always removes and re-downloads even whenskip_exists=True(and also whenoverwrite=False). Add an early-return whendownload_pathalready exists to keep semantics aligned withWget.get().
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
) -> str:
cb82307 to
9e74ca5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:183
- Major: WindowsWget.get adds the skip_exists parameter but the implementation never references it, so callers cannot actually reuse an existing download on Windows (it will still remove and re-download). Consider checking whether download_path already exists (e.g., via ls.path_exists(download_path, sudo=sudo)) and returning early when skip_exists=True.
skip_exists: bool = False,
) -> str:
cached_filename = self._url_file_cache.get(url, None)
if cached_filename:
if force_run:
lisa/base_tools/wget.py:74
- Major: skip_exists=True returns early without updating _url_file_cache and without applying the executable=True chmod behavior. This can cause repeated existence checks on later calls and can return a non-executable file even though the caller requested executable=True. Consider caching the returned path and, if executable=True, ensuring chmod is applied before returning.
This issue also appears on line 179 of the same file.
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
9e74ca5 to
119044b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/base_tools/wget.py:180
skip_existswas added to theWindowsWget.getsignature, but the implementation never uses it (and the current “exists + not overwrite” branch doesn’t return and checksfile_path(directory) rather thandownload_path). As a result, Windows still removes/redownloads even when callers request reuse. Consider mirroring the base behavior: ifdownload_pathexists and (skip_existsis True oroverwriteis False), returndownload_pathwithout deleting/redownloading.
def get(
self,
url: str,
file_path: str = "",
filename: str = "",
overwrite: bool = True,
executable: bool = False,
sudo: bool = False,
force_run: bool = False,
timeout: int = 600,
skip_exists: bool = False,
) -> str:
lisa/base_tools/wget.py:74
- In
Wget.get, the newskip_existsearly-return bypasses the rest of the method, so it won’t update_url_file_cachefor the URL and won’t applyexecutable=True(chmod) when the file already exists. It would be more consistent to still populate the cache and apply the executable bit before returning whenskip_existsis set.
if self.node.shell.exists(download_pure_path):
if skip_exists:
return download_path
elif overwrite:
self.node.shell.remove(download_pure_path, recursive=True)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lisa/base_tools/wget.py:75
- When returning early due to an existing download (skip_exists or overwrite=False), the method bypasses the
executablehandling, so callers requesting an executable may get a non-executable file. Consider applyingchmod +x(whenexecutable=True) before returning, similar to the post-download path.
if self.node.shell.exists(download_pure_path):
if skip_exists or not overwrite:
self._url_file_cache[url] = download_path
return download_path
Downloading large assets again on every run is slow and can fail on flaky mirrors. Add skip_exists so callers can reuse a file that is already present on the node instead of removing and redownloading it. WindowsWget.get takes the same argument so the override keeps matching the base class. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5d5f58ad-b9df-4420-ad37-22caee78e925
0cf94da to
21fd1a3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lisa/base_tools/wget.py:73
- When returning early because the target path already exists (
skip_existsoroverwriteis False), theexecutableflag is ignored. This can leave an existing/non-executable file without+xeven though the caller requested it. Consider applyingchmod +x(respectingsudo) before returning whenexecutable=True, or otherwise documenting thatexecutableis only enforced on fresh downloads.
if self.node.shell.exists(download_pure_path):
if skip_exists or not overwrite:
self._url_file_cache[url] = download_path
return download_path
Part 5 of 9 of a stacked series that reworks the DPDK SRIOV hot plug tests. Stacked on #4657, review only the last commit.
Downloading large source tarballs again on every run is slow and can fail on flaky mirrors.
Wget.getgainsskip_existsso callers can reuse a file that is already present on the node instead of removing and redownloading it.WindowsWget.gettakes the same argument so the override keeps matching the base class.Key Test Cases:
verify_dpdk_build_netvsc|verify_dpdk_build_failsafe
Impacted LISA Features:
Sriov, NetworkInterface
Tested Azure Marketplace Images:
canonical 0001-com-ubuntu-server-jammy 22_04-lts latestmicrosoftcblmariner azure-linux-3 azure-linux-3 latest