-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cerberus.py
91 lines (86 loc) · 2.44 KB
/
test_cerberus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from cerberus import Validator
"""
action_block :: sample ::
- name: manipulate_inventory
type: shell
path: /tmp/shellscripts
actions:
- thisisshell.sh
"""
schema= {
'name': {'type': 'string', 'required': True },
'type': { 'type': 'string', 'allowed': ['shell', 'subprocess']},
'path': {'type': 'string', 'required': False},
'actions': { 'type': 'list', 'schema': {'type': 'string'}, 'required': True}
}
v = Validator(schema)
doc1 = {
'name': 'manuplate_inven',
'type': 'shell',
'path': '/tmp/sompath',
'actions': [
'thisisshell.sh',
'echo "helloworld" "hello too"',
]
}
doc2 = {
'name': 'manuplate_inven',
'type': 'shellidd',
'path': '/tmp/sompath',
'actions': [
'thisisshell.sh',
{}
]
}
print(v.validate(doc1))
print(v.errors)
print(v.validate(doc2))
print(v.errors)
"""
ansible schema hook schema:
- name: build_openshift_cluster
type: ansible
actions:
- playbook: test_playbook.yaml
vars: test_var.yaml
extra_vars: { "testvar": "world"}
"""
print("### Ansible schema ###")
schema= {
'name': {'type': 'string', 'required': True },
'type': { 'type': 'string', 'allowed': ['ansible']},
'path': {'type': 'string', 'required': False},
'actions': { 'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'playbook': {'type': 'string', 'required': True},
'vars': {'type': 'string', 'required': False},
'extra_vars': {'type': 'dict', 'required': False}
}
},
'required': True
}
}
doc1 = {
'name': 'build_openshift_cluster',
'type': 'ansible',
'actions': [
{
'playbook': 'test',
# 'vars': 'test',
# 'extra_vars': {}
},
{
'playbook': 'test',
# 'vars': 'test',
'extra_vars': {
'1': '2',
'2': '3'
}
}
]
}
v = Validator(schema)
print(v.validate(doc1))
print(v.errors)