defusedxml,
glob2,
jenkins,
+ jsonschema,
pytest,
six,
shade,
license
nexus
openstack
+ schema
sign
version
--- /dev/null
+******
+Schema
+******
+
+.. program-output:: lftools schema --help
+
+Commands
+========
+
+verify
+-------
+
+.. program-output:: lftools schema verify --help
from lftools.cli.jenkins import jenkins_cli
from lftools.cli.license import license
from lftools.cli.nexus import nexus
+from lftools.cli.schema import schema
from lftools.cli.sign import sign
from lftools.cli.version import version
cli.add_command(jenkins_cli, name='jenkins')
cli.add_command(license)
cli.add_command(nexus)
+cli.add_command(schema)
cli.add_command(sign)
cli.add_command(version)
--- /dev/null
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Verify YAML Schema."""
+
+from __future__ import print_function
+
+import click
+
+from lftools.schema import check_schema_file
+
+
+@click.group()
+@click.pass_context
+def schema(ctx):
+ """Verify YAML Schema."""
+ pass
+
+
+@click.command(name='verify')
+@click.argument('yamlfile')
+@click.argument('schemafile')
+@click.pass_context
+def verify_schema(ctx, yamlfile, schemafile):
+ """Verify YAML Schema.
+
+ YAMLFILE: Release YAML file to be validated.
+
+ SCHEMAFILE: SCHEMA file to validate against.
+ """
+ check_schema_file(yamlfile, schemafile)
+
+
+schema.add_command(verify_schema)
--- /dev/null
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Verify YAML Schema."""
+
+from __future__ import print_function
+
+import logging
+
+import jsonschema
+import yaml
+
+
+def check_schema_file(yamlfile, schemafile):
+ """Verify YAML Schema.
+
+ YAMLFILE: Release YAML file to be validated.
+
+ SCHEMAFILE: SCHEMA file to validate against.
+ """
+ with open(yamlfile) as _:
+ yaml_file = yaml.safe_load(_)
+
+ with open(schemafile) as _:
+ schema_file = yaml.safe_load(_)
+
+ # Load the schema
+ validation = jsonschema.Draft4Validator(
+ schema_file,
+ format_checker=jsonschema.FormatChecker()
+ )
+
+ validation.iter_errors(yaml_file)
+ # Look for errors
+ errors = 0
+ for error in validation.iter_errors(yaml_file):
+ errors += 1
+ logging.error(error)
+ if errors > 0:
+ raise RuntimeError("{:d} issues invalidate the release schema".format(errors))
--- /dev/null
+---
+features:
+ - |
+ Verify YAML Schema.
+
+ Usage: Usage: lftools schema verify [OPTIONS] YAMLFILE SCHEMAFILE
+
+ .. code-block:: none
+
+ Commands:
+ verify a yaml file based on a schema file.
+
+ .. code-block:: none
+
+ Options:
+ --help Show this message and exit.
glob2 # Needed for Python < 3.5 recursive glob support
deb-pkg-tools~=5.2
defusedxml # Needed due to tox complains on parseString not safe
+jsonschema~=2.6.0
pyyaml
requests~=2.18.0
rpmfile~=0.1.4
--- /dev/null
+# SPDX-License-Identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+project: ipv6
+project-type: feature
+release-model: stable
+foo: bar
+
+releases:
+ - version: opnfv-7.0.0
+ location:
+ ipv6: c0e6ae3d1d443f96f0ab50e417f9ad740669b890
+ - version: opnfv-7.1.0
+ location:
+ ipv6: 7978c6172432174ea6027922524b476783516f56
+
+branches:
+ - name: stable/gambia
+ location:
+ ipv6: e36f753cf6e9ab0c02a400b6bac5c79b48268d44
+
+release-notes: https://opnfv-ipv6.readthedocs.io/en/stable-gambia/release/release-notes/
--- /dev/null
+# SPDX-License-Identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+project: ipv6
+project-type: feature
+release-model: stable
+foo: bar
+
+releases:
+ - version: opnfv-7.0.0
+ location:
+ ipv6: c0e6ae3d1d443f96f0ab50e417f9ad740669b890
+ - version: opnfv-7.1.0
+ location:
+ ipv6: 7978c6172432174ea6027922524b476783516f56
+
+branches:
+ - name: stable/gambia
+ location:
+ ipv6: e36f753cf6e9ab0c02a400b6bac5c79b48268d44
+
+release-notes: https://opnfv-ipv6.readthedocs.io/en/stable-gambia/release/release-notes/
--- /dev/null
+# SPDX-License-Identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+project: ipv6
+project-type: feature
+release-model: stable
+
+releases:
+ - version: opnfv-7.0.0
+ location:
+ ipv6: c0e6ae3d1d443f96f0ab50e417f9ad740669b890
+ - version: opnfv-7.1.0
+ location:
+ ipv6: 7978c6172432174ea6027922524b476783516f56
+
+branches:
+ - name: stable/gambia
+ location:
+ ipv6: e36f753cf6e9ab0c02a400b6bac5c79b48268d44
+
+release-notes: https://opnfv-ipv6.readthedocs.io/en/stable-gambia/release/release-notes/
--- /dev/null
+##############################################################################
+# Copyright (c) 2019 Linux Foundation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+$schema: 'http://json-schema.org/schema#'
+$id: 'https://github.com/opnfv/releng/blob/master/releases/schema.yaml'
+
+additionalProperties: false
+
+required:
+ - 'project'
+ - 'project-type'
+
+properties:
+ project:
+ type: 'string'
+ release-model:
+ type: 'string'
+ enum: ['stable', 'non-release']
+ project-type:
+ type: 'string'
+ enum: ['installer', 'testing', 'feature', 'tools', 'infra']
+ upstream:
+ type: 'string'
+ releases:
+ type: 'array'
+ items:
+ type: 'object'
+ properties:
+ version:
+ type: 'string'
+ # Matches semantic versioning (X.Y.Z)
+ pattern: '^opnfv-([0-9]+\.){2}[0-9]+$'
+ location:
+ type: 'object'
+ required: ['version', 'location']
+ additionalProperties: false
+ branches:
+ type: 'array'
+ items:
+ type: 'object'
+ properties:
+ name:
+ type: 'string'
+ pattern: '^stable/[a-z]+$'
+ location:
+ type: 'object'
+ required: ['name', 'location']
+ additionalProperties: false
+ release-notes:
+ type: 'string'
+ format: 'uri'
--- /dev/null
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Test license command."""
+
+import os
+
+import pytest
+
+from lftools import cli
+
+FIXTURE_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ 'fixtures',
+ )
+
+
+@pytest.mark.datafiles(
+ os.path.join(FIXTURE_DIR, 'schema'),
+ )
+def test_check_license(cli_runner, datafiles):
+ """Test check_schema() command."""
+ os.chdir(str(datafiles))
+
+ # Check that schema passes when schema and yaml are valid.
+ result = cli_runner.invoke(cli.cli, ['schema', 'verify', 'release.yaml', 'schema.yaml'], obj={})
+ # noqa: B101 .
+ assert result.exit_code == 0
+
+ # Check that schema fails when schema and yaml are invalid.
+ result = cli_runner.invoke(cli.cli, ['schema', 'verify', 'release-broken.yaml', 'schema.yaml'], obj={})
+ # noqa: B101 .
+ assert result.exit_code == 1