(two tiny cleanups and re-triggering the patch tests now that all the 503
[integration.git] / test / csit / libraries / FlowLib.py
1 """
2 Library for dynamic flow construction.
3 Authors: james.luhrsen@hp.com
4 Updated: 2014-08-29
5 """
6 '''
7 xmltodict and json libs not needed at this point, but may be useful in
8 the future.
9 '''
10 ##import xmltodict
11 ##import json
12 import string
13 import robot
14 from robot.libraries.BuiltIn import BuiltIn
15
16 ##bare bones xml for building a flow xml for flow:inventory
17 flow_xml_skeleton = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +      \
18                '<flow xmlns="urn:opendaylight:flow:inventory">'         +      \
19                     '<instructions></instructions>'                     +      \
20                     '<match></match>'                                   +      \
21                '</flow>'
22
23 input_xml_skeleton = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +      \
24                '<input xmlns="urn:opendaylight:flow:service">'          +      \
25                '</input>'
26
27
28 class Flow:
29     '''
30     Flow class for creating and interacting with OpenFlow flows
31     '''
32
33     strict = "false"
34     instruction_xmls = ""
35     match_xmls = ""
36     cookie = 0
37     cookie_mask = 0
38     table_id = 0
39     id = 1
40     hard_timeout = 60
41     idle_timeout = 30
42     flow_name = "No Name"
43     priority = 0
44     barrier = "false"
45
46     xml = ""
47
48     json = ""
49
50     def set_field(self, field, value):
51         '''
52            allows for generically setting any attribute in this
53            class based on the 'field' passed in.  In the future,
54            adding a new attribute only requires that single line
55            addition.  no need for additional setter.
56         '''
57         setattr(self, field, value)
58
59 def Make_Inventory_Flow():
60     '''
61         Robot Keyword to create and return an instance of the Flow
62         class.
63     '''
64     flow = Flow()
65     flow.xml = flow_xml_skeleton
66     return flow
67
68 def Make_Service_Flow():
69     '''
70         Robot Keyword to create an input XML that can be used to
71         directly send to flow:service for things like accessing
72         the remove-flow RPC via restconf
73     '''
74     flow = Flow()
75     flow.xml = input_xml_skeleton
76     return flow
77
78 def Set_Flow_Field(flow, field, value):
79     '''
80         Robot Keyword to allow the modification (setting) of the 
81         flow object attributes
82     '''
83     flow.set_field(field,value)
84     return flow
85
86
87 #def Convert_Flow_XML_To_Json(flow):
88 #    '''
89 #       There may be a need in the future to use json to push
90 #       flows, as opposed to xml format that is prevalent in 
91 #       test code at this point.  This function will give a 
92 #       conversion, but unsure if it's proper.  Also, unsure
93 #       if the xmltodict library is viable in the CSIT environment
94 #    '''
95 #    flowXmlDict = xmltodict.parse(flow.xml)
96 #    flow.json = json.dumps(flowXmlDict)
97 #    return flow