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