Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / netvirt / host_route / host_route_handling.robot
1 *** Settings ***
2 Documentation     Test suite for VM based Host Route Handling
3 Suite Setup       Suite Setup
4 Suite Teardown    OpenStackOperations.OpenStack Suite Teardown
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Test Teardown     OpenStackOperations.Get Test Teardown Debugs
7 Library           Collections
8 Library           RequestsLibrary
9 Library           SSHLibrary
10 Library           String
11 Resource          ../../../libraries/DevstackUtils.robot
12 Resource          ../../../libraries/OpenStackOperations.robot
13 Resource          ../../../libraries/VpnOperations.robot
14 Resource          ../../../variables/netvirt/Variables.robot
15 Resource          ../../../variables/Variables.robot
16
17 *** Variables ***
18 @{NETWORKS}       host_route_network_1    host_route_network_2    host_route_network_3    host_route_network_4
19 @{SUBNETS}        host_route_subnet_1    host_route_subnet_2    host_route_subnet_3    host_route_subnet_4
20 @{SUBNET_CIDR}    10.10.10.0    10.20.20.0    10.30.30.0    10.40.40.0
21 ${PREFIX24}       /24
22 ${SECURITY_GROUP}    host_route_security_group
23 @{PORTS}          host_route_port_1    host_route_port_2    host_route_port_3    host_route_port_4    host_route_port_5    host_route_port_6    host_route_port_7
24 @{GATEWAY_PORTS}    host_route_gw_port_1    host_route_gw_port_2    host_route_gw_port_3    host_route_gw_port_4    host_route_gw_port_5    host_route_gw_port_6    host_route_gw_port_7
25 ${ALLOWED_ADDRESS_PAIR}    0.0.0.0/0
26 ${NETWORK_1_VM}    host_route_vm_1
27 @{NETWORK_2_VMS}    host_route_vm_2    host_route_vm_3
28 @{NETWORK_3_VMS}    host_route_vm_4    host_route_vm_5
29 @{NETWORK_4_VMS}    host_route_vm_6    host_route_vm_7
30 @{GATEWAY_VMS}    host_route_gw_vm_1    host_route_gw_vm_2
31 ${ROUTER}         host_route_router_1
32 @{NON_NEUTRON_DESTINATION}    5.5.5.0    6.6.6.0
33 ${NON_NEUTRON_NEXTHOP}    10.10.10.250
34
35 *** Test Cases ***
36 Verify creation of host route via openstack subnet create option
37     [Documentation]    Creating subnet host route via openstack cli and verifying in controller and openstack.
38     OpenStackOperations.Create SubNet    @{NETWORKS}[0]    @{SUBNETS}[0]    @{SUBNET_CIDR}[0]${PREFIX24}    --host-route destination=@{SUBNET_CIDR}[2]${PREFIX24},gateway=${NON_NEUTRON_NEXTHOP}
39     ${SUBNET_GW_IP}    BuiltIn.Create List
40     FOR    ${subnet}    IN    @{SUBNETS}
41         ${ip} =    OpenStackOperations.Get Subnet Gateway Ip    ${subnet}
42         Collections.Append To List    ${SUBNET_GW_IP}    ${ip}
43     END
44     BuiltIn.Set Suite Variable    ${SUBNET_GW_IP}
45     ${elements} =    BuiltIn.Create List    "destination":"@{SUBNET_CIDR}[2]${PREFIX24}","nexthop":"${NON_NEUTRON_NEXTHOP}"
46     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${elements}
47     Verify Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{SUBNET_CIDR}[2]${PREFIX24}',\\sgateway='${NON_NEUTRON_NEXTHOP}'
48     OpenStackOperations.Create Port    @{NETWORKS}[0]    @{PORTS}[0]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
49     OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[0]    ${NETWORK_1_VM}    ${OS_CMP1_HOSTNAME}    sg=${SECURITY_GROUP}
50     OpenStackOperations.Create Port    @{NETWORKS}[0]    @{GATEWAY_PORTS}[0]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
51     OpenStackOperations.Create Vm Instance With Ports On Compute Node    @{GATEWAY_PORTS}[0]    @{GATEWAY_PORTS}[1]    @{GATEWAY_VMS}[0]    ${OS_CMP1_HOSTNAME}    sg=${SECURITY_GROUP}
52     OpenStackOperations.Create Vm Instance With Ports On Compute Node    @{GATEWAY_PORTS}[4]    @{GATEWAY_PORTS}[5]    @{GATEWAY_VMS}[1]    ${OS_CMP2_HOSTNAME}    sg=${SECURITY_GROUP}
53     OpenStackOperations.Poll VM Is ACTIVE    ${NETWORK_1_VM}
54     BuiltIn.Wait Until Keyword Succeeds    180s    15s    OpenStackOperations.Get VM IP    true    ${NETWORK_1_VM}
55     ${NETWORK_1_VM_IPS}    ${NETWORK_1_DHCP_IP}    ${VM_COSOLE_OUTPUT} =    OpenStackOperations.Get VM IP    true    ${NETWORK_1_VM}
56     BuiltIn.Set Suite Variable    ${NETWORK_1_VM_IPS}
57     @{GATEWAY_VM_IPS}    ${GATEWAY_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{GATEWAY_VMS}
58     BuiltIn.Set Suite Variable    @{GATEWAY_VM_IPS}
59     #TODO: Verifiy the routes in VM.
60     OpenStackOperations.Show Debugs    ${NETWORK_1_VM}    @{GATEWAY_VMS}
61     OpenStackOperations.Get Suite Debugs
62
63 Verify creation of host route via openstack subnet update option
64     [Documentation]    Creating host route using subnet update option and setting nexthop ip to subnet gateway ip. Verifying in controller and openstack.
65     OpenStackOperations.Update SubNet    @{SUBNETS}[0]    --host-route destination=@{NON_NEUTRON_DESTINATION}[0]${PREFIX24},gateway=@{SUBNET_GW_IP}[0]
66     ${elements} =    BuiltIn.Create List    "destination":"@{NON_NEUTRON_DESTINATION}[0]${PREFIX24}","nexthop":"@{SUBNET_GW_IP}[0]"
67     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${elements}
68     Verify Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{NON_NEUTRON_DESTINATION}[0]${PREFIX24}',\\sgateway='@{SUBNET_GW_IP}[0]'
69
70 Verify removal of host route
71     [Documentation]    Removing subnet host routes via cli and verifying in controller and openstack.
72     OpenStackOperations.Unset SubNet    @{SUBNETS}[0]    --host-route destination=@{NON_NEUTRON_DESTINATION}[0]${PREFIX24},gateway=@{SUBNET_GW_IP}[0]
73     ${elements} =    BuiltIn.Create List    "destination":"@{NON_NEUTRON_DESTINATION}[0]${PREFIX24}","nexthop":"@{SUBNET_GW_IP}[0]"
74     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements Not At URI    ${SUBNETWORK_URL}    ${elements}
75     Verify No Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{NON_NEUTRON_DESTINATION}[0]${PREFIX24}',\\sgateway='@{SUBNET_GW_IP}[0]'
76
77 Verify creation of host route via openstack subnet set option with VM port as next hop IP
78     [Documentation]    Creating host route using subnet update option and setting nexthop to gateway vm ip and verifying in controller and openstack.
79     OpenStackOperations.Update SubNet    @{SUBNETS}[0]    --host-route destination=@{SUBNET_CIDR}[2]${PREFIX24},gateway=@{GATEWAY_VM_IPS}[0]
80     ${elements} =    BuiltIn.Create List    "destination":"@{SUBNET_CIDR}[2]${PREFIX24}","nexthop":"@{GATEWAY_VM_IPS}[0]"
81     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${elements}
82     Verify Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{SUBNET_CIDR}[2]${PREFIX24}',\\sgateway='@{GATEWAY_VM_IPS}[0]'
83
84 Verify creation of host route via openstack subnet set option with VM port as next hop IP with change in destination prefix
85     [Documentation]    Creating host route using subnet update option and setting nexthop ip to gateway vm ip and changing destination prefix.
86     ...    Verifying in controller and openstack.
87     OpenStackOperations.Update SubNet    @{SUBNETS}[0]    --host-route destination=@{SUBNET_CIDR}[1]${PREFIX24},gateway=@{GATEWAY_VM_IPS}[0]
88     ${elements} =    BuiltIn.Create List    "destination":"@{SUBNET_CIDR}[1]${PREFIX24}","nexthop":"@{GATEWAY_VM_IPS}[0]"
89     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${elements}
90     Verify Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{SUBNET_CIDR}[1]${PREFIX24}',\\sgateway='@{GATEWAY_VM_IPS}[0]'
91
92 Verify creation of host route via openstack subnet set option with change in next hop IP
93     [Documentation]    Creating host route using subnet update option and setting nexthop ip to new gateway vm ip without changing the
94     ...    destination prefix. Verifying in controller and openstack.
95     OpenStackOperations.Update SubNet    @{SUBNETS}[0]    --host-route destination=@{SUBNET_CIDR}[1]${PREFIX24},gateway=@{GATEWAY_VM_IPS}[1]
96     ${elements} =    BuiltIn.Create List    "destination":"@{SUBNET_CIDR}[1]${PREFIX24}","nexthop":"@{GATEWAY_VM_IPS}[1]"
97     BuiltIn.Wait Until Keyword Succeeds    30s    5s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${elements}
98     Verify Hostroutes In Subnet    @{SUBNETS}[0]    destination='@{SUBNET_CIDR}[1]${PREFIX24}',\\sgateway='@{GATEWAY_VM_IPS}[1]'
99
100 *** Keywords ***
101 Suite Setup
102     [Documentation]    Creates initial setup.
103     VpnOperations.Basic Suite Setup
104     OpenStackOperations.Create Allow All SecurityGroup    ${SECURITY_GROUP}
105     FOR    ${network}    IN    @{NETWORKS}
106         OpenStackOperations.Create Network    ${network}
107     END
108     FOR    ${i}    IN RANGE    1    4
109         OpenStackOperations.Create SubNet    @{NETWORKS}[${i}]    @{SUBNETS}[${i}]    @{SUBNET_CIDR}[${i}]${PREFIX24}
110         OpenStackOperations.Create Port    @{NETWORKS}[${i}]    @{PORTS}[${i}]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
111         OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[${i}]    @{NETWORK_${i+1}_VMS}[0]    ${OS_CMP1_HOSTNAME}    sg=${SECURITY_GROUP}
112         OpenStackOperations.Create Port    @{NETWORKS}[${i}]    @{PORTS}[${i+3}]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
113         OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[${i+3}]    @{NETWORK_${i+1}_VMS}[1]    ${OS_CMP2_HOSTNAME}    sg=${SECURITY_GROUP}
114         OpenStackOperations.Create Port    @{NETWORKS}[${i}]    @{GATEWAY_PORTS}[${i}]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
115         OpenStackOperations.Create Port    @{NETWORKS}[${i}]    @{GATEWAY_PORTS}[${i+3}]    sg=${SECURITY_GROUP}    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
116     END
117     @{NETWORK_2_VM_IPS}    ${NETWORK_2_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_2_VMS}
118     BuiltIn.Set Suite Variable    @{NETWORK_2_VM_IPS}
119     @{NETWORK_3_VM_IPS}    ${NETWORK_3_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_3_VMS}
120     BuiltIn.Set Suite Variable    @{NETWORK_3_VM_IPS}
121     @{NETWORK_4_VM_IPS}    ${NETWORK_4_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_4_VMS}
122     BuiltIn.Set Suite Variable    @{NETWORK_4_VM_IPS}
123     OpenStackOperations.Show Debugs    @{NETWORK_2_VMS}    @{NETWORK_3_VMS}    @(NETWORK_4_VMS)
124     OpenStackOperations.Get Suite Debugs
125
126 Verify Hostroutes In Subnet
127     [Arguments]    ${subnet_name}    @{elements}
128     [Documentation]    Show subnet with openstack request and verifies given hostroute in subnet.
129     ${output} =    OpenStackOperations.Show SubNet    ${subnet_name}
130     FOR    ${element}    IN    @{elements}
131         BuiltIn.Should Match Regexp    ${output}    ${element}
132     END
133
134 Verify No Hostroutes In Subnet
135     [Arguments]    ${subnet_name}    @{elements}
136     [Documentation]    Show subnet with openstack request and verifies no given hostroute in subnet.
137     ${output} =    OpenStackOperations.Show SubNet    ${subnet_name}
138     FOR    ${element}    IN    @{elements}
139         BuiltIn.Should Not Match Regexp    ${output}    ${element}
140     END