Connectivity Tests for the Openstack Jobs
[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 Create Network
9     [Arguments]    ${network_name}     ${devstack_path}=/opt/stack/new/devstack
10     [Documentation]    Create Network with neutron request.
11     ${output}=    Write Commands Until Prompt    cd ${devstack_path} && cat localrc
12     Log    ${output}
13     ${output}=    Write Commands Until Prompt    source openrc admin admin
14     Log    ${output}
15     ${output}=    Write Commands Until Prompt    neutron -v net-create ${network_name}
16     Log    ${output}
17     Should Contain    ${output}    Created a new network
18
19 Delete Network
20     [Arguments]    ${network_name}
21     [Documentation]    Delete Network with neutron request.
22     ${output}=    Write Commands Until Prompt    neutron -v net-delete ${network_name}
23     Log    ${output}
24     Should Contain    ${output}    Deleted network: ${network_name}
25
26 Create SubNet
27     [Arguments]    ${network_name}    ${subnet}    ${range_ip}
28     [Documentation]    Create SubNet for the Network with neutron request.
29     ${output}=    Write Commands Until Prompt    neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet}
30     Log    ${output}
31     Should Contain    ${output}    Created a new subnet
32
33 Verify Gateway Ips
34     [Documentation]    Verifies the Gateway Ips with dump flow.
35     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
36     Log    ${output}
37     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
38     \    Should Contain    ${output}    ${GatewayIpElement}
39
40 Verify Dhcp Ips
41     [Documentation]    Verifies the Dhcp Ips with dump flow.
42     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
43     Log    ${output}
44     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
45     \    Should Contain    ${output}    ${DhcpIpElement}
46
47 Verify No 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 Not Contain    ${output}    ${DhcpIpElement}
53
54 Delete SubNet
55     [Arguments]    ${subnet}
56     [Documentation]    Delete SubNet for the Network with neutron request.
57     Log    ${subnet}
58     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
59     Log    ${output}
60     Should Contain    ${output}    Deleted subnet: ${subnet}
61
62 Verify No Gateway Ips
63     [Documentation]    Verifies the Gateway Ips removed with dump flow.
64     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
65     Log    ${output}
66     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
67     \    Should Not Contain    ${output}    ${GatewayIpElement}
68
69 Create Vm Instance
70     [Arguments]    ${net_id}    ${network_name}
71     [Documentation]    Create Vm Instance with the net id of the Netowrk.
72     ${VmElement}=    Set Variable If    "${network_name}"=="net1_network"    MyFirstInstance    MySecondInstance
73     ${output}=    Write Commands Until Prompt    nova boot --image cirros-0.3.4-x86_64-uec --flavor m1.tiny --nic net-id=${net_id} ${VmElement}
74     Log    ${output}
75
76 Delete Vm Instance
77     [Arguments]    ${vm_name}
78     [Documentation]    Delete Vm instances using instance names.
79     ${output}=    Write Commands Until Prompt    nova delete ${vm_name}
80     Log    ${output}
81
82 Get Net Id
83     [Arguments]    ${network_name}
84     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
85     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | get_field 1
86     Log    ${output}
87     ${splitted_output}=    Split String    ${output}    ${EMPTY}
88     ${net_id}=    Get from List    ${splitted_output}    0
89     Log    ${net_id}
90     [Return]    ${net_id}
91
92 Create Vm Instances
93     [Arguments]    ${net_id}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.tiny
94     [Documentation]    Create Four Vm Instance with the net id of the Netowrk.
95     : FOR    ${VmElement}    IN    @{vm_instance_names}
96     \    ${output}=    Write Commands Until Prompt     nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement}
97     \    Log    ${output}
98
99 View Vm Console
100     [Arguments]    ${vm_instance_names}
101     [Documentation]    View Console log of the created vm instances using nova show.
102     : FOR    ${VmElement}    IN    @{vm_instance_names}
103     \    ${output}=   Write Commands Until Prompt     nova show ${VmElement}
104     \    Log    ${output}
105     \    ${output}=   Write Commands Until Prompt     nova console-log ${VmElement}
106     \    Log    ${output}
107
108 Ping Vm From DHCP Namespace
109     [Arguments]    ${net_id}    ${vm_ip}
110     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
111     Log    ${vm_ip}
112     ${output}=    Write Commands Until Prompt     sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
113     Log    ${output}
114     [Return]    ${output}
115
116 Ping From Instance
117     [Arguments]    ${dest_vm}
118     [Documentation]    Ping to the expected destination ip.
119     ${output}=   Write Commands Until Expected Prompt    ping -c 3 ${dest_vm}    $
120     Log    ${output}
121     [Return]    ${output}
122
123 Curl Metadata Server
124     [Documentation]    Ping to the expected destination ip.
125     ${output}=   Write Commands Until Expected Prompt    curl -i http://169.254.169.254    $
126     Write Commands Until Prompt    exit
127     Should Contain     ${output}     200
128
129 Close Vm Instance
130     [Documentation]    Exit the vm instance.
131     ${output}=   Write Commands Until Prompt    exit
132     Log    ${output}
133
134 Ssh Vm Instance
135     [Arguments]    ${net_id}    ${vm_ip}    ${user}=cirros    ${password}=cubswin:)     ${key_file}=test.pem
136     [Documentation]    Login to the vm instance using ssh in the network.
137     ${output}=   Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -i ${key_file} ${user}@${vm_ip}    (yes/no)?
138     Log    ${output}
139     ${output}=   Write Commands Until Expected Prompt    yes    d:
140     Log    ${output}
141     ${output}=   Write Commands Until Expected Prompt    ${password}    $
142     Log    ${output}
143     ${output}=   Write Commands Until Expected Prompt    ifconfig    $
144     Log    ${output}
145     ${output}=   Write Commands Until Expected Prompt    route    $
146     Log    ${output}
147
148 Create Router
149     [Arguments]    ${router_name}
150     [Documentation]    Create Router and Add Interface to the subnets.
151     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}
152     Should Contain     ${output}     Created a new router
153
154 Add Router Interface
155     [Arguments]    ${router_name}     ${interface_name}
156     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
157     Should Contain     ${output}     Added interface
158
159 Remove Interface
160     [Arguments]    ${router_name}     ${interface_name}
161     [Documentation]    Remove Interface to the subnets.
162     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
163     Should Contain     ${output}     Removed interface from router
164
165 Delete Router
166     [Arguments]    ${router_name}
167     [Documentation]    Delete Router and Interface to the subnets.
168     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}
169     Should Contain     ${output}     Deleted router:
170
171 Show Debugs
172     [Arguments]    ${vm_indices}
173     [Documentation]   Run these commands for debugging, it can list state of VM instances and ip information in control node
174     ${output}=   Write Commands Until Prompt     sudo ip netns list
175     Log     ${output}
176     : FOR    ${index}    IN    @{vm_indices}
177     \     ${output}=   Write Commands Until Prompt     nova show ${index}
178     \     Log    ${output}