-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from truenas/NAS-125472
NAS-125472 / 24.04 / Validate cached bootstrap directory based off on the reference group/passwd files
- Loading branch information
Showing
4 changed files
with
56 additions
and
27 deletions.
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
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,34 @@ | ||
import os | ||
import difflib | ||
|
||
from scale_build.exceptions import CallError | ||
|
||
from .paths import REFERENCE_FILES_DIR, REFERENCE_FILES, CHROOT_BASEDIR | ||
|
||
|
||
def compare_reference_files(cut_nonexistent_user_group_membership=False): | ||
for reference_file in REFERENCE_FILES: | ||
with open(os.path.join(REFERENCE_FILES_DIR, reference_file)) as f: | ||
reference = f.readlines() | ||
|
||
if not os.path.exists(os.path.join(CHROOT_BASEDIR, reference_file)): | ||
raise CallError(f'File {reference_file!r} does not exist in cached chroot') | ||
|
||
if cut_nonexistent_user_group_membership: | ||
if reference_file == 'etc/group': | ||
# `etc/group` on newly installed system can't have group membership information for users that have | ||
# not been created yet. | ||
with open(os.path.join(CHROOT_BASEDIR, 'etc/passwd')) as f: | ||
reference_users = {line.split(':')[0] for line in f.readlines()} | ||
|
||
for i, line in enumerate(reference): | ||
bits = line.rstrip().split(':') | ||
bits[3] = ','.join([user for user in bits[3].split(',') if user in reference_users]) | ||
reference[i] = ':'.join(bits) + '\n' | ||
|
||
with open(os.path.join(CHROOT_BASEDIR, reference_file)) as f: | ||
real = f.readlines() | ||
|
||
diff = list(difflib.unified_diff(reference, real)) | ||
|
||
yield reference_file, diff[3:] |
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