blob: 1ba3a2d7a11df4daa94108004e5c7b720b05cded [file] [log] [blame]
garciadeblas7a9e0312023-12-11 22:24:46 +01001*** Comments ***
garciaaledce1fa82020-07-22 22:14:08 +00002# 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
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
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.
13
garciadeblas7a9e0312023-12-11 22:24:46 +010014
15*** Settings ***
16Documentation Library providing keywords for CRUD operations over roles with OSM client.
17Library OperatingSystem
18
19
garciaaledce1fa82020-07-22 22:14:08 +000020*** Variables ***
garciadeblas7a9e0312023-12-11 22:24:46 +010021${SUCCESS_RETURN_CODE} 0
garciaaledce1fa82020-07-22 22:14:08 +000022
23
24*** Keywords ***
25Create Role
garciadeblas7a9e0312023-12-11 22:24:46 +010026 [Documentation] Create a role in OSM with the name passed as argument, and return the role id.
garciaaledce1fa82020-07-22 22:14:08 +000027 [Arguments] ${role_name}
garciaaledce1fa82020-07-22 22:14:08 +000028 Should Not Be Empty ${role_name}
garciadeblas7a9e0312023-12-11 22:24:46 +010029 ${rc} ${stdout}= Run And Return Rc And Output osm role-create ${role_name}
garciaaledce1fa82020-07-22 22:14:08 +000030 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010031 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
32 RETURN ${stdout}
garciaaledce1fa82020-07-22 22:14:08 +000033
34Update Role
garciadeblas7a9e0312023-12-11 22:24:46 +010035 [Documentation] Update a role in OSM.
garciaaledce1fa82020-07-22 22:14:08 +000036 ... 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:
garciadeblasf4ebaa82022-06-23 13:33:26 +020038 ... Update Role \${role_name} add='vims: true'
garciadeblasf4ebaa82022-06-23 13:33:26 +020039 [Arguments] ${role_name} @{optional_parameters}
garciadeblasf4ebaa82022-06-23 13:33:26 +020040 ${osm_update_command}= Set Variable osm role-update ${role_name}
41 FOR ${param} IN @{optional_parameters}
garciadeblas7a9e0312023-12-11 22:24:46 +010042 ${match} ${param_name} ${param_value}= Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters
43 Log ${match},${param_name},${param_value}
garciadeblasf4ebaa82022-06-23 13:33:26 +020044 ${osm_update_command}= Catenate ${osm_update_command} --${param_name}=${param_value}
garciaaledce1fa82020-07-22 22:14:08 +000045 END
garciadeblas7a9e0312023-12-11 22:24:46 +010046 ${rc} ${stdout}= Run And Return Rc And Output ${osm_update_command}
garciadeblas321726f2022-12-21 11:43:06 +010047 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010048 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
garciaaledce1fa82020-07-22 22:14:08 +000049
50Check If Role Exists
garciadeblas7a9e0312023-12-11 22:24:46 +010051 [Documentation] Check if a role exists in OSM.
garciadeblasf4ebaa82022-06-23 13:33:26 +020052 [Arguments] ${role_name}
garciaaledce1fa82020-07-22 22:14:08 +000053 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}"
55 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010056 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
garciaaledce1fa82020-07-22 22:14:08 +000057
58Check If User Has Role
garciadeblas7a9e0312023-12-11 22:24:46 +010059 [Documentation] Check if a user has a role in a specific project in OSM.
garciadeblasf4ebaa82022-06-23 13:33:26 +020060 [Arguments] ${user_name} ${role_name} ${project_name}
garciaaledce1fa82020-07-22 22:14:08 +000061 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}"
65 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010066 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
garciaaledce1fa82020-07-22 22:14:08 +000067
68Delete Role
garciadeblas7a9e0312023-12-11 22:24:46 +010069 [Documentation] Delete from OSM the role passed as argument.
garciadeblasf4ebaa82022-06-23 13:33:26 +020070 [Arguments] ${role_name}
garciadeblas7a9e0312023-12-11 22:24:46 +010071 ${rc} ${stdout}= Run And Return Rc And Output osm role-delete ${role_name}
garciaaledce1fa82020-07-22 22:14:08 +000072 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010073 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}