Skip to content
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

Adapt rootpw tests to crypt module removal in Python 3.13 #1219

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fragments/platform/rhel10/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
3 changes: 3 additions & 0 deletions fragments/platform/rhel8/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
3 changes: 3 additions & 0 deletions fragments/platform/rhel9/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
4 changes: 4 additions & 0 deletions fragments/shared/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%packages
python3
python3-crypt-r
%end
14 changes: 8 additions & 6 deletions rootpw-basic.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ rootpw qweqwe

shutdown

# make sure Python 3 is available for the %post scriptlet
%packages
python3
%end
%ksappend payload/python_crypt_packages.ks

%post --interpreter=/usr/bin/python3

import sys
import crypt
try:
# Use the standalone (not deprecated) package when available
import crypt_r
except ImportError:
# Fallback to the deprecated standard library module
import crypt as crypt_r # pylint: disable=deprecated-module

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand All @@ -39,7 +41,7 @@ with open("/root/RESULT", "wt") as result:
print("Unable to find root password", file=result)
sys.exit(0)

if crypt.crypt("qweqwe", shadow_fields[1]) != shadow_fields[1]:
if crypt_r.crypt("qweqwe", shadow_fields[1]) != shadow_fields[1]:
print("Root password is not correct: %s" % shadow_fields[1], file=result)
sys.exit(0)

Expand Down
1 change: 0 additions & 1 deletion rootpw-crypted.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ python3
%post --interpreter=/usr/bin/python3

import sys
import crypt

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand Down
1 change: 0 additions & 1 deletion rootpw-lock-no-password.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ python3
%post --interpreter=/usr/bin/python3

import sys
import crypt

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand Down
14 changes: 8 additions & 6 deletions rootpw-lock.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ rootpw --lock qweqwe

shutdown

# make sure Python 3 is available for the %post scriptlet
%packages
python3
%end
%ksappend payload/python_crypt_packages.ks

%post --interpreter=/usr/bin/python3

import sys
import crypt
try:
# Use the standalone (not deprecated) package when available
import crypt_r
except ImportError:
# Fallback to the deprecated standard library module
import crypt as crypt_r # pylint: disable=deprecated-module

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand All @@ -48,7 +50,7 @@ with open("/root/RESULT", "wt") as result:
print("Root password is not locked: %s" % shadow_fields[1], file=result)
sys.exit(0)

if crypt.crypt("qweqwe", shadow_fields[1][1:]) != shadow_fields[1][1:]:
if crypt_r.crypt("qweqwe", shadow_fields[1][1:]) != shadow_fields[1][1:]:
print("Root password is not correct: %s" % shadow_fields[1], file=result)
sys.exit(0)

Expand Down