2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
16 Documentation Library providing keywords for CRUD operations over roles with OSM client.
17 Library OperatingSystem
21 ${SUCCESS_RETURN_CODE} 0
26 [Documentation] Create a role in OSM with the name passed as argument, and return the role id.
27 [Arguments] ${role_name}
28 Should Not Be Empty ${role_name}
29 ${rc} ${stdout}= Run And Return Rc And Output osm role-create ${role_name}
31 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
35 [Documentation] Update a role in OSM.
36 ... The extra parameters (like '--add') are given to this function in name=value format. These parameters will be appended to the 'osm role-update' command with the next syntax: --param_name=param_value
37 ... Example of execution:
38 ... Update Role \${role_name} add='vims: true'
39 [Arguments] ${role_name} @{optional_parameters}
40 ${osm_update_command}= Set Variable osm role-update ${role_name}
41 FOR ${param} IN @{optional_parameters}
42 ${match} ${param_name} ${param_value}= Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters
43 Log ${match},${param_name},${param_value}
44 ${osm_update_command}= Catenate ${osm_update_command} --${param_name}=${param_value}
46 ${rc} ${stdout}= Run And Return Rc And Output ${osm_update_command}
48 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
51 [Documentation] Check if a role exists in OSM.
52 [Arguments] ${role_name}
53 Should Not Be Empty ${role_name}
54 ${rc} ${stdout}= Run And Return RC And Output osm role-list | awk 'NR>3 {print $2}' | grep "${role_name}"
56 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
58 Check If User Has Role
59 [Documentation] Check if a user has a role in a specific project in OSM.
60 [Arguments] ${user_name} ${role_name} ${project_name}
61 Should Not Be Empty ${user_name}
62 Should Not Be Empty ${role_name}
63 Should Not Be Empty ${project_name}
64 ${rc} ${stdout}= Run And Return RC And Output osm user-show ${user_name} | grep -B1 "role_name" | grep -B1 "${role_name}" | grep "project_name" | grep "${project_name}"
66 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
69 [Documentation] Delete from OSM the role passed as argument.
70 [Arguments] ${role_name}
71 ${rc} ${stdout}= Run And Return Rc And Output osm role-delete ${role_name}
73 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}