ITM Testcases to Create, Delete and Get Tunnels 61/46461/8
authorAbbas Pareedkunju <abbas.pareedkunju@tcs.com>
Tue, 4 Oct 2016 11:22:16 +0000 (16:52 +0530)
committerJamo Luhrsen <jluhrsen@redhat.com>
Wed, 12 Oct 2016 18:00:15 +0000 (18:00 +0000)
Change-Id: I42852903471c3d9c43aba1c435bae549a3901d85
Signed-off-by: Abbas Pareedkunju <abbas.pareedkunju@tcs.com>
csit/libraries/OVSDB.robot
csit/libraries/VpnOperations.robot
csit/suites/openstack/vpnservice/basic_vpnservice.robot
csit/variables/vpnservice/itm_tunnel_create.json [new file with mode: 0644]

index 32a3d2360f12f96d2b5b4771e002ab5c3205b94b..016997e732a91785cd23d5f59586bb97585ae596 100644 (file)
@@ -144,3 +144,25 @@ Add Multiple Managers to OVS
     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${controller_index}
     ${ovsdb_uuid}=    Wait Until Keyword Succeeds    30s    2s    Get OVSDB UUID    controller_http_session=${session}
     [Return]    ${ovsdb_uuid}
+
+Get DPID
+    [Arguments]    ${ip}
+    [Documentation]    Returns the dpnid from the system at the given ip address using ovs-ofctl assuming br-int is present.
+    ${output} =    Run Command On Remote System    ${ip}    sudo ovs-ofctl show -O Openflow13 br-int | head -1 | awk -F "dpid:" '{print $2}'
+    ${dpnid} =    Convert To Integer    ${output}    16
+    Log    ${dpnid}
+    [Return]    ${dpnid}
+
+Get Ethernet Adapter
+    [Arguments]    ${ip}
+    [Documentation]    Returns the ethernet adapter name from the system at the given ip address using ip addr show.
+    ${adapter} =    Run Command On Remote System    ${ip}    /usr/sbin/ip addr show | grep ${ip} | cut -d " " -f 11
+    Log    ${adapter}
+    [Return]    ${adapter}
+
+Get Default Gateway
+    [Arguments]    ${ip}
+    [Documentation]    Returns the default gateway at the given ip address using route command.
+    ${gateway} =    Run Command On Remote System    ${ip}    /usr/sbin/route -n | grep '^0.0.0.0' | cut -d " " -f 10
+    Log    ${gateway}
+    [Return]    ${gateway}
index fd8fb8f1e98672b5ffd5a0e9ce0894c6d6d4969e..10fee2c8f69a9105d726c04b9eee953adbf46daf 100644 (file)
@@ -4,6 +4,7 @@ Library           SSHLibrary
 Resource          Utils.robot
 Library           Collections
 Library           String
+Library           OperatingSystem
 Variables         ../variables/Variables.py
 
 *** Variables ***
@@ -19,6 +20,18 @@ ${CREATE_EXPORT_RT_DEFAULT}    ["3300:1","8800:1"]
 ${CREATE_IMPORT_RT_DEFAULT}    ["3300:1","8800:1"]
 ${CREATE_TENANT_ID_DEFAULT}    "6c53df3a-3456-11e5-a151-feff819cdc9f"
 ${VPN_CONFIG_DIR}    ${CURDIR}/../variables/vpnservice
+${ITM_CREATE_JSON}    itm_tunnel_create.json
+${itm_prefix_def}    "1.1.1.1/24"
+${itm_vlan-id_def}    0
+${itm_dpn-id1_def}    1
+${itm_portname1_def}    "BR1-eth1"
+${itm_ip-address1_def}    "2.2.2.2"
+${itm_dpn-id2_def}    2
+${itm_portname2_def}    "BR2-eth1"
+${itm_ip-address2_def}    "3.3.3.3"
+${itm_gateway-ip_def}    "0.0.0.0"
+${itm_tunnel-type_def}    vxlan
+${itm_zone-name_def}    TZA
 
 *** Keywords ***
 VPN Create L3VPN
@@ -106,3 +119,55 @@ VPN Delete L3VPN
     ${resp} =    RequestsLibrary.Post Request    session    ${REST_CON_OP}neutronvpn:deleteL3VPN    ${body1}
     Log    ${resp.content}
     Should Be Equal As Strings    ${resp.status_code}    ${CREATE_RESP_CODE}
+
+ITM Create Tunnel
+    [Arguments]    &{Kwargs}
+    [Documentation]    Creates Tunnel between the two DPNs
+    @{KeysList}    Create List    prefix    vlan-id    dpn-id1    portname1    ip-address1
+    ...    dpn-id2    portname2    ip-address2    gateway-ip    tunnel-type    zone-name
+    Log    Arguments Received:${Kwargs}
+    ${json_body} =    OperatingSystem.Get File    ${VPN_CONFIG_DIR}/${ITM_CREATE_JSON}
+    Run Keyword If    ${Kwargs}    Log    ${Kwargs}
+    Log    json_body:${json_body}
+    ${prefix} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[0]}    default=${itm_prefix_def}
+    ${json_body} =    Replace String    ${json_body}    prefix\"\:${itm_prefix_def}    prefix\"\:${prefix}
+    ${vlan-id} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[1]}    default=${itm_vlan-id_def}
+    ${json_body} =    Replace String    ${json_body}    vlan-id\"\:${itm_vlan-id_def}    vlan-id\"\:${vlan-id}
+    ${dpn-id1} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[2]}    default=${itm_dpn-id1_def}
+    ${json_body} =    Replace String    ${json_body}    dpn-id\"\:${itm_dpn-id1_def},    dpn-id\"\:${dpn-id1},
+    ${portname1} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[3]}    default=${itm_portname1_def}
+    ${json_body} =    Replace String    ${json_body}    portname\"\:${itm_portname1_def}    portname\"\:${portname1}
+    ${ip-address1} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[4]}    default=${itm_ip-address1_def}
+    ${json_body} =    Replace String    ${json_body}    ip-address\"\:${itm_ip-address1_def}    ip-address\"\:${ip-address1}
+    ${dpn-id2} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[5]}    default=${itm_dpn-id2_def}
+    ${json_body} =    Replace String    ${json_body}    dpn-id\"\:${itm_dpn-id2_def},    dpn-id\"\:${dpn-id2},
+    ${portname2} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[6]}    default=${itm_portname2_def}
+    ${json_body} =    Replace String    ${json_body}    portname\"\:${itm_portname2_def}    portname\"\:${portname2}
+    ${ip-address2} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[7]}    default=${itm_ip-address2_def}
+    ${json_body} =    Replace String    ${json_body}    ip-address\"\:${itm_ip-address2_def}    ip-address\"\:${ip-address2}
+    ${gateway-ip} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[8]}    default=${itm_gateway-ip_def}
+    ${json_body} =    Replace String    ${json_body}    gateway-ip\"\:${itm_gateway-ip_def}    gateway-ip\"\:${gateway-ip}
+    ${tunnel-type} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[9]}    default=${itm_tunnel-type_def}
+    ${json_body} =    Replace String    ${json_body}    \:tunnel-type-${itm_tunnel-type_def}    \:tunnel-type-${tunnel-type}
+    ${zone-name} =    Run Keyword If    ${Kwargs} != None    Pop From Dictionary    ${Kwargs}    ${KeysList[10]}    default=${itm_zone-name_def}
+    ${json_body} =    Replace String    ${json_body}    \"zone-name\":\"${itm_zone-name_def}    \"zone-name\":\"${zone-name}
+    Log    ${json_body}
+    ${resp} =    RequestsLibrary.Post Request    session    ${REST_CON}/itm:transport-zones/    data=${json_body}
+    Log    ${resp.content}
+    Log    ${resp.status_code}
+    Should Be Equal As Strings    ${resp.status_code}    204
+
+ITM Get Tunnels
+    [Documentation]    Get all Tunnels and return the contents
+    ${resp} =    RequestsLibrary.Get Request    session    ${REST_CON}itm:transport-zones/
+    Log    ${resp.content}
+    Should Be Equal As Strings    ${resp.status_code}    200
+    [Return]    ${resp.content}
+
+ITM Delete Tunnel
+    [Arguments]    ${zone-name}
+    [Documentation]    Delete Tunnels created under the transport-zone
+    ${resp} =    RequestsLibrary.Delete Request    session    ${REST_CON}/itm:transport-zones/transport-zone/${zone-name}/
+    Log    ${resp.content}
+    Should Be Equal As Strings    ${resp.status_code}    200
+    [Return]    ${resp.content}
index a5756e96f62f7c03ef93ea95356b813b64a386d4..32c93bb4dec8bc8665003bd1b785f52db31d01e4 100644 (file)
@@ -12,6 +12,7 @@ Resource          ../../../libraries/Utils.robot
 Resource          ../../../libraries/OpenStackOperations.robot
 Resource          ../../../libraries/DevstackUtils.robot
 Resource          ../../../libraries/VpnOperations.robot
+Resource          ../../../libraries/OVSDB.robot
 Variables         ../../../variables/Variables.py
 
 *** Variables ***
@@ -32,11 +33,23 @@ ${CREATE_TENANT_ID}    "6c53df3a-3456-11e5-a151-feff819c1111"
 @{VPN_INSTANCE_NAME}    4ae8cd92-48ca-49b5-94e1-b2921a2661c7    4ae8cd92-48ca-49b5-94e1-b2921a261111
 
 *** Test Cases ***
-Verify Tunnel Creation
-    [Documentation]    Checks that vxlan tunnels have been created properly.
-    [Tags]    exclude
-    Log    This test case is currently a noop, but work can be added here to validate if needed.    However, as the    suite Documentation notes, it's already assumed that the environment has been configured properly.    If    we do add work in this test case, we need to remove the "exclude" tag for it to run.    In fact, if this
-    ...    test case is critical to run, and if it fails we would be dead in the water for the rest of the suite,    we should move it to Suite Setup so that nothing else will run and waste time in a broken environment.
+Create ITM Tunnel
+    [Documentation]    Checks that vxlan tunnels are created successfully. The proc expects that the two DPNs are in the same network and populates the gateway accordingly.
+    ${node_1_dpid} =    Get DPID    ${OS_COMPUTE_1_IP}
+    ${node_2_dpid} =    Get DPID    ${OS_COMPUTE_2_IP}
+    ${node_1_adapter} =    Get Ethernet Adapter    ${OS_COMPUTE_1_IP}
+    ${node_2_adapter} =    Get Ethernet Adapter    ${OS_COMPUTE_2_IP}
+    ${first_two_octets}    ${third_octet}    ${last_octet}=    Split String From Right    ${OS_COMPUTE_1_IP}    .    2
+    ${subnet} =    Set Variable    ${first_two_octets}.0.0/16
+    ${gateway} =    Get Default Gateway    ${OS_COMPUTE_1_IP}
+    ITM Create Tunnel    tunnel-type=vxlan    vlan-id=0    ip-address1="${OS_COMPUTE_1_IP}"    dpn-id1=${node_1_dpid}    portname1="${node_1_adapter}"    ip-address2="${OS_COMPUTE_2_IP}"
+    ...    dpn-id2=${node_2_dpid}    portname2="${node_2_adapter}"    prefix="${subnet}"    gateway-ip="${gateway}"
+    ${output}=    Run Command On Remote System    ${OS_COMPUTE_1_IP}    sudo ovs-vsctl show
+    Log    ${output}
+    ${output}=    Run Command On Remote System    ${OS_COMPUTE_2_IP}    sudo ovs-vsctl show
+    Log    ${output}
+    ${output} =    ITM Get Tunnels
+    Log    ${output}
 
 Create Neutron Networks
     [Documentation]    Create two networks
@@ -167,6 +180,10 @@ Delete Networks
     : FOR    ${Network}    IN    @{NETWORKS}
     \    Delete Network    ${Network}
 
+Delete ITM Tunnel
+    [Documentation]    Delete tunnels with specific transport-zone.
+    ITM Delete Tunnel    TZA
+
 *** Keywords ***
 Basic Vpnservice Suite Setup
     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
diff --git a/csit/variables/vpnservice/itm_tunnel_create.json b/csit/variables/vpnservice/itm_tunnel_create.json
new file mode 100644 (file)
index 0000000..6c806b5
--- /dev/null
@@ -0,0 +1,27 @@
+{
+   "transport-zone":[
+      {
+         "zone-name":"TZA",
+         "subnets":[
+            {
+               "prefix":"1.1.1.1/24",
+               "vlan-id":0,
+               "vteps":[
+                  {
+                     "dpn-id":1,
+                     "portname":"BR1-eth1",
+                     "ip-address":"2.2.2.2"
+                  },
+                  {
+                     "dpn-id":2,
+                     "portname":"BR2-eth1",
+                     "ip-address":"3.3.3.3"
+                  }
+               ],
+               "gateway-ip":"0.0.0.0"
+            }
+         ],
+         "tunnel-type":"odl-interface:tunnel-type-vxlan"
+      }
+   ]
+}