Motr  M0
validator.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # For any questions about this software or licensing,
17 # please email opensource@seagate.com or cortx-questions@seagate.com.
18 #
19 
20 from cerberus import Validator
21 
23  schema_s3 = {
24  'common': {
25  'type': 'dict',
26  'schema': {
27  'version' : {'type': 'integer', 'allowed': [ 1 ] },
28  'description': {'required': False, 'nullable': True},
29  'priority' : {'type': 'integer', 'min': 1},
30  'batch_id' : {'required': False, 'nullable': True},
31  'type' : {'type': 'string', 'allowed' : ['s3client', 's3corrupt']},
32  'timeout' : {'required': False, 'type': 'string', 'regex': '[0-9]+(d|h|m|s)'},
33  'user' : {'type': 'string', 'regex': '.*@seagate\.com'},
34  'send_email' : {'type': 'boolean'},
35  'nodes' : {'type': 'list',
36  'schema': {
37  'type' : 'dict',
38  'schema': {
39  'srv' : {'type' : 'string', 'nullable': True},
40  'cli' : {'type' : 'string', 'nullable': True}
41  }
42  }
43  }
44  }
45  },
46  'workload': {
47  'type' : 'list',
48  'schema': {
49  'type' : 'dict',
50  'schema': {
51  'app' : {'type' : 'string', 'allowed': ['s3bench', 'sleep', 'exit']},
52  'param': {'type': 'dict',
53  'schema': {
54  'cli_options': {'type' : 'string'}
55  }
56  }
57  }
58  }
59  },
60  's3server' : {
61  'type' : 'dict',
62  'schema' : {
63  'git' : {'oneof': [{'allowed' : ['dev']},
64  {'type' : 'string', 'regex' : '^[0-9a-f]{7,40}$'},
65  {'type' : 'integer', 'min': 1000000, 'max': 9999999}]},
66  'num_instances' : {'type' : 'integer', 'min' : 1},
67  'cmd_line_options' : {'type' : 'string', 'nullable': True},
68  'config_overrides' : {'type' : 'dict', 'nullable' : True}
69  }
70  },
71  'ha' : {'type' : 'string', 'allowed' : ['halon', 'hare']},
72  'motr' : {
73  'type' : 'dict',
74  'schema' : {
75  'git' : {'oneof': [{'allowed' : ['dev']},
76  {'type' : 'string', 'regex' : '^[0-9a-f]{7,40}$'},
77  {'type' : 'integer', 'min': 1000000, 'max': 9999999}]},
78  'build_options' : {'type' : 'string', 'nullable' : True},
79  'config_overrides' : {'type' : 'dict', 'nullable' : True}
80  }
81  },
82  'execution_options' : {
83  'type' : 'dict',
84  'schema' : {
85  'no_motr_trace' : {'type' : 'boolean'},
86  'no_m0trace_files' : {'type' : 'boolean'},
87  'no_m0trace_dumps' : {'type' : 'boolean'},
88  'no_addb_stobs' : {'type' : 'boolean'},
89  'no_addb_dumps' : {'type' : 'boolean'},
90  'no_m0play_db' : {'type' : 'boolean'}
91  }
92  }
93  }
94 
95  return schema_s3
96 
98  schema_motr = {
99  'common': {
100  'type': 'dict',
101  'schema': {
102  'version' : {'type': 'integer', 'allowed': [ 1 ] },
103  'description': {'required': False, 'nullable': True},
104  'priority' : {'type': 'integer', 'min': 1},
105  'batch_id' : {'required': False, 'nullable': True},
106  'user' : {'type': 'string', 'regex': '.*@seagate\.com'},
107  'type' : {'type': 'string', 'allowed' : ['m0crate', 'm0corrupt']},
108  'timeout' : {'required': False, 'type': 'string', 'regex': '[0-9]+(d|h|m|s)'},
109  'nodes' : {'type': 'list',
110  'schema': {
111  'type' : 'dict',
112  'schema': {
113  'srv' : {'type' : 'string', 'nullable': True},
114  'cli' : {'type' : 'string', 'nullable': True}
115  }
116  }
117  }
118  }
119  },
120  'workload': {
121  'type' : 'list',
122  'schema': {
123  'type' : 'dict',
124  'schema': {
125  'app' : {'type' : 'string', 'allowed': ['m0crate', 'sleep', 'exit']},
126  'param': {'type': 'dict',
127  'schema': {
128  'config_overrides' : {'type' : 'dict', 'nullable' : True, 'required': False}
129  }
130  }
131  }
132  }
133  },
134  'ha' : {'type' : 'string', 'allowed' : ['halon', 'hare']},
135  'motr' : {
136  'type' : 'dict',
137  'schema' : {
138  'git' : {'oneof': [{'allowed' : ['dev']},
139  {'type' : 'string', 'regex' : '^[0-9a-f]{7,40}$'},
140  {'type' : 'integer', 'min': 1000000, 'max': 9999999}]},
141  'build_options' : {'type' : 'string', 'nullable' : True},
142  'config_overrides' : {'type' : 'dict', 'nullable' : True}
143  }
144  },
145  'execution_options' : {
146  'type' : 'dict',
147  'schema' : {
148  'no_motr_trace' : {'type' : 'boolean'},
149  'no_m0trace_files' : {'type' : 'boolean'},
150  'no_m0trace_dumps' : {'type' : 'boolean'},
151  'no_addb_stobs' : {'type' : 'boolean'},
152  'no_addb_dumps' : {'type' : 'boolean'},
153  'no_m0play_db' : {'type' : 'boolean'}
154  }
155  }
156  }
157  return schema_motr
158 
159 def validate_config(config):
160  v = Validator(allow_unknown=True, require_all=True)
161  errors = []
162 
163  v.validate(config, get_schema_s3());
164  errors.append({"S3 requirements" : v.errors})
165 
166  v.validate(config, get_schema_motr())
167  errors.append({"Motr requirements": v.errors})
168 
169  return errors
def get_schema_s3()
Definition: validator.py:22
def validate_config(config)
Definition: validator.py:159
def get_schema_motr()
Definition: validator.py:97