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