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