bug fixing
[integration/test.git] / test / tools / OF_Test / robot_suites / 500__OF_Cluster_Sanity_OF / SanityLibrary.py
1 import json
2
3
4 class SanityLibrary:
5
6     def get_flow_content(self, tid=1, fid=1, priority=1):
7
8         flow_template = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
9 <flow xmlns="urn:opendaylight:flow:inventory">
10     <strict>false</strict>
11     <instructions>
12         <instruction>
13             <order>0</order>
14             <apply-actions>
15                 <action>
16                     <order>0</order>
17                     <drop-action/>
18                 </action>
19             </apply-actions>
20         </instruction>
21     </instructions>
22     <table_id>%s</table_id>
23     <id>%s</id>
24     <cookie_mask>4294967295</cookie_mask>
25     <installHw>false</installHw>
26     <match>
27         <ethernet-match>
28             <ethernet-type>
29                 <type>2048</type>
30             </ethernet-type>
31         </ethernet-match>
32         <ipv4-source>10.0.0.1</ipv4-source>
33     </match>
34     <cookie>%s</cookie>
35     <flow-name>%s</flow-name>
36     <priority>%s</priority>
37     <barrier>false</barrier>
38 </flow>'''
39
40         flow_data = flow_template % (tid, fid, fid, 'TestFlow-{0}'.format(fid), priority)
41         return flow_data
42
43     def is_cluter_set_up(self, rsp1, rsp2, rsp3):
44         try:
45             states = []
46             for r in [rsp1, rsp2, rsp3]:
47                 rj = json.loads(r)
48                 states.append(rj['value']['RaftState'])
49                 states.sort()
50             if states == ['Follower', 'Follower', 'Leader']:
51                 return True
52         except Exception:
53             return False
54         return False
55
56     def get_persistence(self, rsp):
57         try:
58             rj = json.loads(rsp)
59             return rj['module'][0]['distributed-datastore-provider:config-properties']['persistent']
60         except:
61             pass
62