-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from truenas/catalog-validate-script
Add catalog validate script to validate catalog structure
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
|
||
from apps_validation.exceptions import CatalogDoesNotExist, ValidationErrors | ||
from apps_validation.validation.validate_catalog import validate_catalog | ||
|
||
|
||
def validate(catalog_path): | ||
|
||
try: | ||
validate_catalog(catalog_path) | ||
except CatalogDoesNotExist: | ||
print(f'[\033[91mFAILED\x1B[0m]\tSpecified {catalog_path!r} path does not exist') | ||
exit(1) | ||
except ValidationErrors as verrors: | ||
print('[\033[91mFAILED\x1B[0m]\tFollowing validation failures were found:') | ||
for index, verror in enumerate(verrors.errors): | ||
print(f'[\033[91m{index}\x1B[0m]\t{verror}') | ||
exit(1) | ||
else: | ||
print('[\033[92mOK\x1B[0m]\tPASSED VALIDATION CHECKS') | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
subparsers = parser.add_subparsers(help='sub-command help', dest='action') | ||
|
||
parser_setup = subparsers.add_parser('validate', help='Validate TrueNAS catalog') | ||
parser_setup.add_argument('--path', help='Specify path of TrueNAS catalog') | ||
|
||
args = parser.parse_args() | ||
if args.action == 'validate': | ||
validate(args.path) | ||
else: | ||
parser.print_help() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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