05695e8dfc935dc57a7702969ac96ede8ab5b8ea
[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=${ctrlip}    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     Run Keyword If    '${vbrname}' == 'Vbr_audit'    Should Be Equal As Strings    ${resp.status_code}    202
136     ...    ELSE     Should Be Equal As Strings    ${resp.status_code}    201
137
138 Create VBRIF in VBR
139     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${ifdescription}    ${retcode}
140     [Documentation]    Create VBR Interface in VBR
141     ${vbrifinfo}    Create Dictionary    if_name=${vbrifname}    description=${ifdescription}
142     ${vbrifcreate}    Create Dictionary    interface=${vbrifinfo}
143     ${vbrifcreate_json}=    json.dumps    ${vbrifcreate}
144     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS_CREATE}    data=${vbrifcreate_json}
145     Should Be Equal As Strings    ${resp.status_code}    ${retcode}
146
147 Define Portmap for VBRIF
148     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${logical_port_id}
149     [Documentation]    Map Interface to a logical port
150     ${logical_port_info}    Create Dictionary    logical_port_id=${logical_port_id}
151     ${portmapdefine}    Create Dictionary    portmap=${logical_port_info}
152     ${portmapdefine_json}=    json.dumps    ${portmapdefine}
153     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${PORTMAP_CREATE}    data=${portmapdefine_json}
154     Should Be Equal As Strings    ${resp.status_code}    204
155
156 Add a FLOWLIST
157     [Arguments]    ${flowlistname}    ${ipversion}
158     [Documentation]    Create FLOWLIST in Coordinator
159     ${flowlistinfo}    Create Dictionary    fl_name=${flowlistname}    ip_version=${ipversion}
160     ${flowlistcreate}    Create Dictionary    flowlist=${flowlistinfo}
161     ${flowlistcreate_json}=    json.dumps    ${flowlistcreate}
162     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS_CREATE}    data=${flowlistcreate_json}
163     Should Be Equal As Strings    ${resp.status_code}    201
164
165 Create FLOWLISTENTRY
166     [Arguments]    ${flowlistname}
167     [Documentation]    Create Flowlistentry for Coordinator
168     ${flowlistentryinfo}    Create Dictionary    seqnum=233    macethertype=0x800    ipdstaddr=10.0.0.1    ipdstaddrprefix=32    ipsrcaddr=10.0.0.3
169     ...    ipsrcaddrprefix=32    ipproto=1
170     ${flowlistentrycreate}    Create Dictionary    flowlistentry=${flowlistentryinfo}
171     ${flowlistentrycreate_json}=    json.dumps    ${flowlistentrycreate}
172     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}/${FLOWLISTENTRIES_CREATE}    data=${flowlistentrycreate_json}
173     Should Be Equal As Strings    ${resp.status_code}    201
174
175 Create FLOWLISTENTRY_ANY in FLOWLIST
176     [Arguments]    ${flowlistname}
177     [Documentation]    Create Flowlistentry_any for Coordinator
178     ${flowlistentryinfo}    Create Dictionary    seqnum=1
179     ${flowlistentrycreate}    Create Dictionary    flowlistentry=${flowlistentryinfo}
180     ${flowlistentrycreate_json}=    json.dumps    ${flowlistentrycreate}
181     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}/${FLOWLISTENTRIES_CREATE}    data=${flowlistentrycreate_json}
182     Should Be Equal As Strings    ${resp.status_code}    201
183
184 Create VBRIF in FLOWFILTER
185     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${ff_type}
186     [Documentation]    create vbridge interface flowfilter
187     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
188     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
189     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
190     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
191     Should Be Equal As Strings    ${resp.status_code}    201
192
193 Create FLOWFILTERENTRY DROP In VBRIFFLOWFILTER
194     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${actiontype}
195     [Documentation]    create domonstration with pass actiontype
196     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
197     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
198     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
199     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
200     Should Be Equal As Strings    ${resp.status_code}    201
201
202 Create FLOWFILTERENTRY PASS In VBRIFFLOWFILTER
203     [Arguments]    ${vtnname}    ${vbrname}    ${vbrifname}    ${actiontype}    ${seqnum}
204     [Documentation]    create domonstration with pass actiontype
205     ${flowfilterentryinfo}    Create Dictionary    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
206     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
207     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
208     ${resp}    RequestsLibrary.Put    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VBRIFS}/${vbrifname}/${FLOWFILTERS}/${FLOWFILTERS_UPDATE}/${seqnum}    data=${flowfilterentrycreate_json}
209     Should Be Equal As Strings    ${resp.status_code}    204
210
211 Create FLOWFILTER in VBR
212     [Arguments]    ${vtnname}    ${vbrname}    ${ff_type}
213     [Documentation]    create vtn flowfilter
214     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
215     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
216     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
217     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
218     Should Be Equal As Strings    ${resp.status_code}    201
219
220 Create FLOWFILTERENTRY PASS in VBRFLOWFILTER
221     [Arguments]    ${vtnname}    ${vbrname}    ${actiontype}
222     [Documentation]    create domonstration with pass actiontype
223     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
224     ${flowfilterentryinfo_1}    Create Dictionary    vnode_name=${vbrname}    fl_name=Flowlist1    direction=in
225     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
226     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
227     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
228     Should Be Equal As Strings    ${resp.status_code}    201
229
230 Create FLOWFILTER in VTN
231     [Arguments]    ${vtnname}    ${ff_type}
232     [Documentation]    create vtn flowfilter
233     ${flowfilters_info}    Create Dictionary    ff_type=${ff_type}
234     ${flowfiltersdefine}    Create Dictionary    flowfilter=${flowfilters_info}
235     ${flowfiltersdefine_json}=    json.dumps    ${flowfiltersdefine}
236     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${FLOWFILTERS_CREATE}    data=${flowfiltersdefine_json}
237     Should Be Equal As Strings    ${resp.status_code}    201
238
239 Create FLOWFILTERENTRY PASS in VTNFLOWFILTER
240     [Arguments]    ${vtnname}    ${actiontype}
241     [Documentation]    create domonstration with pass actiontype
242     ${flowfilterentryinfo}    Create Dictionary    seqnum=233    fl_name=Flowlist1    action_type=${actiontype}    priority=3    dscp=55
243     ${flowfilterentrycreate}    Create Dictionary    flowfilterentry=${flowfilterentryinfo}
244     ${flowfilterentrycreate_json}=    json.dumps    ${flowfilterentrycreate}
245     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${FLOWFILTERS}/${FLOWFILTERENTRIES_CREATE}    data=${flowfilterentrycreate_json}
246     Should Be Equal As Strings    ${resp.status_code}    201
247
248 Create VLANMAP in VBRIDGE
249     [Arguments]    ${vtnname}    ${vbrname}    ${vlanid}
250     [Documentation]    Create VLANMAP for VBRIDGE in Coordinator
251     ${vlaninfo}    Create Dictionary    vlan_id=${vlanid}
252     ${vlancreate}    Create Dictionary    vlanmap=${vlaninfo}
253     ${vlancreate_json}=    json.dumps    ${vlancreate}
254     ${resp}    RequestsLibrary.Post    session    ${VTNWEBAPI}/${VTNS}/${vtnname}/${VBRS}/${vbrname}/${VLANMAP_CREATE }    data=${vlancreate_json}
255     Should Be Equal As Strings    ${resp.status_code}    201
256
257 Start vlan_topo
258     [Documentation]    This will start mininet with custom topology on both the Virtual Machines
259     Start Mininet    ${MININET}    ${vlan_topo}    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
260
261 Delete a FLOWLIST
262     [Arguments]    ${flowlistname}
263     [Documentation]    Delete a Flowlist
264     ${resp}    RequestsLibrary.Delete    session    ${VTNWEBAPI}/${FLOWLISTS}/${flowlistname}.json
265     Should Be Equal As Strings    ${resp.status_code}    204
266
267 Test Ping
268     [Arguments]    ${host1}    ${host2}
269     [Documentation]    Ping hosts to check connectivity
270     Write    ${host1} ping -c 1 ${host2}
271     ${result}    Read Until    mininet>
272     Should Contain    ${result}    64 bytes
273
274 Verify Switch
275     [Arguments]    ${ctrlname}    ${switch_id}
276     [Documentation]    Get switch
277     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}/${SW}/${switch_id}.json
278     ${contents}    To JSON    ${resp.content}
279     ${switchblock}    Get From Dictionary    ${contents}    switch
280     ${status}    Get From Dictionary    ${switchblock}    switch_id
281     Should Be Equal As Strings    ${status}    ${switch_id}
282
283 Verify SwitchPort
284     [Arguments]    ${ctrlname}    ${switch_id}
285     [Documentation]    Get switch
286     ${resp}    RequestsLibrary.Get    session    ${VTNWEBAPI}/${CTRLS}/${ctrlname}/${SW}/${switch_id}/${PORTS}
287     Should Be Equal As Strings    ${resp.status_code}    200