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