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