c0325d334f40ec611abae63847b935bc46da5fd6
[integration/test.git] / csit / libraries / SettingsLibrary.py
1 from string import Template
2
3 # helps in taking the hostname entered by the user
4 # global hostname
5 # global port
6
7 __author__ = "Basheeruddin Ahmed"
8 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
9 __license__ = "New-style BSD"
10 __email__ = "syedbahm@cisco.com"
11
12
13 # def setHostname(host):
14 #     hostname=host
15
16 # def getServer():
17 #     return hostname +":"+"8080"
18
19
20 def getCarsUrl(hostname, port):
21     """Cars resource URL for GET"""
22     return "http://" + hostname + ":" + port + "/rests/data/car:cars"
23
24
25 def getPersonsUrl(hostname, port):
26     """People resouce URL for GET"""
27     return "http://" + hostname + ":" + port + "/rests/data/people:people"
28
29
30 def getCarPersonUrl(hostname, port):
31     """GET cars persons mapping resource URL"""
32     return "http://" + hostname + ":" + port + "/rests/data/car-people:car-people"
33
34
35 def getAddCarInitUrl(hostname, port):
36     """POST or DELETE URL"""
37     return "http://" + hostname + ":" + port + "/rests/data"
38
39
40 def getAddCarUrl(hostname, port):
41     """POST or DELETE URL"""
42     return "http://" + hostname + ":" + port + "/rests/data/car:cars"
43
44
45 def getAddPersonUrl(hostname, port):
46     """POST or DELETE URL"""
47     return "http://" + hostname + ":" + port + "/rests/data"
48
49
50 def getAddPersonRpcUrl(hostname, port):
51     """POST URL -using rpc"""
52     return "http://" + hostname + ":" + port + "/rests/operations/people:add-person"
53
54
55 def getAddCarPersonUrl(hostname, port):
56     """POST URL for car person mapping"""
57     return "http://" + hostname + ":" + port + "/rests/data"
58
59
60 def getBuyCarRpcUrl(hostname, port):
61     """POST URL for buy car rpc"""
62     return "http://" + hostname + ":" + port + "/rests/operations/car-purchase:buy-car"
63
64
65 def getJolokiaURL(hostname, port, shardIndex, shardName):
66     """GET URL for jolokia"""
67     return (
68         "http://"
69         + hostname
70         + ":"
71         + port
72         + "/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-"
73         + shardIndex
74         + "-"
75         + shardName
76         + ",type=DistributedConfigDatastore"
77     )
78
79
80 # Template for Car init resource payload
81 add_car_init_payload_template = Template(
82     """
83     {"car:cars":{
84         "car-entry": [
85             {
86                 "id": "$id",
87                 "category": "$category",
88                 "model": "$model",
89                 "manufacturer": "$manufacturer",
90                 "year": "$year"
91             }
92         ]
93     }}
94     """
95 )
96
97 # Template for Car resource payload
98 add_car_payload_template = Template(
99     """
100         {"car-entry": [
101             {
102                 "id": "$id",
103                 "category": "$category",
104                 "model": "$model",
105                 "manufacturer": "$manufacturer",
106                 "year": "$year"
107             }
108         ]
109     }
110     """
111 )
112
113 # Template for Person resource payload
114 add_person_payload_template = Template(
115     """
116     {"people:people":{
117         "person": [
118             {
119                 "id": "$personId",
120                 "gender": "$gender",
121                 "age": "$age",
122                 "address": "$address",
123                 "contactNo":"$contactNo"
124             }
125         ]
126     }}
127     """
128 )
129
130 # Template for Car Person mapping  payload
131 add_car_person_template = Template(
132     """
133     {"car-people:car-people":{
134         "car-person": [
135             {
136                 "car-id": "$Id",
137                 "person-id": "$personId"
138             }
139         ]
140     }}
141     """
142 )
143
144 # Template for adding person using RPC
145 add_person_rpc_payload_template = Template(
146     """
147     {
148         "input":
149             {
150                 "people:id" : "$personId",
151                 "people:gender":"$gender",
152                 "people:address" : "$address",
153                 "people:contactNo":"$contactNo",
154                 "people:age":"$age"
155             }
156     }
157     """
158 )
159
160 # Template for buing car rpc
161 buy_car_rpc_template = Template(
162     """
163     {
164         "input" :
165         {
166             "car-purchase:person" : "/people:people/people:person[people:id='$personId']",
167             "car-purchase:person-id" : "$personId",
168             "car-purchase:car-id" : "$carId"
169         }
170     }
171     """
172 )