Bug 873: Robot Automation improvement: NS_CONFIG Provided via both 1. Using Environme...
[osm/devops.git] / robot-systest / lib / cli / ns_lib.robot
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2019 Tech Mahindra Limited
5 #
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 #         http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 ##
20
21 ## Change log:
22 # 1. Feature 7829: Jayant Madavi, Mrityunjay Yadav : MY00514913@techmahindra.com : 06-aug-2019 : Improvement to the code, robot framework initial seed code.
23 ##
24
25
26 *** Variables ***
27 ${success_return_code}    0
28 ${ns_launch_max_wait_time}    5min
29 ${ns_launch_pol_time}    30sec
30 ${ns_delete_max_wait_time}    1min
31 ${ns_delete_pol_time}    15sec
32 ${nsconfig}
33
34
35 *** Keywords ***
36 Get NS List
37     [Documentation]  Get ns instance list
38
39     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-list
40     log     ${stdout}
41     Should Be Equal As Integers    ${rc}    ${success_return_code}
42
43
44 Launch Network Services and Return
45     [Arguments]  ${vim_name}  ${ns_config}=''
46
47     Run Keyword If    ${ns_config}==''    Get NS Config
48     ...  ELSE  Set NS Config    ${ns_config}
49     Log To Console    \n${nsconfig}
50     Should Not Be Empty    ${nsd_ids}    There are no NS descriptors to launch the NS
51     :FOR    ${nsd}    IN    @{nsd_ids}
52     \    ${ns_name}=    GENERATE NAME
53     \    Append To List     ${ns_ids}       ${ns_name}
54     \    Create Network Service    ${nsd}   ${vim_name}    ${ns_name}    ${nsconfig}
55
56
57 Set NS Config
58     [Arguments]   ${ns_config}
59     ${nsconfig}=    Get Variable Value    ${ns_config}    ''
60     Set Test Variable    ${nsconfig}
61
62
63 Get NS Config
64     ${nsconfig}=    Get Environment Variable    NS_CONFIG    ''
65     Set Test Variable    ${nsconfig}
66
67
68 Create Network Service
69     [Documentation]  Create ns at osm
70     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}    ${ns_config}
71
72     Run Keyword If   ${ns_config}!=''   Create Network Service With Config    ${nsd}    ${vim_name}    ${ns_name}    ${ns_config}
73     ...    ELSE    Create Network Service Without Config    ${nsd}   ${vim_name}    ${ns_name}
74
75     WAIT UNTIL KEYWORD SUCCEEDS     ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
76     Check For NS Instance For Failure    ${ns_name}
77
78
79 Create Network Service Without Config
80     [Documentation]  Create ns at osm
81     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}
82
83     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-create --ns_name ${ns_name} --nsd_name ${nsd} --vim_account ${vim_name}
84     log     ${stdout}
85     Should Be Equal As Integers    ${rc}    ${success_return_code}
86
87
88 Create Network Service With Config
89     [Documentation]  Create ns at osm
90     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}    ${ns_config}
91
92     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-create --ns_name ${ns_name} --nsd_name ${nsd} --vim_account ${vim_name} --config ${ns_config}
93     log     ${stdout}
94     Should Be Equal As Integers    ${rc}    ${success_return_code}
95
96
97 Delete NS
98     [Documentation]  Delete ns
99     [Arguments]  ${ns}
100
101     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-delete ${ns}
102     log     ${stdout}
103     Should Be Equal As Integers    ${rc}    ${success_return_code}
104
105     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Delete   ${ns}
106
107
108 Check For NS Instance To Configured
109     [Arguments]  ${ns_name}
110
111     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-list --filter name="${ns_name}"
112     log     ${stdout}
113     Should Be Equal As Integers    ${rc}    ${success_return_code}
114     Should Contain Any      ${stdout}   configured    failed
115
116
117 Check For NS Instance For Failure
118     [Arguments]  ${ns_name}
119
120     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-list --filter name="${ns_name}"
121     log     ${stdout}
122     Should Be Equal As Integers    ${rc}    ${success_return_code}
123     Should Not Contain      ${stdout}   failed
124
125
126 Check For NS Instance To Be Delete
127     [Arguments]  ${ns}
128
129     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-list
130     log     ${stdout}
131     Should Be Equal As Integers    ${rc}    ${success_return_code}
132     Should Not Contain      ${stdout}   ${ns}
133
134
135 Force Delete NS
136     [Documentation]  Forcely Delete ns
137     [Arguments]  ${ns}
138
139     ${rc}   ${stdout}=      Run and Return RC and Output    osm ns-delete ${ns}
140     log     ${stdout}
141     Should Be Equal As Integers    ${rc}    ${success_return_code}
142     WAIT UNTIL KEYWORD SUCCEEDS    ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Delete   ${ns}