VAT-to-PAPI: VPPCounters
[csit.git] / resources / libraries / robot / robot_enhancements.robot
1 # Copyright (c) 2018 Cisco and/or its affiliates.
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 *** Settings ***
15 | Documentation
16 | ... | Place to store general keywords, similar to ones in BuiltIn library.
17 | Library | OperatingSystem
18 | Library | String
19
20 *** Keywords ***
21 | Ensure Global Variable
22 | | [Documentation] | Give default value (from environment or code) to variable.
23 | | ...
24 | | ... | Ideally we would just use Variables table to set global variables.
25 | | ... | Unfortunately, __init__ files are special (among other things)
26 | | ... | by the fact that variables set in the table are not available
27 | | ... | for (sub)directory suites.
28 | | ... | Therefore we are using BuiltIn.Set_Global_Variable explicitly.
29 | | ... | While we are running code here, we allow environment variables
30 | | ... | to override the default values.
31 | | ... | If environment variable name is not specified (or empty),
32 | | ... | the upper case of the variable name is used, prefixed by "CSIT_".
33 | | ... | The --variable parameter to pybot takes precedence to environment.
34 | | ...
35 | | ... | *Arguments:*
36 | | ... | - variable_name - Name of global variable to set. Type: string
37 | | ... | - default_value - Value to set if not set otherwise. Type: string
38 | | ... | - env_var_name - Name of environment variable to read. Type: string
39 | | ... | - application - Prefix for default environment variable. Type: string
40 | | ...
41 | | ... | *Example:*
42 | | ... | \| Ensure Global Variable \| perf_trial_duration \| 10.0 \| TRIAL_DUR
43 | | ...
44 | | [Arguments] | ${variable_name} | ${default_value} | ${env_var_name}=${EMPTY}
45 | | ... | ${application}=CSIT
46 | | ...
47 | | ${env_var_length} = | Get Length | ${env_var_name}
48 | | ${default_env_var} = | Convert To Uppercase | ${variable_name}
49 | | ${env_var} = | Set Variable If | ${env_var_length}
50 | | ... | ${env_var_name} | ${application}_${default_env_var}
51 | | ${updated_default} = | Get Environment Variable
52 | | ... | ${env_var} | ${default_value}
53 | | ${final_value} = | Get Variable Value
54 | | ... | \${${variable_name}} | ${updated_default}
55 | | Set Global Variable | \${${variable_name}} | ${final_value}