adding vth code as well as aaf and cert config
[it/otf.git] / otf-robot-test-head / app / utils / __init__.py
1 """ Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 #############################################################################"""\r
15 \r
16 \r
17 import os\r
18 import datetime\r
19 import json\r
20 \r
21 \r
22 def unix_time_millis(dt):\r
23     epoch = datetime.datetime.utcfromtimestamp(0)\r
24     return (dt - epoch).total_seconds() * 1000.0\r
25 \r
26 \r
27 def zip_dir(path, zip_handle):\r
28     for root, dirs, files in os.walk(path):\r
29         for f in files:\r
30             zip_handle.write(os.path.join(root, f))\r
31 \r
32 \r
33 def try_get_json_value(key, data):\r
34     if key not in data:\r
35         raise KeyError('The key {key} is not in {data}.'\r
36                        .format(key=key, data=json.dumps(data)))\r
37 \r
38     return data[key]\r
39 \r
40 \r
41 def resolve_robot_status_code(code):\r
42     resolved_message = 'Invalid robot status code.'\r
43 \r
44     if code == 0:\r
45         resolved_message = 'All critical tests passed.'\r
46     elif 0 <= code <= 249:\r
47         resolved_message = '{numTestsFailed} test(s) failed.'.format(numTestsFailed=code)\r
48     elif code == 250:\r
49         resolved_message = '250 or more critical failures.'\r
50     elif code == 251:\r
51         resolved_message = 'Help or version information printed.'\r
52     elif code == 252:\r
53         resolved_message = 'Invalid test data or command line options.'\r
54     elif code == 253:\r
55         resolved_message = 'Test execution stopped by user.'\r
56     elif code == 255:\r
57         resolved_message = 'Unexpected internal error.'\r
58 \r
59     return resolved_message\r
60 \r
61 \r
62 \r