Adds Robot test BASIC-15 for RBAC configurations 06/9506/3
authorgarciaale <agarcia@whitestack.com>
Wed, 22 Jul 2020 22:14:08 +0000 (22:14 +0000)
committerbeierlm <mark.beierl@canonical.com>
Tue, 28 Jul 2020 14:22:29 +0000 (16:22 +0200)
Change-Id: Ia907f795dc735eff64cab3027885a8363bf815d8
Signed-off-by: garciaale <agarcia@whitestack.com>
robot-systest/lib/project_lib.robot
robot-systest/lib/role_lib.robot [new file with mode: 0644]
robot-systest/lib/user_lib.robot [new file with mode: 0644]
robot-systest/resources/basic_15-rbac_configurations_data.py [new file with mode: 0644]
robot-systest/testsuite/basic_15-rbac_configurations.robot [new file with mode: 0644]

index 916730d..ae4f5cc 100644 (file)
@@ -15,6 +15,16 @@ ${success_return_code}   0
 
 
 *** Keywords ***
+Create Project
+    [Arguments]   ${project_name}
+
+    Should Not Be Empty   ${project_name}
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm project-create ${project_name}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+    [Return]  ${stdout}
+
+
 Create Project With Quotas
     [Arguments]   ${project_name}   ${project_quotas}
 
diff --git a/robot-systest/lib/role_lib.robot b/robot-systest/lib/role_lib.robot
new file mode 100644 (file)
index 0000000..8f873fa
--- /dev/null
@@ -0,0 +1,71 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Variables ***
+${success_return_code}   0
+
+
+*** Keywords ***
+Create Role
+    [Arguments]   ${role_name}
+
+    Should Not Be Empty   ${role_name}
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm role-create ${role_name}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+    [Return]  ${stdout}
+
+
+Update Role
+    [Documentation]     Updates a role in OSM.
+    ...                 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
+    ...                 Example of execution:
+    ...                     Update Role  \${role_name}  add='vims: true'
+
+    [Arguments]  ${role_name}  @{optional_parameters}
+
+    ${osm_update_command}=  Set Variable  osm role-update ${role_name}
+    FOR  ${param}  IN  @{optional_parameters}
+        ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in optional parameters
+        ${osm_update_command}=  Catenate  ${osm_update_command}  --${param_name}=${param_value}
+    END
+    ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_update_command}
+    log  ${stdout}
+    Should Be Equal As Integers  ${rc}  ${success_return_code}
+
+
+Check If Role Exists
+    [Arguments]  ${role_name}
+
+    Should Not Be Empty   ${role_name}
+    ${rc}   ${stdout}=   Run And Return RC And Output   osm role-list | awk 'NR>3 {print $2}' | grep "${role_name}"
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+
+
+Check If User Has Role
+    [Arguments]  ${user_name}  ${role_name}  ${project_name}
+
+    Should Not Be Empty   ${user_name}
+    Should Not Be Empty   ${role_name}
+    Should Not Be Empty   ${project_name}
+    ${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}"
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+
+
+Delete Role
+    [Arguments]  ${role_name}
+
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm role-delete ${role_name}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
diff --git a/robot-systest/lib/user_lib.robot b/robot-systest/lib/user_lib.robot
new file mode 100644 (file)
index 0000000..8047c33
--- /dev/null
@@ -0,0 +1,54 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Variables ***
+${success_return_code}   0
+
+
+*** Keywords ***
+Create User
+    [Arguments]   ${user_name}   ${user_password}
+
+    Should Not Be Empty   ${user_name}
+    Should Not Be Empty   ${user_password}
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm user-create ${user_name} --password ${user_password}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+    [Return]  ${stdout}
+
+
+Update User Role
+    [Arguments]   ${user_name}   ${project_name}   ${role_name}
+
+    Should Not Be Empty   ${user_name}
+    Should Not Be Empty   ${project_name}
+    Should Not Be Empty   ${role_name}
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm user-update --add-project-role '${project_name},${role_name}' ${user_name}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+
+
+Check If User Exists
+    [Arguments]  ${user_name}
+
+    Should Not Be Empty   ${user_name}
+    ${rc}   ${stdout}=   Run And Return RC And Output   osm user-list | awk 'NR>3 {print $2}' | grep "${user_name}"
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+
+
+Delete User
+    [Arguments]  ${user_name}
+
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm user-delete ${user_name}
+    Log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
diff --git a/robot-systest/resources/basic_15-rbac_configurations_data.py b/robot-systest/resources/basic_15-rbac_configurations_data.py
new file mode 100644 (file)
index 0000000..684ac24
--- /dev/null
@@ -0,0 +1,24 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+from pathlib import Path
+
+# Get ${HOME} from local machine
+home = str(Path.home())
+# User, project and roles to use
+user_name = 'basic_15_test_user'
+user_password = 'basic_15_user_pass'
+user_role = 'project_user'
+user_project = 'admin'
+project_name = 'basic_15_test_project'
+new_project_name = 'basic_15_project_test'
+role_name = 'test_role'
diff --git a/robot-systest/testsuite/basic_15-rbac_configurations.robot b/robot-systest/testsuite/basic_15-rbac_configurations.robot
new file mode 100644 (file)
index 0000000..56cddc0
--- /dev/null
@@ -0,0 +1,89 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation     [BASIC-15] RBAC Configurations.
+
+Library   OperatingSystem
+Library   String
+Library   Collections
+
+Resource   %{ROBOT_DEVOPS_FOLDER}/lib/user_lib.robot
+Resource   %{ROBOT_DEVOPS_FOLDER}/lib/project_lib.robot
+Resource   %{ROBOT_DEVOPS_FOLDER}/lib/role_lib.robot
+
+Variables   %{ROBOT_DEVOPS_FOLDER}/resources/basic_15-rbac_configurations_data.py
+
+Suite Teardown   Run Keyword And Ignore Error   Test Cleanup
+
+
+*** Variables ***
+${success_return_code}   0
+
+*** Test Cases ***
+Create And Validate User
+    [Tags]   rbac_configurations   sanity   regression
+
+    Create User   ${user_name}   ${user_password}
+    Check If User Exists   ${user_name}
+
+
+Assign Role To User
+    [Tags]   rbac_configurations   sanity   regression
+
+    Update User Role   ${user_name}  ${user_project}  ${user_role}
+    Check If User Is Assigned To Project   ${user_name}   ${user_project}
+    Check If User Has Role   ${user_name}  ${user_role}  ${user_project}
+
+
+Run Action As User
+    [Tags]   rbac_configurations   sanity   regression
+
+    ${rc}   ${stdout}=   Run And Return RC And Output   OSM_USER=${user_name} OSM_PROJECT=${user_project} OSM_PASSWORD=${user_password} osm ns-list
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+
+
+Create And Update Project
+    [Tags]   rbac_configurations   sanity   regression
+
+    Create Project   ${project_name}
+    Update Project Name   ${project_name}   ${new_project_name}
+
+
+Create And Validate Role
+    [Tags]   rbac_configurations   sanity   regression
+
+    Create Role   ${role_name}
+    Check If Role Exists   ${role_name}
+
+
+Update Role Information
+    [Tags]   rbac_configurations   sanity   regression
+
+    Update Role   ${role_name}   add='vims: true'
+    Check If Role Exists   ${role_name}
+
+
+Delete Allocated Resources
+    [Tags]   rbac_configurations   sanity   regression  cleanup
+
+    Delete User   ${user_name}
+    Delete Project   ${new_project_name}
+    Delete Role   ${role_name}
+
+
+*** Keywords ***
+Test Cleanup
+    Run Keyword If Test Failed  Run Keyword And Ignore Error  Delete User  ${user_name}
+    Run Keyword If Test Failed  Run Keyword And Ignore Error  Delete Role  ${role_name}
+    Run Keyword If Test Failed  Run Keyword And Ignore Error  Delete Project  ${project_name}
+    Run Keyword If Test Failed  Run Keyword And Ignore Error  Delete Project  ${new_project_name}