Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / lib / role_lib.resource
1 *** Comments ***
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
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
14
15 *** Settings ***
16 Documentation   Library providing keywords for CRUD operations over roles with OSM client.
17 Library   OperatingSystem
18
19
20 *** Variables ***
21 ${SUCCESS_RETURN_CODE}   0
22
23
24 *** Keywords ***
25 Create Role
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}
30     Log   ${stdout}
31     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
32     RETURN   ${stdout}
33
34 Update Role
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}
45     END
46     ${rc}   ${stdout}=   Run And Return Rc And Output   ${osm_update_command}
47     Log   ${stdout}
48     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
49
50 Check If Role Exists
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}"
55     Log   ${stdout}
56     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
57
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}"
65     Log   ${stdout}
66     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
67
68 Delete Role
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}
72     Log   ${stdout}
73     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}