diff --git a/config/Dockerfiles/linchpin-tests.sh b/config/Dockerfiles/linchpin-tests.sh index af42c376c..c462456a1 100755 --- a/config/Dockerfiles/linchpin-tests.sh +++ b/config/Dockerfiles/linchpin-tests.sh @@ -11,7 +11,7 @@ TESTS_DIR="./config/Dockerfiles/tests.d" if [ -z "${PROVIDERS}" ]; then - PROVIDERS="dummy libvirt" + PROVIDERS="dummy libvirt beaker openstack" fi # this function checks the distros.exclude value within the test. diff --git a/linchpin/tests/mockdata/general/schema.json b/linchpin/tests/mockdata/general/schema.json new file mode 100644 index 000000000..1c498c478 --- /dev/null +++ b/linchpin/tests/mockdata/general/schema.json @@ -0,0 +1,139 @@ +{ + "res_defs": { + "type": "list", + "schema": { + "anyof": [{ + "type": "dict", + "schema": { + "role": { + "type": "string", + "required": true, + "allowed": ["libvirt_node"] + }, + "name": { "type": "string", "required": true }, + "vcpus": { "type": "integer", "required": true }, + "memory": { "type": "integer", "required": true }, + "count": { "type": "integer", "required": false }, + "uri": { "type": "string", "required": false }, + "driver": { + "type": "string", + "allowed": ["kvm", "qemu"], + "required": false }, + "image_src": { "type": "string", "required": false }, + "arch": { "type": "string", "required": false }, + "remote_user": { "type": "string", "required": false }, + "boot_dev": { "type": "string", "required": false }, + "additional_storage": { "type": "string", "required": false }, + "network_bridge": { "type": "string", "required": false }, + "ssh_key": { "type": "string", "required": false }, + "cloud_config": { + "type": "dict", + "required": false, + "schema": { + "virt_type": { "type": "string", "required": false }, + "run_script": { "type": "string", "required": false }, + "run_commands": { "type": "list", "required": false }, + "users": { + "type": "list", + "required": false, + "schema": { + "type": "dict", + "required": false, + "schema": { + "name": { "type": "string", "required": true }, + "gecos": { "type": "string", "required": false }, + "primary_group": { "type": "string", "required": false }, + "groups": { "type": "string", "required": false }, + "sudo": { "type": "string", "required": false }, + "passwd": { "type": "string", "required": false }, + "lock_passwd": { "type": "boolean", "required": false }, + "ssh_import_id": { "type": "string", "required": false }, + "ssh_authorized_keys": { "type": "list", "required": false }, + "inject_ssh_keys": { "type": "string", "required": false } + } + } + }, + "root_password": { "type": "string", "required": false }, + "packages": { "type": "list", "required": false } + } + }, + "networks": { + "type": "list", + "required": false, + "schema": { + "type": "dict", + "schema": { + "name": { "type": "string", "required": true }, + "ip": { "type": "string", "required": false }, + "mac": { "type": "string", "required": false } + } + } + }, + "storage": { + "type": "list", + "required": false, + "schema": { + "type": "dict", + "required": true, + "schema": { + "name": { "type": "string", "required": true }, + "size": { "type": "integer", "required": true }, + "units": { "type": "string", "required": false }, + "disk_type": { "type": "string", "required": false, + "allowed": ["virtio_blk", "virtio_scsi"] }, + "cache": { "type": "string", "required": false }, + "format": { "type": "string", "required": false }, + "shareable": { "type": "boolean", "required": false }, + "device": { "type": "string", "required": false }, + "source": { + "type": "dict", + "required": false, + "schema": { + "file": { "type": "string", "required": false }, + "block": { "type": "string", "required": false }, + "dir": { "type": "string", "required": false }, + "network_protocol": { "type": "string", "required": false, + "allowed": ["nbd", "isci", "rbd", "sheepdog", "gluster", "vxhs"]}, + "network_name": { "type": "string", "required": false }, + "volume": { "type": "string", "required": false }, + "pool": { "type": "string", "required": false } + } + } + } + } + } + } + }, + { + "type": "dict", + "schema": { + "role": { + "type": "string", + "required": true, + "allowed": ["libvirt_network"] }, + "name": { "type": "string", "required": true }, + "uri": { "type": "string", "required": false }, + "ip": { "type": "string", "required": true }, + "prefix": { "type": "string", "required": false }, + "dhcp_start": { "type": "string", "required": false }, + "dhcp_end": { "type": "string", "required": false }, + "bridge": { "type": "string", "required": false }, + "domain": { "type": "string", "required": false } + } + }, + { + "type": "dict", + "schema": { + "role": { + "type": "string", + "required": true, + "allowed": ["libvirt_storage"] }, + "name": { "type": "string", "required": true }, + "uri": { "type": "string", "required": false }, + "size": { "type": "integer", "required": true }, + "path": { "type": "integer", "required": true } + } + }] + } + } +} diff --git a/linchpin/tests/mockdata/libvirt/libvirt-new.yml b/linchpin/tests/mockdata/libvirt/libvirt-new.yml new file mode 100644 index 000000000..94b050cf2 --- /dev/null +++ b/linchpin/tests/mockdata/libvirt/libvirt-new.yml @@ -0,0 +1,26 @@ +--- +topology_name: libvirt-new +resource_groups: + - resource_group_name: libvirt-new + resource_group_type: libvirt + resource_definitions: + - role: libvirt_node + name: centos71 + uri: qemu:///system + count: 1 + image_src: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1608.qcow2.xz + memory: 2048 + vcpus: 1 + arch: x86_64 + ssh_key: libvirt + networks: + - name: default + additional_storage: 10G + cloud_config: + users: + - name: herlo + gecos: Clint Savage + groups: wheel + sudo: ALL=(ALL) NOPASSWD:ALL + ssh_import_id: gh:herlo + lock_passwd: true diff --git a/linchpin/tests/test_init_pass.py b/linchpin/tests/test_init_pass.py index 5cc3bc3e7..feeeee59d 100644 --- a/linchpin/tests/test_init_pass.py +++ b/linchpin/tests/test_init_pass.py @@ -228,6 +228,19 @@ def test_do_action(): assert not failed +@with_setup(setup_lp_api) +def test_do_validation(): + return_code, results = lpa.do_validation(provision_data) + + failed = False + if return_code: + failed = True + for target, data in results.iteritems(): + if not data.startswith("valid"): + print("Validation for target '{0}': has failed with" + " error '{1}'".format(target, msg)) + + assert not failed @with_setup(setup_lp_api) def test_lp_journal(): diff --git a/linchpin/tests/utils/test_validator_pass.py b/linchpin/tests/utils/test_validator_pass.py new file mode 100644 index 000000000..587aff532 --- /dev/null +++ b/linchpin/tests/utils/test_validator_pass.py @@ -0,0 +1,60 @@ +import os +import sys +import json +import yaml + +from nose.tools import assert_true +from nose.tools import with_setup + +from linchpin import LinchpinAPI +from linchpin.utils.dataparser import DataParser +from linchpin.context import LinchpinContext +from linchpin.rundb import RunDB + +from linchpin.utils.validator import AnyofValidator + +from linchpin.tests.mockdata.contextdata import ContextData + + +def setup_validator(): + + """ + Perform setup of AnyofValidator, definitions, field, and value + """ + + global validator + global topo + + lpc = LinchpinContext() + lpc.load_config() + lpc.load_global_evars() + lpa = LinchpinAPI(lpc) + + schema_file = 'schema.json' + base_path = '{0}'.format(os.path.dirname(os.path.realpath(__file__)))\ + .rstrip('/') + lib_path = os.path.realpath(os.path.join(base_path, os.pardir)) + sp = '{0}/{1}/{2}'.format(lib_path, 'mockdata/general', schema_file) + schema = json.load(open(sp)) + + validator = AnyofValidator(schema) + + topo_name = 'libvirt-new.yml' + topo_file = '{0}/{1}/{2}'.format(lib_path, 'mockdata/libvirt', topo_name) + topo = yaml.load(open(topo_file)) + + + +@with_setup(setup_validator) +def test_validate_anyof(): + document = { 'res_defs': topo['resource_groups'][0]['resource_definitions']} + success = validator.validate(document) + assert_true(success) + + +def main(): + pass + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/linchpin/utils/validator.py b/linchpin/utils/validator.py index ea7c1e5b7..23cf93d27 100644 --- a/linchpin/utils/validator.py +++ b/linchpin/utils/validator.py @@ -8,7 +8,6 @@ def __init__(self, *args, **kwargs): def _validate_anyof(self, definitions, field, value): """ {'type': 'list', 'logical': 'anyof'} """ - # print "definitions:", definitions if 'role' not in definitions[0]['schema'].keys(): return super(AnyofValidator, self)._validate_anyof(definitions,