-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for new blivet fstab handling
Blivet can now handle fstab, so handling it in the role became redundant. This adapts the role for the blivet change and removes no longer needed code. - requires blivet PRs #1119 (main change) and #1197 (bug fixes) Issue Tracker Tickets (Jira): #20182
- Loading branch information
Showing
5 changed files
with
89 additions
and
158 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,61 @@ | ||
import json | ||
import subprocess | ||
import sys | ||
|
||
|
||
def find_dev_in_fstab(dev, fstab): | ||
# check whether some device representation is present in the fstab | ||
if not dev: | ||
raise ValueError("No device given") | ||
|
||
# dev can be represented by string starting with description followed by '=' (e.g. UUID=<something>) | ||
pair = dev.split('=') | ||
prefix = "/dev/disk/by-*/" | ||
|
||
if len(pair) == 1: | ||
dev_id = pair[0] | ||
if dev_id.startswith('/'): | ||
prefix = "" | ||
else: | ||
dev_id = pair[1] | ||
|
||
cmd_output = subprocess.run("lsblk --list -Jno PATH,UUID,PARTUUID,LABEL,PARTLABEL %s%s" % (prefix, dev_id), | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
text=True) | ||
|
||
if cmd_output.stderr: | ||
raise ValueError("Lsblk command failed: %s" % cmd_output.stderr) | ||
|
||
blockdevices = json.loads(cmd_output.stdout)['blockdevices'] | ||
|
||
exact_matches = 0 | ||
partial_matches = 0 | ||
|
||
for bdev in blockdevices: | ||
for key in ['path', 'uuid', 'partuuid', 'label', 'partlabel']: | ||
if bdev[key] is not None and bdev[key] in fstab: | ||
if dev_id == bdev[key]: | ||
exact_matches += 1 | ||
else: | ||
partial_matches += 1 | ||
|
||
return exact_matches, partial_matches | ||
|
||
|
||
def main(args): | ||
if len(args) < 2: | ||
raise ValueError("Missing arguments") | ||
|
||
dev = args[1] | ||
|
||
# This is an ugly stuff but it will work for the testing purposes | ||
fstab = ' '.join(args[2:]) | ||
|
||
exact_matches, partial_matches = find_dev_in_fstab(dev, fstab) | ||
|
||
print(exact_matches, partial_matches) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv) |
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