add initial vpnservice test cases
[integration/test.git] / csit / libraries / OpenStackOperations.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 Variables         ../variables/Variables.py
6
7 *** Keywords ***
8 Source Password
9     [Arguments]    ${force}=no    ${source_pwd}=yes
10     [Documentation]    Sourcing the Openstack PAsswords for neutron configurations
11     Run Keyword If    '${source_pwd}' == 'yes' or '${force}' == 'yes'    Write Commands Until Prompt    cd ${DEVSTACK_DEPLOY_PATH}; source openrc admin admin
12
13 Create Network
14     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
15     [Documentation]    Create Network with neutron request.
16     ${devstack_conn_id}=       Get ControlNode Connection
17     Switch Connection    ${devstack_conn_id}
18     ${output}=    Write Commands Until Prompt    neutron -v net-create ${network_name} ${additional_args}    30s
19     Close Connection
20     Log    ${output}
21     Should Contain    ${output}    Created a new network
22
23 List Networks
24     [Documentation]    List networks and return output with neutron client.
25     ${devstack_conn_id}=       Get ControlNode Connection
26     Switch Connection    ${devstack_conn_id}
27     ${output}=    Write Commands Until Prompt    neutron net-list    30s
28     Close Connection
29     Log    ${output}
30     [Return]    ${output}
31
32 List Subnets
33     [Documentation]    List subnets and return output with neutron client.
34     ${devstack_conn_id}=       Get ControlNode Connection
35     Switch Connection    ${devstack_conn_id}
36     ${output}=    Write Commands Until Prompt    neutron subnet-list    30s
37     Close Connection
38     Log    ${output}
39     [Return]    ${output}
40
41 Delete Network
42     [Arguments]    ${network_name}
43     [Documentation]    Delete Network with neutron request.
44     ${devstack_conn_id}=       Get ControlNode Connection
45     Switch Connection    ${devstack_conn_id}
46     ${output}=    Write Commands Until Prompt    neutron -v net-delete ${network_name}     30s
47     Close Connection
48     Log    ${output}
49     Should Contain    ${output}    Deleted network: ${network_name}
50
51 Create SubNet
52     [Arguments]    ${network_name}    ${subnet}    ${range_ip}
53     [Documentation]    Create SubNet for the Network with neutron request.
54     ${devstack_conn_id}=       Get ControlNode Connection
55     Switch Connection    ${devstack_conn_id}
56     ${output}=    Write Commands Until Prompt    neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet}    30s
57     Close Connection
58     Log    ${output}
59     Should Contain    ${output}    Created a new subnet
60
61 Verify Gateway Ips
62     [Documentation]    Verifies the Gateway Ips with dump flow.
63     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
64     Log    ${output}
65     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
66     \    Should Contain    ${output}    ${GatewayIpElement}
67
68 Verify Dhcp Ips
69     [Documentation]    Verifies the Dhcp Ips with dump flow.
70     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
71     Log    ${output}
72     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
73     \    Should Contain    ${output}    ${DhcpIpElement}
74
75 Verify No Dhcp Ips
76     [Documentation]    Verifies the Dhcp Ips with dump flow.
77     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
78     Log    ${output}
79     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
80     \    Should Not Contain    ${output}    ${DhcpIpElement}
81
82 Delete SubNet
83     [Arguments]    ${subnet}
84     [Documentation]    Delete SubNet for the Network with neutron request.
85     Log    ${subnet}
86     ${devstack_conn_id}=       Get ControlNode Connection
87     Switch Connection    ${devstack_conn_id}
88     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
89     Close Connection
90     Log    ${output}
91     Should Contain    ${output}    Deleted subnet: ${subnet}
92
93 Verify No Gateway Ips
94     [Documentation]    Verifies the Gateway Ips removed with dump flow.
95     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
96     Log    ${output}
97     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
98     \    Should Not Contain    ${output}    ${GatewayIpElement}
99
100 Delete Vm Instance
101     [Arguments]    ${vm_name}
102     [Documentation]    Delete Vm instances using instance names.
103     ${devstack_conn_id}=       Get ControlNode Connection
104     Switch Connection    ${devstack_conn_id}
105     ${output}=    Write Commands Until Prompt    nova force-delete ${vm_name}      40s
106     Close Connection
107
108 Get Net Id
109     [Arguments]    ${network_name}      ${devstack_conn_id}
110     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
111     Switch Connection    ${devstack_conn_id}
112     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | get_field 1       30s
113     Log    ${output}
114     ${splitted_output}=    Split String    ${output}    ${EMPTY}
115     ${net_id}=    Get from List    ${splitted_output}    0
116     Log    ${net_id}
117     [Return]    ${net_id}
118
119 Create Vm Instances
120     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano
121     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
122     ${devstack_conn_id}=       Get ControlNode Connection
123     Switch Connection    ${devstack_conn_id}
124     ${net_id}=    Get Net Id    ${net_name}      ${devstack_conn_id}
125     : FOR    ${VmElement}    IN    @{vm_instance_names}
126     \    ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement}    30s
127     \    Log    ${output}
128     \    Wait Until Keyword Succeeds    25s    5s    Verify VM Is ACTIVE    ${VmElement}
129
130 Verify VM Is ACTIVE
131     [Arguments]    ${vm_name}
132     [Documentation]    Run these commands to check whether the created vm instance is active or not.
133     ${output}=    Write Commands Until Prompt    nova show ${vm_name} | grep OS-EXT-STS:vm_state      30s
134     Log    ${output}
135     Should Contain    ${output}    active
136
137 View Vm Console
138     [Arguments]    ${vm_instance_names}
139     [Documentation]    View Console log of the created vm instances using nova show.
140     : FOR    ${VmElement}    IN    @{vm_instance_names}
141     \    ${output}=    Write Commands Until Prompt    nova show ${VmElement}
142     \    Log    ${output}
143     \    ${output}=    Write Commands Until Prompt    nova console-log ${VmElement}
144     \    Log    ${output}
145
146 Ping Vm From DHCP Namespace
147     [Arguments]    ${net_name}    ${vm_ip}
148     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
149     Log    ${vm_ip}
150     ${devstack_conn_id}=       Get ControlNode Connection
151     Switch Connection    ${devstack_conn_id}
152     ${net_id}=    Get Net Id    ${net_name}     ${devstack_conn_id}
153     Log    ${net_id}
154     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
155     Log    ${output}
156     Close Connection
157     Should Contain    ${output}    64 bytes
158
159 Ping From DHCP Should Not Succeed
160     [Arguments]    ${net_name}    ${vm_ip}
161     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
162     Log    ${vm_ip}
163     ${devstack_conn_id}=       Get ControlNode Connection
164     Switch Connection    ${devstack_conn_id}
165     ${net_id}=    Get Net Id    ${net_name}     ${devstack_conn_id}
166     Log    ${net_id}
167     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
168     Close Connection
169     Log    ${output}
170     Should Not Contain    ${output}    64 bytes
171
172 Ping From Instance
173     [Arguments]    ${dest_vm}
174     [Documentation]    Ping to the expected destination ip.
175     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm}    ${OS_SYSTEM_PROMPT}
176     Log    ${output}
177     [Return]    ${output}
178
179 Curl Metadata Server
180     [Documentation]    Ping to the expected destination ip.
181     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
182     Write Commands Until Prompt    exit
183     Should Contain    ${output}    200
184
185 Close Vm Instance
186     [Documentation]    Exit the vm instance.
187     ${output}=    Write Commands Until Prompt    exit
188     Log    ${output}
189
190 Check If Console Is VmInstance
191     [Arguments]    ${console}=cirros
192     [Documentation]    Check if the session has been able to login to the VM instance
193     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
194     Should Contain    ${output}    ${console}
195
196 Exit From Vm Console
197     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
198     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
199     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
200     Get OvsDebugInfo
201
202 Check Ping
203     [Arguments]    ${ip_address}
204     [Documentation]    Run Ping command on the IP available as argument
205     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
206     Should Contain    ${output}    64 bytes
207
208 Check Metadata Access
209     [Documentation]    Try curl on the Metadataurl and check if it is okay
210     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
211     Should Contain    ${output}    200
212
213 Test Operations From Vm Instance
214     [Arguments]    ${net_name}    ${src_ip}    ${list_of_local_dst_ips}    ${l2_or_l3}=l2    ${list_of_external_dst_ips}=${NONE}    ${user}=cirros
215     ...    ${password}=cubswin:)
216     [Documentation]    Login to the vm instance using ssh in the network.
217     ${devstack_conn_id}=       Get ControlNode Connection
218     Switch Connection    ${devstack_conn_id}
219     ${net_id}=    Get Net Id    ${net_name}      ${devstack_conn_id}
220     ${output}=    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh ${user}@${src_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no    d:
221     Log    ${output}
222     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
223     Log    ${output}
224     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
225     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
226     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route    ${OS_SYSTEM_PROMPT}
227     ${dest_vm}=    Get From List    ${list_of_local_dst_ips}    0
228     Log    ${dest_vm}
229     Run Keyword If    ${rcode}    Check Ping    ${dest_vm}
230     ${dest_dhcp}=    Get From List    ${list_of_local_dst_ips}    1
231     Log    ${dest_dhcp}
232     Run Keyword If    ${rcode}    Check Ping    ${dest_dhcp}
233     ${dest_vm}=    Get From List    ${list_of_local_dst_ips}    2
234     Log    ${dest_vm}
235     Run Keyword If    ${rcode}    Check Ping    ${dest_vm}
236     Run Keyword If    ${rcode}    Check Metadata Access
237     Run Keyword If    '${l2_or_l3}' == 'l3'    Ping Other Instances    ${list_of_external_dst_ips}
238     [Teardown]    Exit From Vm Console
239
240 Ping Other Instances
241     [Arguments]    ${list_of_external_dst_ips}
242     [Documentation]    Check reachability with other network's instances.
243     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
244     ${dest_vm}=    Get From List    ${list_of_external_dst_ips}    0
245     Log    ${dest_vm}
246     Run Keyword If    ${rcode}    Check Ping    ${dest_vm}
247     ${dest_dhcp}=    Get From List    ${list_of_external_dst_ips}    1
248     Log    ${dest_dhcp}
249     Run Keyword If    ${rcode}    Check Ping    ${dest_dhcp}
250     ${dest_vm}=    Get From List    ${list_of_external_dst_ips}    2
251     Log    ${dest_vm}
252     Run Keyword If    ${rcode}    Check Ping    ${dest_vm}
253
254 Create Router
255     [Arguments]    ${router_name}
256     [Documentation]    Create Router and Add Interface to the subnets.
257     ${devstack_conn_id}=       Get ControlNode Connection
258     Switch Connection    ${devstack_conn_id}
259     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
260     Close Connection
261     Should Contain    ${output}    Created a new router
262
263 Add Router Interface
264     [Arguments]    ${router_name}    ${interface_name}
265     ${devstack_conn_id}=       Get ControlNode Connection
266     Switch Connection    ${devstack_conn_id}
267     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
268     Close Connection
269     Should Contain    ${output}    Added interface
270
271 Remove Interface
272     [Arguments]    ${router_name}    ${interface_name}
273     [Documentation]    Remove Interface to the subnets.
274     ${devstack_conn_id}=       Get ControlNode Connection
275     Switch Connection    ${devstack_conn_id}
276     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
277     Close Connection
278     Should Contain    ${output}    Removed interface from router
279
280 Delete Router
281     [Arguments]    ${router_name}
282     [Documentation]    Delete Router and Interface to the subnets.
283     ${devstack_conn_id}=       Get ControlNode Connection
284     Switch Connection    ${devstack_conn_id}
285     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}       60s
286     Close Connection
287     Should Contain    ${output}    Deleted router:
288
289 Get DumpFlows And Ovsconfig
290     [Arguments]    ${openstack_node_ip}
291     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
292     Log    ${openstack_node_ip}
293     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
294     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
295     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
296     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ]>
297     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ]>
298
299 Get ControlNode Connection
300     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
301     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
302     SSHLibrary.Set Client Configuration    timeout=30s
303     Source Password      force=yes
304     [Return]    ${control_conn_id}
305
306 Get OvsDebugInfo
307     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
308     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
309     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
310     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
311
312 Show Debugs
313     [Arguments]    ${vm_indices}
314     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
315     ${output}=    Write Commands Until Prompt    sudo ip netns list
316     Log    ${output}
317     : FOR    ${index}    IN    @{vm_indices}
318     \    ${output}=    Write Commands Until Prompt    nova show ${index}     30s
319     \    Log    ${output}
320     Close Connection