9ec9a48651d695aab26c3551423dcdaa6f07275c
[integration/test.git] / csit / libraries / VtnCoKeywords.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Library           String
4 Library           DateTime
5 Library           RequestsLibrary
6 Library           json
7 Library           SSHLibrary
8 Library           Collections
9 Library           XML
10 Variables         ../variables/Variables.py
11 Resource          ./Utils.robot
12
13 *** variable ***
14 ${vlan_topo}      sudo mn --controller=remote,ip=${CONTROLLER} --custom vlan_vtn_test.py --topo vlantopo
15
16 *** Keywords ***
17 Get VtnCo
18     [Documentation]    Download the VTN Coordinator from Controller VM
19     Log    Download the VTN Coordinator bz2 file
20     SSHLibrary.Open_Connection    ${CONTROLLER}
21     SSHLibrary.Login_With_Public_Key    ${CONTROLLER_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
22     ${VTNC_FILENAME}=    Catenate    SEPARATOR=/    ${WORKSPACE}    vtn_coordinator.tar.bz2
23     SSHLibrary.Get_File    ${WORKSPACE}/${BUNDLEFOLDER}/externalapps/*vtn-coordinator*-bin.tar.bz2    ${VTNC_FILENAME}
24     SSHLibrary.Close_Connection
25     SSHLibrary.Open_Connection    ${MININET}
26     SSHLibrary.Login_With_Public_Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
27     SSHLibrary.Put_File    ${VTNC_FILENAME}    /tmp
28     SSHLibrary.Close_Connection
29
30 Start SuiteVtnCo
31     [Documentation]    Download and startup the VTN Coordinator.
32     Log    Start the VTN Coordinator
33     #Get VtnCo
34     ${vtnc_conn_id}=    SSHLibrary.Open Connection    ${CONTROLLER}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
35     Set Suite Variable    ${vtnc_conn_id}
36     SSHLibrary.Login_With_Public_Key    ${CONTROLLER_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
37     SSHLibrary.Execute Command    sudo mkdir -p /usr/local/vtn
38     SSHLibrary.Execute Command    sudo chown jenkins /usr/local/vtn
39     SSHLibrary.Execute Command    sudo yum install -q -y http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-1.noarch.rpm
40     SSHLibrary.Execute Command    sudo yum install -q -y postgresql93-libs postgresql93 postgresql93-server postgresql93-contrib postgresql93-odbc
41     SSHLibrary.Execute Command    tar -C/ -jxvf ${WORKSPACE}/${BUNDLEFOLDER}/externalapps/*vtn-coordinator*-bin.tar.bz2
42     SSHLibrary.Execute Command    /usr/local/vtn/sbin/db_setup
43     SSHLibrary.Execute Command    /usr/local/vtn/bin/vtn_start
44     SSHLibrary.Execute Command    /usr/local/vtn/bin/unc_dmctl status
45     SSHLibrary.Execute Command    /usr/local/vtn/sbin/db_setup
46     SSHLibrary.Execute Command    sed -i 's/odcdrv_ping_interval = 30/odcdrv_ping_interval = 10/g' /usr/local/vtn/modules/odcdriver.conf
47     SSHLibrary.Execute Command    sed -i 's/physical_attributes_read_interval = 40/physical_attributes_read_interval = 15/g' /usr/local/vtn/modules/vtndrvintf.conf
48     SSHLibrary.Execute Command    /usr/local/vtn/bin/vtn_start
49     SSHLibrary.Execute Command    /usr/local/vtn/bin/unc_dmctl status
50     SSHLibrary.Execute Command    /usr/local/vtn/bin/drvodc_control loglevel trace
51     SSHLibrary.Execute Command    /usr/local/vtn/bin/lgcnw_control loglevel trace
52     SSHLibrary.Execute Command    exit
53
54 Stop SuiteVtnCo
55     [Documentation]    Exit the Launch Test
56     Log    Stop the Launch Test
57
58 Start SuiteVtnCoTest
59     [Documentation]    Start the VTNCo Test
60     Create Session    session    http://${CONTROLLER}:8083    headers=${VTNC_HEADERS}
61
62 Stop SuiteVtnCoTest
63     [Documentation]    Exit the VtnCo Test
64     Delete All Sessions
65
66 Get Coordinator Version
67     [Documentation]    Get API version for testing
68     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/api_version
69     Should Be Equal As Strings    ${resp.status_code}    200
70
71 Add a Controller
72     [Arguments]    ${ctrlname}    ${ctrlip}
73     [Documentation]    Create a controller
74     ${controllerinfo}    Create Dictionary    controller_id=${ctrlname}    type=odc    ipaddr=${CONTROLLER}    version=1.0
75     ${controllercreate}    Create Dictionary    controller=${controllerinfo}
76     ${controllercreate_json}=    json.dumps    ${controllercreate}
77     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${CTRLS_CREATE}    data=${controllercreate_json}
78     Should Be Equal As Strings    ${resp.status_code}    201
79
80 Remove Controller
81     [Arguments]    ${ctrlname}
82     [Documentation]    Delete a Controller
83     ${resp}    RequestsLibrary.Delete    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}.json
84     Should Be Equal As Strings    ${resp.status_code}    204
85
86 Update Controller
87     [Arguments]    ${ctrlname}    ${ctrlip}    ${desc}
88     [Documentation]    Update controller
89     ${controllerinfo}    Create Dictionary    description=${desc}    ipaddr=${ctrlip}    version=1.0
90     ${controllerupdate}    Create Dictionary    controller=${controllerinfo}
91     ${controllerupdate_json}=    json.dumps    ${controllerupdate}
92     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}.json    data=${controllerupdate_json}
93     Should Be Equal As Strings    ${resp.status_code}    204
94
95 Audit Controller
96     [Arguments]    ${ctrlname}
97     [Documentation]    Trigger Manual Audit
98     ${auditinfo}    Create Dictionary    force=false    real-network_audit=false
99     ${auditupdate}    Create Dictionary    audit=${auditinfo}
100     ${auditupdate_json}=    json.dumps    ${auditupdate}
101     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}/audit.json    data=${auditupdate_json}
102     Should Be Equal As Strings    ${resp.status_code}    204
103
104 Check Controller Status
105     [Arguments]    ${ctrlname}    ${stat}
106     [Documentation]    Get controller status
107     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}.json
108     ${contents}    To JSON    ${resp.content}
109     ${controllerblock}    Get From Dictionary    ${contents}    controller
110     ${status}    Get From Dictionary    ${controllerblock}    operstatus
111     Should Be Equal As Strings    ${status}    ${stat}
112
113 Add a VTN
114     [Arguments]    ${vtnname}    ${vtndescription}
115     [Documentation]    Create VTN in Coordinator
116     ${vtninfo}    Create Dictionary    vtn_name=${vtnname}    description=${vtndescription}
117     ${vtncreate}    Create Dictionary    vtn=${vtninfo}
118     ${vtncreate_json}=    json.dumps    ${vtncreate}
119     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS_CREATE}    data=${vtncreate_json}
120     Should Be Equal As Strings    ${resp.status_code}    201
121
122 Delete a VTN
123     [Arguments]    ${vtnname}
124     [Documentation]    Delete a VTN Created
125     ${resp}    RequestsLibrary.Delete    session    ${VTNWEBAPI}/${VTNS}/${vtnname}.json
126     Should Be Equal As Strings    ${resp.status_code}    204
127
128 Create VBR in VTN
129     [Arguments]    ${vtnname}    ${vbrname}    ${ctrlname}
130     [Documentation]    Create VBR for VTN in Coordinator
131     ${vbrinfo}    Create Dictionary    vbr_name=${vbrname}    controller_id=${ctrlname}    domain_id=(DEFAULT)
132     ${vbrcreate}    Create Dictionary    vbridge=${vbrinfo}
133     ${vbrcreate_json}=    json.dumps    ${vbrcreate}
134     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS_CREATE}    data=${vbrcreate_json}
135     Should Be Equal As Strings    ${resp.status_code}    201
136
137 Create VBRIF in VBR
138     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${ifdescription}    ${retcode}
139     [Documentation]    Create VBR Interface in VBR
140     ${vbrifinfo}    Create Dictionary    if_name=${vbrifname}    description=${ifdescription}
141     ${vbrifcreate}    Create Dictionary    interface=${vbrifinfo}
142     ${vbrifcreate_json}=    json.dumps    ${vbrifcreate}
143     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS_CREATE}    data=${vbrifcreate_json}
144     Should Be Equal As Strings    ${resp.status_code}    ${retcode}
145
146 Define Portmap for VBRIF
147     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${logical_port_id}
148     [Documentation]    Map Interface to a logical port
149     ${logical_port_info}    Create Dictionary    logical_port_id=${logical_port_id}
150     ${portmapdefine}    Create Dictionary    portmap=${logical_port_info}
151     ${portmapdefine_json}=    json.dumps    ${portmapdefine}
152     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${PORTMAP_CREATE}    data=${portmapdefine_json}
153     Should Be Equal As Strings    ${resp.status_code}    204
154
155 Add a FLOWLIST
156     [Arguments]    ${flowlistname}    ${ipversion}
157     [Documentation]    Create FLOWLIST in Coordinator
158     ${flowlistinfo}    Create Dictionary    fl_name=${flowlistname}    ip_version=${ipversion}
159     ${flowlistcreate}    Create Dictionary    flowlist=${flowlistinfo}
160     ${flowlistcreate_json}=    json.dumps    ${flowlistcreate}
161     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS_CREATE}    data=${flowlistcreate_json}
162     Should Be Equal As Strings    ${resp.status_code}    201
163
164 Create FLOWLISTENTRY
165     [Arguments]    ${flowlistname}
166     [Documentation]    Create Flowlistentry for Coordinator
167     ${flowlistentryinfo}    Create Dictionary    seqnum=233    macethertype=0x800    ipdstaddr=10.0.0.1    ipdstaddrprefix=32    ipsrcaddr=10.0.0.3
168     ...    ipsrcaddrprefix=32    ipproto=1
169     ${flowlistentrycreate}    Create Dictionary    flowlistentry=${flowlistentryinfo}
170     ${flowlistentrycreate_json}=    json.dumps    ${flowlistentrycreate}
171     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}/${FLOWLISTENTRIES_CREATE}    data=${flowlistentrycreate_json}
172     Should Be Equal As Strings    ${resp.status_code}    201
173
174 Create FLOWLISTENTRY_ANY in FLOWLIST
175     [Arguments]    ${flowlistname}
176     [Documentation]    Create Flowlistentry_any for Coordinator
177     ${flowlistentryinfo}    Create Dictionary    seqnum=1
178     ${flowlistentrycreate}    Create Dictionary    flowlistentry=${flowlistentryinfo}
179     ${flowlistentrycreate_json}=    json.dumps    ${flowlistentrycreate}
180     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}/${FLOWLISTENTRIES_CREATE}    data=${flowlistentrycreate_json}
181     Should Be Equal As Strings    ${resp.status_code}    201
182
183 Create VBRIF in FLOWFILTER
184     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${ff_type}
185     [Documentation]    create vbridge interface flowfilter
186     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
187     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
188     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
189     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
190     Should Be Equal As Strings    ${resp.status_code}    201
191
192 Create FLOWFILTERENTRY DROP In VBRIFFLOWFILTER
193     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${actiontype}
194     [Documentation]    create domonstration with pass actiontype
195     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
196     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
197     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
198     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
199     Should Be Equal As Strings    ${resp.status_code}    201
200
201 Create FLOWFILTERENTRY PASS In VBRIFFLOWFILTER
202     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${actiontype}    ${seqnum}
203     [Documentation]    create domonstration with pass actiontype
204     ${flowfilterentryinfo}    Create Dictionary    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
205     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
206     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
207     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS}/${FLOWFILTERS_UPDATE}/${seqnum}    data=${flowfilterentrycreate_json}
208     Should Be Equal As Strings    ${resp.status_code}    204
209
210 Create FLOWFILTER in VBR
211     [Arguments]    ${vtnname}    ${vbrname}    ${ff_type}
212     [Documentation]    create vtn flowfilter
213     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
214     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
215     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
216     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
217     Should Be Equal As Strings    ${resp.status_code}    201
218
219 Create FLOWFILTERENTRY PASS in VBRFLOWFILTER
220     [Arguments]    ${vtnname}    ${vbrname}    ${actiontype}
221     [Documentation]    create domonstration with pass actiontype
222     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
223     ${flowfilterentryinfo_1}    Create Dictionary    vnode_name=${vbrname}    fl_name=Flowlist1    direction=in
224     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
225     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
226     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
227     Should Be Equal As Strings    ${resp.status_code}    201
228
229 Create FLOWFILTER in VTN
230     [Arguments]    ${vtnname}    ${ff_type}
231     [Documentation]    create vtn flowfilter
232     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
233     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
234     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
235     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
236     Should Be Equal As Strings    ${resp.status_code}    201
237
238 Create FLOWFILTERENTRY PASS in VTNFLOWFILTER
239     [Arguments]    ${vtnname}    ${actiontype}
240     [Documentation]    create domonstration with pass actiontype
241     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
242     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
243     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
244     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
245     Should Be Equal As Strings    ${resp.status_code}    201
246
247 Create VLANMAP in VBRIDGE
248     [Arguments]    ${vtnname}    ${vbrname}    ${vlanid}
249     [Documentation]    Create VLANMAP for VBRIDGE in Coordinator
250     ${vlaninfo}    Create Dictionary    vlan_id=${vlanid}
251     ${vlancreate}    Create Dictionary    vlanmap=${vlaninfo}
252     ${vlancreate_json}=    json.dumps    ${vlancreate}
253     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VLANMAP_CREATE }    data=${vlancreate_json}
254     Should Be Equal As Strings    ${resp.status_code}    201
255
256 Start vlan_topo
257     [Documentation]    This will start mininet with custom topology on both the Virtual Machines
258     Start Mininet    ${MININET}    ${vlan_topo}    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
259
260 Delete a FLOWLIST
261     [Arguments]    ${flowlistname}
262     [Documentation]    Delete a Flowlist
263     ${resp}    RequestsLibrary.Delete    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}.json
264     Should Be Equal As Strings    ${resp.status_code}    204
265
266 Test Ping
267     [Arguments]    ${host1}    ${host2}
268     [Documentation]    Ping hosts to check connectivity
269     Write    ${host1} ping -c 4 ${host2}
270     ${result}    Read Until    mininet>
271     Should Contain    ${result}    64 bytes
272
273 Verify Switch
274     [Arguments]    ${ctrlname}    ${switch_id}
275     [Documentation]    Get switch
276     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}/${SW}/${switch_id}.json
277     ${contents}    To JSON    ${resp.content}
278     ${switchblock}    Get From Dictionary    ${contents}    switch
279     ${status}    Get From Dictionary    ${switchblock}    switch_id
280     Should Be Equal As Strings    ${status}    ${switch_id}
281
282 Verify SwitchPort
283     [Arguments]    ${ctrlname}    ${switch_id}
284     [Documentation]    Get switch
285     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}/${SW}/${switch_id}/${PORTS}
286     Should Be Equal As Strings    ${resp.status_code}    200