Skip to content

Commit

Permalink
Merge pull request #3 from truenas/catalog-validate-script
Browse files Browse the repository at this point in the history
Add catalog validate script to validate catalog structure
  • Loading branch information
sonicaj authored Apr 23, 2024
2 parents 4c72ee6 + c1ba085 commit 990db3c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions apps_validation/scripts/catalog_validate.py
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()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
platforms='any',
entry_points={
'console_scripts': [
'dev_charts_validate = apps_validation.scripts.dev_apps_validate:main',
'apps_catalog_validate = catalog_validation.scripts.catalog_validate:main',
'apps_dev_charts_validate = apps_validation.scripts.dev_apps_validate:main', # TODO: Remove apps_prefix
],
},
)

0 comments on commit 990db3c

Please sign in to comment.