-
Notifications
You must be signed in to change notification settings - Fork 157
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
overlay.d & tests: Add alternatives migration and test #3253
Open
travier
wants to merge
2
commits into
coreos:testing-devel
Choose a base branch
from
travier:testing-devel-alternatives-migration
base: testing-devel
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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,2 @@ | ||
# Config file for overriding permission bits on overlay files/dirs | ||
# Format: =<file mode in decimal> <absolute path to a file or directory> |
This file contains 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,2 @@ | ||
# Config file for overriding permission bits on overlay files/dirs | ||
# Format: =<file mode in decimal> <absolute path to a file or directory> |
This file contains 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,2 @@ | ||
# Config file for overriding permission bits on overlay files/dirs | ||
# Format: =<file mode in decimal> <absolute path to a file or directory> |
This file contains 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,2 @@ | ||
# Config file for overriding permission bits on overlay files/dirs | ||
# Format: =<file mode in decimal> <absolute path to a file or directory> |
23 changes: 23 additions & 0 deletions
23
overlay.d/50alternatives/usr/libexec/coreos-alternatives-migration
This file contains 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,23 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
# set -x | ||
|
||
main() { | ||
# Should never happen as systemd checks this, but just in case | ||
if [[ ! -d "/var/lib/alternatives" ]]; then | ||
echo "Skipped /var/lib/alternatives as it is not a directory" | ||
exit 0 | ||
fi | ||
|
||
# We can safely directly try to remove the directory as rmdir will fail on | ||
# a non-empty directory | ||
rmdir "/var/lib/alternatives" || echo "Warning: /var/lib/alternatives is not empty" | ||
|
||
# Do the migration, explicitely using the new configuration directory to | ||
# ignore /var/lib/alternatives if it still exists | ||
alternatives --admindir /etc/alternatives-admindir --set iptables /usr/sbin/iptables-nft | ||
return $? | ||
} | ||
|
||
main "${@}" |
12 changes: 12 additions & 0 deletions
12
overlay.d/50alternatives/usr/systemd/system/coreos-alternatives-migration.service
This file contains 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,12 @@ | ||
[Unit] | ||
Description=Migrate systems to fixed alternatives configuration | ||
ConditionPathExists=/var/lib/alternatives | ||
ConditionPathIsDirectory=/var/lib/alternatives | ||
|
||
[Service] | ||
ExecStart=/usr/libexec/coreos-alternatives-migration | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
|
||
[Install] | ||
WantedBy=basic.target |
This file contains 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 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,79 @@ | ||
#!/bin/bash | ||
## kola: | ||
## description: Verify that the alternatives config is properly migrated and test the migration | ||
|
||
# See | ||
# - https://github.com/coreos/fedora-coreos-tracker/issues/1818 | ||
|
||
set -xeuo pipefail | ||
|
||
# shellcheck disable=SC1091 | ||
. "$KOLA_EXT_DATA/commonlib.sh" | ||
|
||
if test -e "/var/lib/alternatives"; then | ||
ls -al "/var/lib/alternatives" | ||
fatal "Error: Found '/var/lib/alternatives' which should not exists" | ||
fi | ||
if ! test -d "/etc/alternatives"; then | ||
fatal "Error: '/etc/alternatives' is missing" | ||
fi | ||
if ! test -d "/etc/alternatives-admindir"; then | ||
fatal "Error: '/etc/alternatives-admindir' is missing" | ||
fi | ||
|
||
# To test the migration we will re-create the setup from an older FCOS node | ||
|
||
# First, reset iptables to the legacy backend | ||
alternatives --set iptables /usr/sbin/iptables-legacy | ||
if [[ $(alternatives --display iptables | grep -c "link currently points to /usr/sbin/iptables-legacy") != "1" ]]; then | ||
fatal "Could not set iptables to legacy backend for testing" | ||
fi | ||
if [[ $(iptables --version | grep -c "legacy") != "1" ]]; then | ||
fatal "Could not set iptables to legacy backend for testing" | ||
fi | ||
|
||
# Then re-create the broken alternatives folder in /var | ||
install -dm0755 /var/lib/alternatives | ||
|
||
# Do the migration | ||
/usr/libexec/coreos-alternatives-migration | ||
|
||
if [[ $(alternatives --admindir /etc/alternatives-admindir --display iptables | grep -c "link currently points to /usr/sbin/iptables-nft") != "1" ]]; then | ||
fatal "Error: migration did not set iptables to nft backend" | ||
fi | ||
if [[ $(iptables --version | grep -c "nf_tables") != "1" ]]; then | ||
fatal "Error: iptables not reset to nftables backend" | ||
fi | ||
if [[ -d "/var/lib/alternatives" ]]; then | ||
fatal "Error: /var/lib/alternatives should not exists anymore" | ||
fi | ||
|
||
# Second case, if an admin set some config up for alternatives | ||
|
||
# First, reset iptables to the legacy backend | ||
alternatives --set iptables /usr/sbin/iptables-legacy | ||
if [[ $(alternatives --display iptables | grep -c "link currently points to /usr/sbin/iptables-legacy") != "1" ]]; then | ||
fatal "Could not set iptables to legacy backend for testing" | ||
fi | ||
if [[ $(iptables --version | grep -c "legacy") != "1" ]]; then | ||
fatal "Could not set iptables to legacy backend for testing" | ||
fi | ||
|
||
# Then re-create the broken alternatives folder in /var | ||
install -dm0755 /var/lib/alternatives | ||
|
||
# And add some fake config | ||
touch /var/lib/alternatives/foo | ||
|
||
# Do the migration | ||
/usr/libexec/coreos-alternatives-migration | ||
|
||
if [[ $(alternatives --admindir /etc/alternatives-admindir --display iptables | grep -c "link currently points to /usr/sbin/iptables-nft") != "1" ]]; then | ||
fatal "Error: migration did not set iptables to nft backend" | ||
fi | ||
if [[ $(iptables --version | grep -c "nf_tables") != "1" ]]; then | ||
fatal "Error: iptables not reset to nftables backend" | ||
fi | ||
if [[ ! -d "/var/lib/alternatives" ]]; then | ||
fatal "Error: /var/lib/alternatives should still exists" | ||
fi |
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.
On silverblue, check
/var/lib/alternatives
is broken link, should we care about this?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.
Indeed, if we want to have a single migration script for all variants then we should take this one into account.