Repository navigation
Fixes #39765 - TFTP archive extraction feature #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lzap
wants to merge
1
commit into
theforeman:develop
Choose a base branch
from
lzap:tftp-api-39765
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| PROXY_URL="http://127.0.0.1:8000" | ||
|
|
||
| # CentOS 10 Stream | ||
| curl --fail --silent --show-error \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data '{ | ||
| "extract": { | ||
| "source": "https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/images/boot.iso", | ||
| "destination": "bootloader-universe/pxegrub2/centos/10/x86_64/boot.iso", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
| "type": "iso", | ||
| "files": { | ||
| "bootloader-universe/pxegrub2/centos/10/x86_64/grubx64.efi": "EFI/BOOT/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/centos/10/x86_64/shimx64.efi": "EFI/BOOT/BOOTX64.EFI" | ||
| }, | ||
| "symlinks": { | ||
| "bootloader-universe/pxegrub2/centos/10/x86_64/boot.efi": "bootloader-universe/pxegrub2/centos/10/x86_64/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/centos/10/x86_64/boot-sb.efi": "bootloader-universe/pxegrub2/centos/10/x86_64/shimx64.efi" | ||
| } | ||
| } | ||
| }' \ | ||
| "${PROXY_URL}/tftp/fetch_and_process" | ||
|
|
||
| # Debian stable | ||
| curl --fail --silent --show-error \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data '{ | ||
| "extract": { | ||
| "source": "https://deb.debian.org/debian/dists/bookworm/main/installer-amd64/current/images/netboot/netboot.tar.gz", | ||
| "destination": "bootloader-universe/pxegrub2/debian/bookworm/amd64/netboot.tar.gz", | ||
| "type": "tgz", | ||
| "files": { | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/linux": "debian-installer/amd64/linux", | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/initrd.gz": "debian-installer/amd64/initrd.gz", | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/grubx64.efi": "debian-installer/amd64/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/shimx64.efi": "debian-installer/amd64/bootnetx64.efi" | ||
| }, | ||
| "symlinks": { | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/boot.efi": "bootloader-universe/pxegrub2/debian/bookworm/amd64/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/debian/bookworm/amd64/boot-sb.efi": "bootloader-universe/pxegrub2/debian/bookworm/amd64/shimx64.efi" | ||
| } | ||
| } | ||
| }' \ | ||
| "${PROXY_URL}/tftp/fetch_and_process" | ||
|
|
||
| # Ubuntu stable | ||
| curl --fail --silent --show-error \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data '{ | ||
| "extract": { | ||
| "source": "https://releases.ubuntu.com/26.04/ubuntu-26.04-netboot-amd64.tar.gz", | ||
| "destination": "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/netboot.tar.gz", | ||
| "type": "tgz", | ||
| "files": { | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/linux": "amd64/linux", | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/initrd.gz": "amd64/initrd", | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/grubx64.efi": "amd64/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/shimx64.efi": "amd64/bootx64.efi" | ||
| }, | ||
| "symlinks": { | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/boot.efi": "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/grubx64.efi", | ||
| "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/boot-sb.efi": "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/shimx64.efi" | ||
| } | ||
| } | ||
| }' \ | ||
| "${PROXY_URL}/tftp/fetch_and_process" | ||
|
|
||
| # Ubuntu ISO is also needed | ||
| curl --fail --silent --show-error \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data '{ | ||
| "source": "https://releases.ubuntu.com/26.04/ubuntu-26.04-live-server-amd64.iso", | ||
| "destination": "bootloader-universe/pxegrub2/ubuntu/26.04/amd64/boot.iso" | ||
| }' \ | ||
| "${PROXY_URL}/tftp/fetch_and_process" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| module Proxy::TFTP | ||
| class BootFilesInProgress < StandardError | ||
| def status_code | ||
| 409 | ||
| end | ||
| end | ||
|
|
||
| # Coordinates writes and reads of TFTP paths so conflicting operations can | ||
| # fail fast instead of waiting on work in progress. | ||
| class DirLock | ||
| def initialize | ||
| @mutex = Mutex.new | ||
| @active = {} | ||
| end | ||
|
|
||
| # Call defer_release when handing the reservation to async work. That work | ||
| # must call release on completion. Otherwise, release happens on block exit. | ||
| def with_write(paths) | ||
| registered = false | ||
| deferred = false | ||
| released = false | ||
| release_mutex = Mutex.new | ||
| release = proc do | ||
| should_release = release_mutex.synchronize do | ||
| next false if released | ||
| released = true | ||
| end | ||
| release_write(paths) if should_release | ||
| end | ||
| defer_release = proc { deferred = true } | ||
|
|
||
| paths = reserve_write(paths) | ||
| registered = true | ||
| yield release, defer_release | ||
| ensure | ||
| release.call if registered && !deferred | ||
| end | ||
|
|
||
| def with_read(paths) | ||
| reserved_paths = reserve_read(paths) | ||
| yield | ||
| ensure | ||
| release_read(reserved_paths) if reserved_paths | ||
| end | ||
|
|
||
| def active?(path) | ||
| @mutex.synchronize do | ||
| @active.any? { |active_path, entry| entry[:writer] && paths_conflict?(active_path, path.to_s) } | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def reserve_write(paths) | ||
| paths = normalize_paths(paths) | ||
| @mutex.synchronize do | ||
| busy_path = paths.find do |path| | ||
| @active.keys.find { |active_path| paths_conflict?(active_path, path) } | ||
| end | ||
| raise BootFilesInProgress, "TFTP files are already being updated: #{busy_path}" if busy_path | ||
|
|
||
| paths.each { |path| @active[path] = { writer: true, readers: 0 } } | ||
| end | ||
| paths | ||
| end | ||
|
|
||
| def release_write(paths) | ||
| @mutex.synchronize do | ||
| paths.each do |path| | ||
| entry = @active[path.to_s] | ||
| @active.delete(path.to_s) if entry && entry[:writer] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def reserve_read(paths) | ||
| paths = normalize_paths(paths) | ||
| @mutex.synchronize do | ||
| busy_path = paths.find do |path| | ||
| @active.any? { |active_path, entry| entry[:writer] && paths_conflict?(active_path, path) } | ||
| end | ||
| raise BootFilesInProgress, "Bootloader universe files are currently being downloaded or extracted: #{busy_path}" if busy_path | ||
|
|
||
| paths.each do |path| | ||
| entry = @active[path] ||= { writer: false, readers: 0 } | ||
| entry[:readers] += 1 | ||
| end | ||
| end | ||
| paths | ||
| end | ||
|
|
||
| def release_read(paths) | ||
| @mutex.synchronize do | ||
| paths.each do |path| | ||
| entry = @active[path.to_s] | ||
| next unless entry && entry[:readers].positive? | ||
|
|
||
| entry[:readers] -= 1 | ||
| @active.delete(path.to_s) if entry[:readers].zero? && !entry[:writer] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def normalize_paths(paths) | ||
| paths.map(&:to_s).uniq | ||
| end | ||
|
|
||
| def paths_conflict?(first, second) | ||
| first == second || first.start_with?("#{second}#{File::SEPARATOR}") || second.start_with?("#{first}#{File::SEPARATOR}") | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the PR description:
But here I see the
sourceas part of theextract, not as a new third field.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually different fields, there is "source" and "destination" (aliases) and "extract.source" and "extract.destination". I know this is confusing. As I said elsewhere now I think I should drop the modifications of the original API call and make a new one and keep the original untouched.