Skip to content

Commit

Permalink
Add dataset schema validation for build process
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Sep 13, 2023
1 parent f4447fa commit 9c0d6e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scale_build/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main():
)

validate_parser = subparsers.add_parser('validate', help='Validate TrueNAS Scale build manifest and system state')
for action in ('manifest', 'system_state'):
for action in ('datasets', 'manifest', 'system_state'):
validate_parser.add_argument(f'--validate-{action}', dest=action, action='store_true')
validate_parser.add_argument(f'--no-validate-{action}', dest=action, action='store_false')
validate_parser.set_defaults(**{action: True})
Expand All @@ -93,7 +93,7 @@ def main():
elif args.action == 'clean':
complete_cleanup()
elif args.action == 'validate':
validate(args.system_state, args.manifest)
validate(args.system_state, args.manifest, args.datasets)
elif args.action == 'branchout':
validate_branch_out_config(not args.skip_push)
branch_out_repos(not args.skip_push)
Expand Down
12 changes: 11 additions & 1 deletion scale_build/validate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import jsonschema
import logging
import shutil

from .exceptions import CallError, MissingPackagesException
from .utils.manifest import validate_manifest
from truenas_install import fhs


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -31,10 +33,18 @@ def validate_system_state():
raise MissingPackagesException(missing_packages)


def validate(system_state_flag=True, manifest_flag=True):
def validate_datasets():
jsonschema.validate(fhs.TRUENAS_DATASETS, fhs.TRUENAS_DATASET_SCHEMA)


def validate(system_state_flag=True, manifest_flag=True, datasets_flag=True):
if system_state_flag:
validate_system_state()
logger.debug('System state Validated')
if manifest_flag:
validate_manifest()
logger.debug('Manifest Validated')

if datasets_flag:
validate_datasets()
logger.debug('Dataset schema Validated')
47 changes: 43 additions & 4 deletions truenas_install/fhs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
KEYS
--------------
The following keys are supported:
`name` - the name of the dataset (will be appended to other dataset
name related components
`options` - Dataset configuration options (explained below)
`name` - the name of the dataset (will be appended to other dataset name
related components
`options` - Dataset configuration options (explained below). There is no
default.
`mode` - permissions to set on the dataset's mountpoint during installation
`mountpoint` - dataset mountpoint.
default is 0o755
`mountpoint` - dataset mountpoint. If no mountpoint is specified then it
/`name` will be assumed.
`snap` - Take a snapshot named "pristine" after creating the dataset.
default is False
OPTIONS
--------------
Expand Down Expand Up @@ -47,6 +51,41 @@
from /usr/local/share/ca-certificates.
"""


# Following schema is used for validation (e.g. "make validate") in scale-build
# If any changes are made to OPTIONS or KEYS above then schema must be updated
# accordingly.
TRUENAS_DATASET_SCHEMA = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'options': {
'type': 'array',
'items': {
'type': 'string',
'enum': [
'NOSUID',
'NOEXEC',
'NOACL',
'NOATIME',
'RO',
'NODEV',
]
},
'uniqueItems': True,
},
'mode': {'type': 'integer'},
'mountpoint': {'type': 'string'},
'snap': {'type': 'boolean'},
},
'required': ['name', 'options'],
'additionalProperties': False,
}
}


TRUENAS_DATASETS = [
{
'name': 'audit',
Expand Down

0 comments on commit 9c0d6e7

Please sign in to comment.