Пример #1
0
def testTlmValidator():
    # test successful tlm validation
    msgs, v = tlmval([os.path.join(DATA_PATH,  "testValidTlm1.yaml"), tlm.getDefaultSchema()])
    dispmsgs(msgs)
    assert v
    assert len(msgs) == 0

    # test failed tlm validation - duplicate packet name
    try:
        msgs, v = tlmval([os.path.join(DATA_PATH,  "testTlmValidator1.yaml"), tlm.getDefaultSchema()])
        assert False
    except util.YAMLError, e:
        assert "Duplicate packet name" in e.message
Пример #2
0
def testTlmValidator():
    # test successful tlm validation
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testValidTlm1.yaml"), tlm.getDefaultSchema()]
    )
    dispmsgs(msgs)
    assert v
    assert len(msgs) == 0

    # test failed tlm validation - duplicate packet name
    try:
        msgs, v = tlmval(
            [os.path.join(DATA_PATH, "testTlmValidator1.yaml"), tlm.getDefaultSchema()]
        )
        assert False
    except util.YAMLError as e:
        assert "Duplicate packet name" in e.message

    # test failed tlm validation - duplicate field name
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testTlmValidator2.yaml"), tlm.getDefaultSchema()]
    )
    assert not v
    assert len(msgs) == 1
    assert "Duplicate field name" in msgs[0]

    # test failed tlm validation - invalid field type
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testTlmValidator3.yaml"), tlm.getDefaultSchema()]
    )
    assert not v
    assert len(msgs) == 1
    assert "Invalid field type" in msgs[0]

    # test failed tlm validation - invalid field size for field type specified
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testTlmValidator4.yaml"), tlm.getDefaultSchema()]
    )
    assert not v
    assert len(msgs) == 2
    assert "Invalid field size" in msgs[0]

    # test failed tlm validation - un-quoted YAML special variables in enumerations
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testTlmValidator5.yaml"), tlm.getDefaultSchema()]
    )
    assert not v
    assert len(msgs) == 2
    assert "Invalid enum value" in msgs[0]

    # test failed tlm validation - empty string for a YAML field
    msgs, v = tlmval(
        [os.path.join(DATA_PATH, "testTlmValidator6.yaml"), tlm.getDefaultSchema()]
    )

    assert not v
    assert len(msgs) == 1
    assert "Missing value for desc." in msgs[0]
Пример #3
0
def testTlmDictValidation():
    # Validation test of current telemetry dictionary
    msgs, v = tlmval([ait.config.tlmdict.filename, tlm.getDefaultSchema()])
    dispmsgs(msgs)
    assert v
    assert len(msgs) == 0
Пример #4
0
    assert len(msgs) == 0

    # test failed tlm validation - duplicate packet name
    try:
        msgs, v = tlmval([
            os.path.join(DATA_PATH, "testTlmValidator1.yaml"),
            tlm.getDefaultSchema()
        ])
        assert False
    except util.YAMLError, e:
        assert "Duplicate packet name" in e.message

    # test failed tlm validation - duplicate field name
    msgs, v = tlmval([
        os.path.join(DATA_PATH, "testTlmValidator2.yaml"),
        tlm.getDefaultSchema()
    ])
    assert not v
    assert len(msgs) == 1
    assert "Duplicate field name" in msgs[0]

    # test failed tlm validation - invalid field type
    msgs, v = tlmval([
        os.path.join(DATA_PATH, "testTlmValidator3.yaml"),
        tlm.getDefaultSchema()
    ])
    assert not v
    assert len(msgs) == 1
    assert "Invalid field type" in msgs[0]

    # test failed tlm validation - invalid field size for field type specified
Пример #5
0
def main():
    argparser = argparse.ArgumentParser(
        description="""
Validate YAML files with applicable schema and/or advanced
content validation for CMD and TLM dictionaries.

YAML validation is done through a combination of JSON Schema
(http://json-schema.org/) and Python-coded content validation.  The
JSON Schema is used to validate general format of the YAML, i.e
dictionaries contain the expected keys, values are the expected type,
etc.

Why JSON Schema? All of the available YAML validators did not meet the
robustness expected for this tool. Since JSON and YAML are stored
similarly in memory, the JSON Schema became an option.  The only
difference between YAML and JSON is the use of multiple documents in
the same YAML file. The val.py module handles this implication. See
TBD wiki page for more details on developing JSON schema for an
applicable YAML file.
""",
        epilog="""
Examples:

    $ ait-yaml-validate.py --cmd
    $ ait-yaml-validate.py --tlm
    $ ait-yaml-validate.py --evr
    $ ait-yaml-validate.py --cmd --yaml /path/to/cmd.yaml
    $ ait-yaml-validate.py --tlm --yaml /path/to/tlm.yaml
    $ ait-yaml-validate.py --yaml /path/to/yaml --schema /path/to/schema
""",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    argparser.add_argument('-y',
                           '--yaml',
                           metavar='</path/to/yaml>',
                           type=str,
                           help='Path to YAML file.')

    argparser.add_argument('-s',
                           '--schema',
                           metavar='</path/to/schema>',
                           type=str,
                           help='Path to JSON schema file.')

    argparser.add_argument(
        '-c',
        '--cmd',
        action='store_true',
        default=False,
        help="""Command dictionary flag. If a YAML file is not
        specified, the default command dictionary and schema will be used.
        """)

    argparser.add_argument(
        '-t',
        '--tlm',
        action='store_true',
        default=False,
        help="""Telemetry dictionary flag. If a YAML file is not
        specified, the default telemetry dictionary and schema will be used.
        """)

    argparser.add_argument(
        '-e',
        '--evr',
        action='store_true',
        default=False,
        help="""EVR dictionary flag. If a YAML file is not specified,
        the default EVR dictionary and schema will be used.
        """)

    argparser.add_argument(
        '-l',
        '--limits',
        action='store_true',
        default=False,
        help="""Limits dictionary flag. If a YAML file is not specified,
        the default limits dictionary and schema will be used.
        """)

    if len(sys.argv) < 2:
        argparser.print_usage()
        print 'Run with --help for detailed help.'
        sys.exit(2)

    options = argparser.parse_args()

    log.begin()

    # Validate specified yaml file with specified schema
    if options.yaml is not None and options.schema is not None:
        # Check YAML exists
        if not os.path.exists(options.yaml):
            raise os.error(options.yaml + " does not exist.")

        # Check schema exists
        if not os.path.exists(options.schema):
            raise os.error(options.schema + " does not exist.")

        validator = val.Validator
        retcode = validate(validator, options.yaml, options.schema)

    else:
        if options.cmd:
            yml = ait.config.cmddict.filename
            schema = cmd.getDefaultSchema()
            validator = val.CmdValidator
        elif options.evr:
            yml = ait.config.evrdict.filename
            schema = evr.getDefaultSchema()
            validator = val.Validator
        elif options.tlm:
            yml = ait.config.tlmdict.filename
            schema = tlm.getDefaultSchema()
            validator = val.TlmValidator
        elif options.limits:
            yml = ait.config.limits.filename
            schema = limits.getDefaultSchema()
            validator = val.Validator

        if options.yaml is not None:
            yml = options.yaml

        retcode = validate(validator, yml, schema)

    log.end()
    return retcode
Пример #6
0
def testTlmValidator():
    # test successful tlm validation
    msgs, v = tlmval([os.path.join(DATA_PATH,  "testValidTlm1.yaml"), tlm.getDefaultSchema()])
    dispmsgs(msgs)
    assert v
    assert len(msgs) == 0

    # test failed tlm validation - duplicate packet name
    try:
        msgs, v = tlmval([os.path.join(DATA_PATH,  "testTlmValidator1.yaml"), tlm.getDefaultSchema()])
        assert False
    except util.YAMLError, e:
        assert "Duplicate packet name" in e.message

    # test failed tlm validation - duplicate field name
    msgs, v = tlmval([os.path.join(DATA_PATH,  "testTlmValidator2.yaml"), tlm.getDefaultSchema()])
    assert not v
    assert len(msgs) == 1
    assert "Duplicate field name" in msgs[0]

    # test failed tlm validation - invalid field type
    msgs, v = tlmval([os.path.join(DATA_PATH,  "testTlmValidator3.yaml"), tlm.getDefaultSchema()])
    assert not v
    assert len(msgs) == 1
    assert "Invalid field type" in msgs[0]

    # test failed tlm validation - invalid field size for field type specified
    msgs, v = tlmval([os.path.join(DATA_PATH,  "testTlmValidator4.yaml"), tlm.getDefaultSchema()])
    assert not v
    assert len(msgs) == 2
    assert "Invalid field size" in msgs[0]