コード例 #1
0
 def test_cli_validation_function_integrity_ko_dext(self):
     validator = Validator()
     input_args = ['--integrity', '--function',
                   SAMPLE_DIR + 'samples/functions/invalid_integrity-son/',
                   '--dext', 'yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 3)
コード例 #2
0
 def test_cli_validation_service_syntax_nonexistent_descriptor(self):
     validator = Validator()
     input_args = ['--syntax', '--service',
                   SAMPLE_DIR + 'samples/services/invalid-syntax-tng/' +
                   'unexpected_field.yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 1)
コード例 #3
0
 def test_cli_validation_service_syntax_ko_required_properties(self):
     validator = Validator()
     input_args = ['--syntax', '--service',
                   SAMPLE_DIR + 'samples/services/invalid-syntax-tng/' +
                   'required_properties.yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 1)
コード例 #4
0
 def test_cli_validation_function_syntax_ko_bad_syntax(self):
     validator = Validator()
     input_args = ['--syntax', '--function',
                   SAMPLE_DIR + 'samples/functions/invalid-syntax-tng/' +
                   'invalid-firewall-vnfd-tng.yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 1)
コード例 #5
0
 def test_cli_validation_function_syntax_ok_dext(self):
     validator = Validator()
     input_args = ['--syntax', '--function',
                   SAMPLE_DIR + 'samples/functions/valid-syntax-tng/',
                   '--dext', 'yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 0)
コード例 #6
0
 def test_cli_validation_function_topology_ok(self):
     validator = Validator()
     input_args = ['--topology', '--function',
                   SAMPLE_DIR + 'samples/functions/valid-son/' +
                   'firewall-vnfd.yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 0)
コード例 #7
0
 def test_cli_validation_service_integrity_ok(self):
     validator = Validator()
     input_args = ['--integrity', '--service',
                   SAMPLE_DIR + 'samples/services/valid-son/valid.yml',
                   '--dpath', SAMPLE_DIR + 'samples/functions/valid-son/',
                   '--dext', 'yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(result_validator.error_count, 0)
コード例 #8
0
 def test_cli_validation_function_custom_ko(self):
     validator = Validator()
     input_args = ['--custom', '--cfile',
                   SAMPLE_DIR + 'samples/custom_rules/rules/' +
                   'custom_rule_1.yml', '--function',
                   SAMPLE_DIR + 'samples/custom_rules/functions/' +
                   'invalid/function_1_ko.yml']
     args = cli.parse_args(input_args)
     print("Test arguments: {}".format(args))
     check_args = cli.check_args(args)
     self.assertTrue(check_args)
     result_validator = cli.dispatch(args, validator)
     self.assertEqual(len(result_validator.customErrors), 4)
コード例 #9
0
    def test_validate_function_valid(self):
        """
        Tests the validation of a valid 5GTANGO function.
        """
        functions_path = os.path.join(SAMPLES_DIR, 'functions', 'valid-son')
        validator = Validator()
        validator.configure(syntax=True, integrity=True, topology=True)
        validator.validate_function(functions_path)

        self.assertEqual(validator.error_count, 0)
        self.assertEqual(validator.warning_count, 0)
コード例 #10
0
    def test_validate_function_integrity_invalid(self):
        """
        Tests the incorrect validation of a function integrity.
        """
        functions_path = os.path.join(SAMPLES_DIR, 'functions',
                                      'invalid_integrity-son')
        validator = Validator()
        validator.configure(syntax=True, integrity=True, topology=False)
        validator.validate_function(functions_path)

        self.assertEqual(validator.error_count, 3)
        self.assertEqual(validator.warning_count, 0)
コード例 #11
0
    def test_validate_service_syntax_valid_simplest_nsd(self):
        """
        Tests the correct validation of a service syntax simplest nsd
        """
        service_path = os.path.join(SAMPLES_DIR, 'services',
                                    'valid-syntax-tng', 'simplest-example.yml')

        validator = Validator()
        validator.configure(syntax=True, integrity=False, topology=False)
        validator.validate_service(service_path)

        self.assertEqual(validator.error_count, 0)
        self.assertEqual(validator.warning_count, 0)
コード例 #12
0
    def test_validate_service_syntax_invalid_required_properties(self):
        """
        Tests the incorrect validation of a service syntax with \
        required field in the nsd
        """
        service_path = os.path.join(SAMPLES_DIR, 'services',
                                    'invalid-syntax-tng',
                                    'required_properties.yml')

        validator = Validator()
        validator.configure(syntax=True, integrity=False, topology=False)
        validator.validate_service(service_path)

        self.assertEqual(validator.error_count, 1)
        self.assertEqual(validator.warning_count, 0)
コード例 #13
0
    def test_validate_service_syntax_nonexistent_descriptor(self):
        """
        Tests the incorrect validation of a service syntax with \
        a unexpected field in the nsd
        """
        service_path = os.path.join(SAMPLES_DIR, 'services',
                                    'invalid-syntax-tng',
                                    'unexpected_field.yml')

        validator = Validator()
        validator.configure(syntax=True, integrity=False, topology=False)
        validator.validate_service(service_path)

        self.assertEqual(validator.error_count, 1)
        self.assertEqual(validator.warning_count, 0)
コード例 #14
0
def validate_project_with_external_validator(args, project_path):
    """
    Try to use an external validator (typically tng-sdk-validation)
    to validate the given service project.
    Throws TangoValidationException on validation error.
    """
    # check if external validator is available?
    try:
        from tngsdk.validation import cli as v_cli
        from tngsdk.validation.validator import Validator
    except BaseException as ex:
        LOG.error("Skipping validation: tng-sdk-validate not installed?")
        LOG.debug(ex)
        return
    # ok! let us valiade ...
    v = Validator()
    # define validation_level
    if len(args.validation_level) == 1:
        validation_level = "-" + args.validation_level
    else:
        validation_level = "--" + args.validation_level
    # define arguments for validator
    v_args = v_cli.parse_args([
        validation_level,  # levels -s / -i / -t
        "--debug",  # temporary
        "--project",
        project_path,  # path to project
        "--workspace",
        args.workspace  # workspace path
    ])
    v_cli.dispatch(v_args, v)
    # check validation result
    # - warnings
    if v.warning_count > 0:
        LOG.warning("There have been {} tng-validate warnings".format(
            v.warning_count))
        LOG.warning("tng-validate warnings: '{}'".format(v.warnings))
    # - errors
    if v.error_count > 0:
        raise TangoValidationException("tng-validate error(s): '{}'".format(
            v.errors))
コード例 #15
0
    def test_validate_service_topology_valid(self):
        """
        Tests the correct validation of a service topology
        """
        service_path = os.path.join(SAMPLES_DIR, 'services', 'valid-son',
                                    'valid.yml')
        functions_path = os.path.join(SAMPLES_DIR, 'functions', 'valid-son')
        validator = Validator()
        validator.configure(syntax=True,
                            integrity=True,
                            topology=True,
                            dpath=functions_path)
        validator.validate_service(service_path)

        self.assertEqual(validator.error_count, 0)
        self.assertEqual(validator.warning_count, 0)
コード例 #16
0
ファイル: validator.py プロジェクト: panstav1/tng-sdk-package
def validate_project_with_external_validator(args, project_path):
    """
    Try to use an external validator (typically tng-sdk-validation)
    to validate the given service project.
    Throws TangoValidationException on validation error.
    """
    # shall we validate?
    if args.skip_validation:
        LOG.warning("Skipping validation upon user request (--no-validation).")
        return
    # check if external validator is available?
    try:
        from tngsdk.validation import cli as v_cli
        from tngsdk.validation.validator import Validator
    except BaseException as ex:
        del ex
        LOG.error("Skipping validation: tng-sdk-validate not installed?")
        return
    # ok! let us valiade ...
    v = Validator()
    # define arguments for validator
    v_args = v_cli.parse_args([
        # levels -s / -i / -t
        "-s",  # TODO  change to -i if CNF are supported by validator
        "--project",
        project_path,  # path to project
        "--workspace",
        args.workspace  # workspace path
    ])
    v_cli.dispatch(v_args, v)
    # check validation result
    # - warnings
    if v.warning_count > 0:
        LOG.warning("There have been {} tng-validate warnings".format(
            v.warning_count))
        LOG.warning("tng-validate warnings: '{}'".format(v.warnings))
    # - errors
    if v.error_count > 0:
        raise TangoValidationException("tng-validate error(s): '{}'".format(
            v.errors))