a54448a0214f00d88d87f513d13918abb6d9eea2
[osm/tests.git] / robot-systest / lib / vim_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 *** Settings ***
14 Documentation     Library to manage VIM Targets.
15
16 Library   String
17 Library   Collections
18 Library   OperatingSystem
19
20 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/prometheus_lib.robot
21
22
23 *** Variables ***
24 ${success_return_code}   0
25 ${delete_max_wait_time}   1min
26 ${delete_pol_time}   15sec
27 ${vim_status_max_wait_time}   2min
28 ${vim_status_pol_time}   15sec
29
30
31 *** Keywords ***
32 Create VIM Target
33     [Documentation]     Create a VIM Target in OSM.
34     ...                 The optional parameters (such as 'config' or 'sdn_controller') are given to this function in name=value format. These parameters will be appended to the 'osm vim-create' command with the next syntax: --param_name=param_value
35     ...                 Return the ID of the created VIM Target.
36     ...                 Example of execution:
37     ...                     \${vim_account_id}=  Create VIM Target  \${vim_name}  \${vim_user}  \${vim_password}  \${vim_auth_url}  \${vim_tenant}  \${vim_account_type}  config='{...}'
38
39     [Arguments]  ${vim_name}  ${vim_user}  ${vim_password}  ${vim_auth_url}  ${vim_tenant}  ${vim_account_type}  @{optional_parameters}
40
41     ${osm_vim_create_command}=  Set Variable  osm vim-create --name ${vim_name} --user ${vim_user} --password ${vim_password} --auth_url ${vim_auth_url} --tenant ${vim_tenant} --account_type ${vim_account_type}
42     FOR  ${param}  IN  @{optional_parameters}
43         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in optional parameters
44         ${osm_vim_create_command}=  Catenate  ${osm_vim_create_command}  --${param_name}=${param_value}
45     END
46     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_vim_create_command}
47     log  ${stdout}
48     Should Be Equal As Integers  ${rc}  ${success_return_code}
49     [Return]  ${stdout}
50
51
52 Delete VIM Target
53     [Arguments]   ${vim_name}
54
55     ${rc}  ${stdout}=  Run Keyword And Continue On Failure  Run and Return RC and Output  osm vim-delete ${vim_name}
56     log  ${stdout}
57     Wait Until Keyword Succeeds  ${delete_max_wait_time}  ${delete_pol_time}  Check for VIM Target  ${vim_name}
58
59
60 Get VIM Targets
61     ${rc}  ${stdout}=  Run and Return RC and Output  osm vim-list
62     log  ${stdout}
63     Should Be Equal As Integers  ${rc}  ${success_return_code}
64
65
66 Check for VIM Target
67     [Arguments]  ${vim_name}
68
69     ${rc}  ${stdout}=  Run and Return RC and Output  osm vim-list | awk '{print $2}' | grep ${vim_name}
70     Should Not Be Equal As Strings  ${stdout}  ${vim_name}
71
72
73 Check for VIM Target Status
74     [Arguments]  ${vim_name}  ${prometheus_host}  ${prometheus_port}
75
76     ${vim_account_id}=  Get VIM Target ID  ${vim_name}
77     Wait Until Keyword Succeeds  ${vim_status_max_wait_time}  ${vim_status_pol_time}  Check If VIM Target Is Available  ${vim_account_id}  ${prometheus_host}  ${prometheus_port}
78
79
80 Get VIM Target ID
81     [Arguments]  ${vim_name}
82
83     ${rc}  ${stdout}=  Run and Return RC and Output  osm vim-list | grep " ${vim_name} " | awk '{print $4}'
84     Should Be Equal As Integers  ${rc}  ${success_return_code}
85     Should Not Be Equal As Strings  ${stdout}  ${EMPTY}  msg=VIM Target '${vim_name}' not found  values=false
86     [Return]  ${stdout}
87
88
89 Check If VIM Target Is Available
90     [Arguments]  ${vim_account_id}  ${prometheus_host}  ${prometheus_port}
91
92     ${metric}=  Get Metric  ${prometheus_host}  ${prometheus_port}  osm_vim_status  vim_account_id=${vim_account_id}
93     Should Be Equal As Integers  ${metric}  1  msg=VIM Target '${vim_account_id}' is not active  values=false