Update README.md with instructions to run tests using testing-daily images
[osm/tests.git] / robot-systest / lib / openstack_lib.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Variables ***
14 ${success_return_code}   0
15
16
17 *** Keywords ***
18 Get Server Flavor ID
19     [Arguments]   ${server_id}
20
21     Should Not Be Empty   ${server_id}
22     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server show ${server_id} | grep flavor | awk 'NR>1{print $1}' RS='(' FS=')'
23     Log   ${stdout}
24     Should Be Equal As Integers   ${rc}   ${success_return_code}
25     [Return]   ${stdout}
26
27
28 Get Flavor Properties
29     [Arguments]   ${flavor_id}
30
31     Should Not Be Empty   ${flavor_id}
32     ${rc}   ${stdout}=   Run and Return RC and Output   openstack flavor show ${flavor_id} | grep properties | awk -F '|' '{print $3}'
33     Log   ${stdout}
34     Should Be Equal As Integers   ${rc}   ${success_return_code}
35     [Return]   ${stdout}
36
37
38 Check NS Servers In VIM
39     [Documentation]   Check if the number of servers in Openstack by filtering by NS name is as expected.
40     [Arguments]   ${ns_name}   ${number}
41
42     Should Not Be Empty   ${ns_name}
43     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server list | grep ${ns_name} | awk '{print $4}'
44     Log   ${stdout}
45     Should Be Equal As Integers   ${rc}   ${success_return_code}
46     @{servers} =   Split String   ${stdout}
47     ${n_servers}=   Get Length   ${servers}
48     Should Be Equal As Integers   ${number}   ${n_servers}
49
50
51 Check If Volume Bootable
52     [Documentation]   Check the volume properties and return whether it is bootable or not.
53     [Arguments]   ${volume_id}
54
55     Should Not Be Empty   ${volume_id}
56     ${rc}   ${stdout}=   Run and Return RC and Output   openstack volume show ${volume_id} | grep bootable | awk '{print $4}'
57     log   ${stdout}
58     Should Be Equal As Integers   ${rc}   ${success_return_code}
59     [Return]   ${stdout}
60
61
62 Get Project Quota
63     [Documentation]   Get a field (ram, cores, ports, etc.) from quota in current project.
64     [Arguments]   ${field}
65
66     Should Not Be Empty   ${field}
67     ${rc}   ${stdout}=   Run and Return RC and Output   openstack quota show -f yaml | yq '.[] | select(.Resource=="${field}") | .Limit'
68     Log   ${stdout}
69     Should Be Equal As Integers   ${rc}   ${success_return_code}
70     [Return]   ${stdout}
71
72
73 Get Server Property
74     [Documentation]   Get a field (flavor, image, volumes_attached, etc.) from a server.
75     [Arguments]   ${server_id}   ${field}
76
77     Should Not Be Empty   ${server_id}
78     Should Not Be Empty   ${field}
79     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server show ${server_id} -c ${field} -f value
80     Log   ${stdout}
81     Should Be Equal As Integers   ${rc}   ${success_return_code}
82     [Return]   ${stdout}
83
84
85 Check VM In Server Group
86     [Documentation]   Check if a given server is included in an Openstack server group
87     [Arguments]   ${server_id}   ${server_group_name}
88
89     Should Not Be Empty   ${server_group_name}
90     Should Not Be Empty   ${server_id}
91     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server group show ${server_group_name} -c members -f value
92     Log   ${stdout}
93     Should Be Equal As Integers   ${rc}   ${success_return_code}
94     Should Contain   ${stdout}   ${server_id}
95
96
97 Set Volume Id
98     [Documentation]   Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
99     [Arguments]   ${volume_match}   ${index}
100
101     Should Not Be Empty   ${volume_match}   ${index}
102     ${bootable}=   Check If Volume Bootable   ${volume_match}[${index}]
103     Set Suite Variable   ${bootable}
104     IF   '${bootable}'=='true'
105         Set Suite Variable   ${root_vol_id}   ${volume_match}[${index}]
106         IF   ${index}==0
107             Set Suite Variable   ${ordinary_vol_id}   ${volume_match}[1]
108         ELSE
109             Set Suite Variable   ${ordinary_vol_id}   ${volume_match}[0]
110         END
111     END
112
113
114 Get Persistent Volumes Attached To Vm
115     [Documentation]   Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
116     [Arguments]   ${ns_id}
117
118     Variable Should Exist   ${ns_id}   msg=NS is not available
119     ${vnfs_list}=   Get Ns Vnf List   ${ns_id}
120     ${vim_id}=   Get VNF VIM ID   ${vnfs_list}[0]
121     ${volumes_attached}=   Get Server Property   ${vim_id}   volumes_attached
122     log   ${volumes_attached}
123     ${stdout}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
124     log   ${stdout}
125     [Return]   ${stdout}
126
127
128 Check If Volume Exists
129     [Documentation]   Checks if a volume id exists
130     [Arguments]   ${volume_id}
131
132     Should Not Be Empty   ${volume_id}
133     ${rc}   ${stdout}=   Run and Return RC and Output   openstack volume list | grep ${volume_id} | wc -l
134     Log   ${stdout}
135     Should Be Equal As Integers   ${rc}   ${success_return_code}
136     [Return]   ${stdout}
137
138
139 Delete Volume
140     [Documentation]   Delete a volume by its identifier
141     [Arguments]   ${volume_id}
142
143     Should Not Be Empty   ${volume_id}
144     ${rc}   ${stdout}=   Run and Return RC and Output   openstack volume delete ${volume_id}
145     Log   ${stdout}
146     Should Be Equal As Integers   ${rc}   ${success_return_code}
147     [Return]   ${stdout}
148
149
150 Get Subnet
151     [Documentation]   Get subnet information in JSON format
152     [Arguments]   ${subnet_id}
153
154     Should Not Be Empty   ${subnet_id}
155     ${rc}   ${stdout}=   Run and Return RC and Output   openstack subnet show ${subnet_id} -f json
156     Log   ${stdout}
157     Should Be Equal As Integers   ${rc}   ${success_return_code}
158     [Return]   ${stdout}
159
160
161 Stop Server
162     [Documentation]   Stop a server
163     [Arguments]   ${server_id}
164
165     Should Not Be Empty   ${server_id}
166     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server stop ${server_id}
167     Log   ${stdout}
168     Should Be Equal As Integers   ${rc}   ${success_return_code}
169     [Return]   ${stdout}
170
171
172 Halt Server
173     [Documentation]   Reset a server
174     [Arguments]   ${server_id}
175
176     Should Not Be Empty   ${server_id}
177     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server set --state error ${server_id}
178     Log   ${stdout}
179     Should Be Equal As Integers   ${rc}   ${success_return_code}
180     [Return]   ${stdout}
181
182
183 Delete Server
184     [Documentation]   Delete a server
185     [Arguments]   ${server_id}
186
187     Should Not Be Empty   ${server_id}
188     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server delete ${server_id}
189     Log   ${stdout}
190     Should Be Equal As Integers   ${rc}   ${success_return_code}
191     [Return]   ${stdout}
192
193
194 Create Flavor
195     [Documentation]   Create a Flavor
196     [Arguments]   ${flavor_name}   ${cpu}=1   ${ram}=1024   ${disk}=10
197
198     Should Not Be Empty   ${flavor_name}
199     ${rc}   ${flavor_id}=   Run and Return RC and Output   openstack flavor create ${flavor_name} --ram ${ram} --disk ${disk} --vcpus ${cpu} -f yaml | yq '.id' | tr -d \\"
200     Log   ${flavor_id}
201     Should Be Equal As Integers   ${rc}   ${success_return_code}
202     [Return]   ${flavor_id}
203
204
205 Delete Flavor
206     [Documentation]   Delete a Flavor
207     [Arguments]   ${flavor_id}
208
209     Should Not Be Empty   ${flavor_id}
210     ${rc}   ${stdout}=   Run and Return RC and Output   openstack flavor delete ${flavor_id}
211     Log   ${stdout}
212     Should Be Equal As Integers   ${rc}   ${success_return_code}
213     [Return]   ${stdout}