Install latest stable version of Juju
[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
33
34 *** Keywords ***
35 Get NS List
36     [Documentation]  Get ns instance list
37
38     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-list
39     log     ${stdout}
40     Should Be Equal As Integers         ${rc}   ${success_return_code}
41
42
43 Launch Network Services and Return
44     [Arguments]  ${vim_name}
45         
46         Should Not Be Empty    ${nsd_ids}    There are no NS descriptors to launch the NS
47     :FOR    ${nsd}    IN    @{nsd_ids}
48     \    ${ns_name}=    GENERATE NAME
49     \    Append To List     ${ns_ids}       ${ns_name}
50     \    Create Network Service    ${nsd}   ${vim_name}    ${ns_name}
51     \    Delete NS   ${ns_name}
52
53         
54 Create Network Service
55     [Documentation]  Create ns at osm
56     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}
57
58     ${ns_config}=   Get Environment Variable    NS_CONFIG    ${EMPTY}
59         Run Keyword If   ${ns_config}!='${EMPTY}'   Create Network Service With Config    ${nsd}    ${vim_name}    ${ns_name}    ${ns_config}
60         ...    ELSE    Create Network Service Without Config    ${nsd}   ${vim_name}    ${ns_name}
61         
62     WAIT UNTIL KEYWORD SUCCEEDS     ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
63     Check For NS Instance For Failure    ${ns_name}
64         
65
66 Create Network Service Without Config
67     [Documentation]  Create ns at osm
68     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}
69
70     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-create --ns_name ${ns_name} --nsd_name ${nsd} --vim_account ${vim_name}
71     log     ${stdout}
72     Should Be Equal As Integers         ${rc}   ${success_return_code}
73
74
75 Create Network Service With Config
76     [Documentation]  Create ns at osm
77     [Arguments]  ${nsd}   ${vim_name}    ${ns_name}    ${ns_config}
78
79     ${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}
80     log     ${stdout}
81     Should Be Equal As Integers         ${rc}   ${success_return_code}
82
83         
84 Delete NS
85     [Documentation]  Delete ns
86     [Arguments]  ${ns}
87
88     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-delete ${ns}
89     log     ${stdout}
90     Should Be Equal As Integers         ${rc}   ${success_return_code}
91
92     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Delete   ${ns}
93
94
95 Check For NS Instance To Configured
96     [Arguments]  ${ns_name}
97
98     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-list --filter name="${ns_name}"
99     log     ${stdout}
100     Should Be Equal As Integers         ${rc}   ${success_return_code}
101     Should Contain Any      ${stdout}   configured    failed
102
103
104 Check For NS Instance For Failure
105     [Arguments]  ${ns_name}
106
107     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-list --filter name="${ns_name}"
108     log     ${stdout}
109     Should Be Equal As Integers         ${rc}   ${success_return_code}
110     Should Not Contain      ${stdout}   failed
111
112
113 Check For NS Instance To Be Delete
114     [Arguments]  ${ns}
115
116     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-list
117     log     ${stdout}
118     Should Be Equal As Integers         ${rc}   ${success_return_code}
119     Should Not Contain      ${stdout}   ${ns}
120
121
122 Force Delete NS
123     [Documentation]  Forcely Delete ns
124     [Arguments]  ${ns}
125
126     ${rc}   ${stdout}=      Run and Return RC and Output            osm ns-delete ${ns}
127     log     ${stdout}
128     Should Be Equal As Integers         ${rc}   ${success_return_code}
129     WAIT UNTIL KEYWORD SUCCEEDS    ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Delete   ${ns}