65f94233ea6188cf42bde50be5113fb38fd85e3b
[integration/test.git] / csit / libraries / VpnOperations.robot
1 *** Settings ***
2 Documentation     Openstack library. This library is useful for tests to create network, subnet, router and vm instances
3 Library           SSHLibrary
4 Resource          Utils.robot
5 Resource          TemplatedRequests.robot
6 Resource          ../variables/Variables.robot
7 Library           Collections
8 Library           String
9 Library           OperatingSystem
10
11 *** Variables ***
12 &{ITM_CREATE_DEFAULT}    tunneltype=vxlan    vlanid=0    prefix=1.1.1.1/24    gateway=0.0.0.0    dpnid1=1    portname1=BR1-eth1    ipaddress1=2.2.2.2
13 ...               dpnid2=2    portname2= BR2-eth1    ipaddress2=3.3.3.3
14 &{L3VPN_CREATE_DEFAULT}    vpnid=4ae8cd92-48ca-49b5-94e1-b2921a261111    name=vpn1    rd=["2200:1"]    exportrt=["2200:1","8800:1"]    importrt=["2200:1","8800:1"]    tenantid=6c53df3a-3456-11e5-a151-feff819cdc9f
15 ${VAR_BASE}       ${CURDIR}/../variables/vpnservice/
16 ${ODL_FLOWTABLE_L3VPN}    21
17
18 *** Keywords ***
19 VPN Create L3VPN
20     [Arguments]    &{Kwargs}
21     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
22     Run keyword if    "routerid" in ${Kwargs}    Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
23     ...    ELSE    Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
24     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
25     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
26     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_create    mapping=${L3vpn_create_actual_val}    session=session
27
28 VPN Get L3VPN
29     [Arguments]    &{Kwargs}
30     [Documentation]    Will return detailed list of the L3VPN_ID received
31     ${resp} =    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/get_l3vpn    mapping=${Kwargs}    session=session
32     Log    ${resp}
33     [Return]    ${resp}
34
35 Associate L3VPN To Network
36     [Arguments]    &{Kwargs}
37     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
38     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_l3vpn    mapping=${Kwargs}    session=session
39
40 Dissociate L3VPN From Networks
41     [Arguments]    &{Kwargs}
42     [Documentation]    Disssociate the already associated networks from L3VPN
43     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_l3vpn    mapping=${Kwargs}    session=session
44
45 Associate VPN to Router
46     [Arguments]    &{Kwargs}
47     [Documentation]    Associate the created L3VPN to a router-id received as argument
48     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_router_l3vpn    mapping=${Kwargs}    session=session
49
50 Dissociate VPN to Router
51     [Arguments]    &{Kwargs}
52     [Documentation]    Dissociate the already associated routers from L3VPN
53     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_router_l3vpn    mapping=${Kwargs}    session=session
54
55 VPN Delete L3VPN
56     [Arguments]    &{Kwargs}
57     [Documentation]    Delete the created L3VPN
58     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_delete    mapping=${Kwargs}    session=session
59
60 ITM Create Tunnel
61     [Arguments]    &{Kwargs}
62     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
63     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
64     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
65     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/itm_create    mapping=${Itm_actual_val}    session=session
66
67 ITM Get Tunnels
68     [Documentation]    Get all Tunnels and return the contents
69     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
70     Log    ${resp.content}
71     Should Be Equal As Strings    ${resp.status_code}    200
72     [Return]    ${resp.content}
73
74 ITM Delete Tunnel
75     [Arguments]    ${zone-name}
76     [Documentation]    Delete Tunnels created under the transport-zone
77     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
78     Log    ${resp.content}
79     Should Be Equal As Strings    ${resp.status_code}    200
80     [Return]    ${resp.content}
81
82 Verify Flows Are Present For L3VPN
83     [Arguments]    ${ip}    ${vm_ips}
84     [Documentation]    Verify Flows Are Present For L3VPN
85     ${flow_output}=    Run Command On Remote System    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
86     Log    ${flow_output}
87     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
88     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
89     Log    ${l3vpn_table}
90     : FOR    ${i}    IN    @{vm_ips}
91     \    ${resp}=    Should Contain    ${l3vpn_table}    ${i}
92
93 Verify Tunnel Status as UP
94     [Documentation]    Verify that the tunnels are UP
95     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
96     Log    ${output}
97     Should Contain    ${output}    ${STATE_UP}
98     Should Not Contain    ${output}    ${STATE_DOWN}
99
100 Verify Tunnel Status as DOWN
101     [Documentation]    Verify that the tunnels are DOWN
102     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
103     Log    ${output}
104     Should Contain    ${output}    ${STATE_DOWN}
105
106 Verify VXLAN interface
107     [Documentation]    Verify that the VXLAN interfaces are Enabled
108     ${output}=    Issue Command On Karaf Console    ${VXLAN_SHOW}
109     Log    ${output}
110     Should Contain    ${output}    ${STATE_UP}
111     Should Contain    ${output}    ${STATE_ENABLE}
112     Should Not Contain    ${output}    ${STATE_DISABLE}