blob: a895940a9fe2dce8171f8f2ea5c191b4356aba39 [file] [log] [blame]
Scott Bakeracb2bf62019-03-15 10:20:35 -07001#!/usr/bin/env python
2
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from __future__ import absolute_import, print_function
18
19import requests
20import sys
21
22
23def matches(test, item):
24 if ">=" in test:
25 delim = ">="
26 elif ">" in test:
27 delim = ">"
28 elif "=" in test:
29 delim = "="
30 (name, value) = test.split(delim, 1)
31 if value.startswith("@"):
32 value = item[value[1:]]
33
34 if delim == ">":
35 if float(item[name]) > float(value):
36 return True
37
38 if delim == ">=":
39 if float(item[name]) >= float(value):
40 return True
41
42 if delim == "=":
43 if str(item[name]) == str(value):
44 return True
45 return False
46
47
48def main():
49 url = sys.argv[1]
50 tests = sys.argv[2:]
51
52 r = requests.get(url, auth=("admin@opencord.org", "letmein"))
53 for item in r.json()["items"]:
54 okay = True
55 for test in tests:
56 if not matches(test, item):
57 okay = False
58 if okay:
59 print("matched")
60 sys.exit(0)
61
62 print("Not Matched")
63 sys.exit(-1)
64
65
66if __name__ == "__main__":
67 main()