Fix bgpcep-1node-throughpcep
[integration/test.git] / csit / libraries / IoTDM / riotdm.py
1 import iotdm
2
3 application = iotdm.application
4 container = iotdm.container
5 contentInstance = iotdm.contentInstance
6
7
8 def connect_to_iotdm(host, user, pw, p):
9     return iotdm.connect(host, base="InCSE1", auth=(user, pw), protocol=p)
10
11
12 def create_resource(connection, parent, restype, a=None):
13     restype = int(restype)
14     if a is None:
15         x = connection.create(parent, restype)
16     else:
17         x = connection.create(parent, restype, attr=a)
18     if x is None:
19         raise AssertionError("Cannot create this resource")
20     elif hasattr(x, "status_code"):
21         if x.status_code < 200 or x.status_code > 299:
22             raise AssertionError(
23                 "Cannot create this resource [%d] : %s" % (x.status_code, x.text)
24             )
25     return x
26
27
28 # this might not be necessary now that the library functions can take dicts
29
30
31 def create_subscription(connection, parent, ip, port):
32     uri = "http://%s:%d" % (ip, int(port))
33     x = connection.create(
34         parent,
35         "subscription",
36         {"notificationURI": uri, "notificationContentType": "wholeResource"},
37     )
38     if x is None:
39         raise AssertionError("Cannot create this subscription")
40     elif hasattr(x, "status_code"):
41         if x.status_code < 200 or x.status_code > 299:
42             raise AssertionError(
43                 "Cannot create subscription [%d] : %s" % (x.status_code, x.text)
44             )
45     return x
46
47
48 def retrieve_resource(connection, resid):
49     x = connection.retrieve(resid)
50     if x is None:
51         raise AssertionError("Cannot retrieve this resource")
52     elif hasattr(x, "status_code"):
53         if x.status_code < 200 or x.status_code > 299:
54             raise AssertionError(
55                 "Cannot retrieve this resource [%d] : %s" % (x.status_code, x.text)
56             )
57     return x
58
59
60 def update_resource(connection, resid, attr):
61     x = connection.update(resid, attr)
62     if x is None:
63         raise AssertionError("Cannot update this resource")
64     elif hasattr(x, "status_code"):
65         if x.status_code < 200 or x.status_code > 299:
66             raise AssertionError(
67                 "Cannot update this resource [%d] : %s" % (x.status_code, x.text)
68             )
69     return x
70
71
72 def delete_resource(connection, resid):
73     x = connection.delete(resid)
74     if x is None:
75         raise AssertionError("Cannot delete this resource")
76     elif hasattr(x, "status_code"):
77         if x.status_code < 200 or x.status_code > 299:
78             raise AssertionError(
79                 "Cannot delete this resource [%d] : %s" % (x.status_code, x.text)
80             )
81     return x
82
83
84 def text(x):
85     return x.text
86
87
88 def status_code(x):
89     return x.status_code
90
91
92 def json(x):
93     return x.json()
94
95
96 def elapsed(x):
97     return x.elapsed.total_seconds()