forked from CentOS-PaaS-SIG/linchpin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CentOS-PaaS-SIG#688 from 14rcole/validate-unit-tests
- Loading branch information
Showing
6 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} | ||
}] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters