refactor dhcp function
[integration/test.git] / csit / suites / openstack / connectivity / 01_l2_tests.robot
1 *** Settings ***
2 Documentation     Test suite to verify packet flows between vm instances.
3 Suite Setup       BuiltIn.Run Keywords    SetupUtils.Setup_Utils_For_Setup_And_Teardown
4 ...               AND    DevstackUtils.Devstack Suite Setup
5 Suite Teardown    Close All Connections
6 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
7 Test Teardown     Get Test Teardown Debugs
8 Library           SSHLibrary
9 Library           OperatingSystem
10 Library           RequestsLibrary
11 Resource          ../../../libraries/DevstackUtils.robot
12 Resource          ../../../libraries/OpenStackOperations.robot
13 Resource          ../../../libraries/SetupUtils.robot
14 Resource          ../../../libraries/Utils.robot
15
16 *** Variables ***
17 @{NETWORKS_NAME}    l2_network_1    l2_network_2
18 @{SUBNETS_NAME}    l2_subnet_1    l2_subnet_2
19 @{NET_1_VM_INSTANCES}    MyFirstInstance_1    MySecondInstance_1    MyThirdInstance_1
20 @{NET_2_VM_INSTANCES}    MyFirstInstance_2    MySecondInstance_2    MyThirdInstance_2
21 @{SUBNETS_RANGE}    30.0.0.0/24    40.0.0.0/24
22 ${network1_vlan_id}    1235
23
24 *** Test Cases ***
25 Create VLAN Network @{NETWORKS_NAME}[0]
26     [Documentation]    Create Network with neutron request.
27     Create Network    @{NETWORKS_NAME}[0]    --provider:network_type=vlan --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} --provider:segmentation_id=${network1_vlan_id}
28
29 Create VXLAN Network @{NETWORKS_NAME}[1]
30     [Documentation]    Create Network with neutron request.
31     Create Network    @{NETWORKS_NAME}[1]
32
33 Create Subnets For l2_network_1
34     [Documentation]    Create Sub Nets for the Networks with neutron request.
35     Create SubNet    @{NETWORKS_NAME}[0]    @{SUBNETS_NAME}[0]    @{SUBNETS_RANGE}[0]
36
37 Create Subnets For l2_network_2
38     [Documentation]    Create Sub Nets for the Networks with neutron request.
39     Create SubNet    @{NETWORKS_NAME}[1]    @{SUBNETS_NAME}[1]    @{SUBNETS_RANGE}[1]
40
41 Add Ssh Allow Rule
42     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
43     Neutron Security Group Create    csit
44     Neutron Security Group Rule Create    csit    direction=ingress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
45     Neutron Security Group Rule Create    csit    direction=egress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
46     Neutron Security Group Rule Create    csit    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
47     Neutron Security Group Rule Create    csit    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
48     Neutron Security Group Rule Create    csit    direction=ingress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
49     Neutron Security Group Rule Create    csit    direction=egress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
50
51 Create Vm Instances For l2_network_1
52     [Documentation]    Create Four Vm instances using flavor and image names for a network.
53     Create Vm Instances    l2_network_1    ${NET_1_VM_INSTANCES}    sg=csit
54
55 Create Vm Instances For l2_network_2
56     [Documentation]    Create Four Vm instances using flavor and image names for a network.
57     Create Vm Instances    l2_network_2    ${NET_2_VM_INSTANCES}    sg=csit
58
59 Check Vm Instances Have Ip Address
60     [Documentation]    Test case to verify that all created VMs are ready and have received their ip addresses.
61     ...    We are polling first and longest on the last VM created assuming that if it's received it's address
62     ...    already the other instances should have theirs already or at least shortly thereafter.
63     # first, ensure all VMs are in ACTIVE state.    if not, we can just fail the test case and not waste time polling
64     # for dhcp addresses
65     : FOR    ${vm}    IN    @{NET_1_VM_INSTANCES}    @{NET_2_VM_INSTANCES}
66     \    Wait Until Keyword Succeeds    15s    5s    Verify VM Is ACTIVE    ${vm}
67     ${status}    ${message}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    60s    5s    Collect VM IP Addresses
68     ...    true    @{NET_1_VM_INSTANCES}
69     ${status}    ${message}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    60s    5s    Collect VM IP Addresses
70     ...    true    @{NET_2_VM_INSTANCES}
71     ${NET2_VM_IPS}    ${NET2_DHCP_IP}    Collect VM IP Addresses    false    @{NET_2_VM_INSTANCES}
72     ${NET1_VM_IPS}    ${NET1_DHCP_IP}    Collect VM IP Addresses    false    @{NET_1_VM_INSTANCES}
73     ${VM_INSTANCES}=    Collections.Combine Lists    ${NET_1_VM_INSTANCES}    ${NET_2_VM_INSTANCES}
74     ${VM_IPS}=    Collections.Combine Lists    ${NET1_VM_IPS}    ${NET2_VM_IPS}
75     ${LOOP_COUNT}    Get Length    ${VM_INSTANCES}
76     : FOR    ${index}    IN RANGE    0    ${LOOP_COUNT}
77     \    ${status}    ${message}    Run Keyword And Ignore Error    Should Not Contain    @{VM_IPS}[${index}]    None
78     \    Run Keyword If    '${status}' == 'FAIL'    Write Commands Until Prompt    nova console-log @{VM_INSTANCES}[${index}]    30s
79     Append To List    ${NET1_VM_IPS}    @{NET1_DHCP_IP}[0]
80     Set Suite Variable    ${NET1_VM_IPS}
81     Append To List    ${NET2_VM_IPS}    @{NET2_DHCP_IP}[0]
82     Set Suite Variable    ${NET2_VM_IPS}
83     Should Not Contain    ${NET1_VM_IPS}    None
84     Should Not Contain    ${NET2_VM_IPS}    None
85     [Teardown]    Run Keywords    Show Debugs    @{NET_1_VM_INSTANCES}    @{NET_2_VM_INSTANCES}
86     ...    AND    Get Test Teardown Debugs
87
88 Ping Vm Instance1 In l2_network_1
89     [Documentation]    Check reachability of vm instances by pinging to them.
90     Ping Vm From DHCP Namespace    l2_network_1    @{NET1_VM_IPS}[0]
91
92 Ping Vm Instance2 In l2_network_1
93     [Documentation]    Check reachability of vm instances by pinging to them.
94     Ping Vm From DHCP Namespace    l2_network_1    @{NET1_VM_IPS}[1]
95
96 Ping Vm Instance3 In l2_network_1
97     [Documentation]    Check reachability of vm instances by pinging to them.
98     Ping Vm From DHCP Namespace    l2_network_1    @{NET1_VM_IPS}[2]
99
100 Ping Vm Instance1 In l2_network_2
101     [Documentation]    Check reachability of vm instances by pinging to them.
102     Ping Vm From DHCP Namespace    l2_network_2    @{NET2_VM_IPS}[0]
103
104 Ping Vm Instance2 In l2_network_2
105     [Documentation]    Check reachability of vm instances by pinging to them.
106     Ping Vm From DHCP Namespace    l2_network_2    @{NET2_VM_IPS}[1]
107
108 Ping Vm Instance3 In l2_network_2
109     [Documentation]    Check reachability of vm instances by pinging to them.
110     Ping Vm From DHCP Namespace    l2_network_2    @{NET2_VM_IPS}[2]
111
112 Connectivity Tests From Vm Instance1 In l2_network_1
113     [Documentation]    Login to the vm instance and test some operations
114     Test Operations From Vm Instance    l2_network_1    @{NET1_VM_IPS}[0]    ${NET1_VM_IPS}
115
116 Connectivity Tests From Vm Instance2 In l2_network_1
117     [Documentation]    Login to the vm instance and test operations
118     Test Operations From Vm Instance    l2_network_1    @{NET1_VM_IPS}[1]    ${NET1_VM_IPS}
119
120 Connectivity Tests From Vm Instance3 In l2_network_1
121     [Documentation]    Login to the vm instance and test operations
122     Test Operations From Vm Instance    l2_network_1    @{NET1_VM_IPS}[2]    ${NET1_VM_IPS}
123
124 Connectivity Tests From Vm Instance1 In l2_network_2
125     [Documentation]    Login to the vm instance and test operations
126     Test Operations From Vm Instance    l2_network_2    @{NET2_VM_IPS}[0]    ${NET2_VM_IPS}
127
128 Connectivity Tests From Vm Instance2 In l2_network_2
129     [Documentation]    Logging to the vm instance using generated key pair.
130     Test Operations From Vm Instance    l2_network_2    @{NET2_VM_IPS}[1]    ${NET2_VM_IPS}
131
132 Connectivity Tests From Vm Instance3 In l2_network_2
133     [Documentation]    Login to the vm instance using generated key pair.
134     Test Operations From Vm Instance    l2_network_2    @{NET2_VM_IPS}[2]    ${NET2_VM_IPS}
135
136 Delete A Vm Instance
137     [Documentation]    Delete Vm instances using instance names.
138     Delete Vm Instance    MyFirstInstance_1
139
140 No Ping For Deleted Vm
141     [Documentation]    Check non reachability of deleted vm instances by pinging to them.
142     ${output}=    Ping From DHCP Should Not Succeed    l2_network_1    @{NET_1_VM_IPS}[0]
143
144 Delete Vm Instances In l2_network_1
145     [Documentation]    Delete Vm instances using instance names in l2_network_1.
146     : FOR    ${VmElement}    IN    @{NET_1_VM_INSTANCES}
147     \    Delete Vm Instance    ${VmElement}
148
149 Delete Vm Instances In l2_network_2
150     [Documentation]    Delete Vm instances using instance names in l2_network_2.
151     : FOR    ${VmElement}    IN    @{NET_2_VM_INSTANCES}
152     \    Delete Vm Instance    ${VmElement}
153     [Teardown]    Run Keywords    Show Debugs    @{NET_1_VM_INSTANCES}    @{NET_2_VM_INSTANCES}
154     ...    AND    Get Test Teardown Debugs
155
156 Delete Sub Networks In l2_network_1
157     [Documentation]    Delete Sub Nets for the Networks with neutron request.
158     Delete SubNet    l2_subnet_1
159
160 Delete Sub Networks In l2_network_2
161     [Documentation]    Delete Sub Nets for the Networks with neutron request.
162     Delete SubNet    l2_subnet_2
163
164 Delete Networks
165     [Documentation]    Delete Networks with neutron request.
166     : FOR    ${NetworkElement}    IN    @{NETWORKS_NAME}
167     \    Delete Network    ${NetworkElement}