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