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