[RIC-571] Add Automation tests + bug fix in Setup of existing eNB flow
[ric-plt/e2mgr.git] / Automation / Tests / Resource / Keywords.robot
1 ##############################################################################
2 #
3 #   Copyright (c) 2019 AT&T Intellectual Property.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 ##############################################################################
18 #
19 #   This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 #   platform project (RICP).
21 #
22
23 *** Settings ***
24 Documentation   Keywords file
25 Library     ../Scripts/cleanup_db.py
26 Library     ../Scripts/k8s_helper.py
27 Resource   ../Resource/resource.robot
28 Library     OperatingSystem
29 Library     Process
30 Variables  ../Scripts/variables.py
31
32 *** Variables ***
33 ${e2adapter}  ${e2adapter_pod_name}
34
35 *** Keywords ***
36 Get Request nodeb
37     [Arguments]    ${nodeb_name}=${ranName}
38     Sleep    1s
39     GET      ${getNodeb}/${nodeb_name}
40
41 Update Gnb request
42     Sleep  1s
43     PUT    ${update_gnb_url}   ${update_gnb_body}
44
45 Add eNb Request
46     Sleep  1s
47     POST    ${enb_url}   ${add_enb_request_body}
48
49 Delete eNb Request
50     Sleep  1s
51     DELETE    ${enb_url}/${enb_ran_name}
52
53 Update eNb Request
54     Sleep  1s
55     PUT    ${enb_url}/${enb_ran_name}   ${update_enb_request_body}
56
57 Set General Configuration request
58     Sleep  1s
59     PUT    ${set_general_configuration}   ${set_general_configuration_body}
60
61 Update Gnb request not valid
62     Sleep  1s
63     PUT    ${update_gnb_url}   ${update_gnb_body_notvalid}
64
65 Remove log files
66     Remove File  ${EXECDIR}/${gnb_log_filename}
67     Remove File  ${EXECDIR}/${e2mgr_log_filename}
68     Remove File  ${EXECDIR}/${e2t_log_filename}
69
70 Save logs
71     Sleep   1s
72     Run     ${Save_sim_log}
73     Run     ${Save_e2mgr_log}
74     Run     ${Save_e2t_log}
75
76 Prepare Enviorment
77      [Arguments]     ${need_to_restart_pods}=${False}     ${set_new_timestamp}=${True}
78      Init logs
79      Flush And Populate DB    ${set_new_timestamp}
80      Run keyword if  ${need_to_restart_pods}==${True}   Restart RM and GNB Simulator
81      Wait until keyword succeeds  2 min    10 sec    Validate Required Dockers
82
83 Restart RM and GNB Simulator
84     Restart routing manager
85     Wait until keyword succeeds  2 min    10 sec    Validate Required Dockers
86     Restart simulator
87
88
89 Init logs
90     ${starting_timestamp}    Evaluate   datetime.datetime.now(datetime.timezone.utc).isoformat("T")   modules=datetime
91     ${e2t_log_filename}      Evaluate      "e2t.${SUITE NAME}.log".replace(" ","-")
92     ${e2mgr_log_filename}    Evaluate      "e2mgr.${SUITE NAME}.log".replace(" ","-")
93     ${gnb_log_filename}      Evaluate      "gnb.${SUITE NAME}.log".replace(" ","-")
94     ${Save_sim_log}          Evaluate  "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${gnbe2_sim_pod}) > ${gnb_log_filename}"
95     ${Save_e2mgr_log}        Evaluate   "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${e2mgr_pod}) > ${e2mgr_log_filename}"
96     ${Save_e2t_log}          Evaluate   "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${e2term_pod}) > ${e2t_log_filename}"
97     Set Suite Variable  ${e2t_log_filename}
98     Set Suite Variable  ${e2mgr_log_filename}
99     Set Suite Variable  ${gnb_log_filename}
100     Set Suite Variable  ${Save_sim_log}
101     Set Suite Variable  ${Save_e2mgr_log}
102     Set Suite Variable  ${Save_e2t_log}
103
104 Validate Required Dockers
105     [Arguments]    ${required_number_of_dockers}=${pods_number}
106     Log To Console  Validating all required dockers are up
107     ${result}=  Run And Return Rc And Output     ${verify_all_pods_are_ready_command}
108     Should Be Equal As Integers    ${result[1]}    ${required_number_of_dockers}
109
110 Start E2
111      Log to Console  Starting E2Term
112      Run And Return Rc And Output    ${start_e2}
113      Sleep  5s
114
115 Stop E2
116      Log to Console  Stopping E2Term
117      Run And Return Rc And Output    ${stop_e2}
118      Sleep  5s
119
120 Start E2 Manager
121      Log to Console  Starting E2Mgr
122      Run And Return Rc And Output    ${start_e2mgr}
123      Sleep  5s
124
125 Stop E2 Manager
126      Log to Console  Stopping E2Mgr
127      Run And Return Rc And Output    ${stop_e2mgr}
128      Sleep  5s
129
130 Start Dbass
131      Log to Console  Starting redis
132      Run And Return Rc And Output    ${dbass_start}
133      Sleep  5s
134
135 Stop Dbass
136      Log to Console  Stopping redis
137      Run And Return Rc And Output    ${dbass_stop}
138      Sleep  5s
139
140 Stop Simulator
141     log to console  Stopping gnbe2 simulator
142     Run And Return Rc And Output    ${stop_simu}
143     Sleep  90s
144
145 Start Simulator
146     log to console  Starting gnbe2 simulator
147     Run And Return Rc And Output    ${start_simu}
148
149 Restart simulator
150    Log to Console  Restarting gnbe2 simulator
151    Stop Simulator
152    Start Simulator
153
154 Start Routing Manager
155     Log to Console  Starting routing manager
156     Run And Return Rc And Output    ${start_routing_manager}
157     Sleep  5s
158
159 Stop Routing Manager
160     Log to Console  Stopping routing manager
161     Run And Return Rc And Output    ${stop_routing_manager}
162     Sleep  5s
163
164 Restart Routing Manager
165     Log to Console  Restarting routing manager
166     Stop Routing Manager
167     Start Routing Manager
168
169 Start e2adapter
170      Log to Console  Starting e2adapter
171      Run And Return Rc And Output    ${start_e2adapter}
172      Sleep  5s
173
174 Stop e2adapter
175      Log to Console  Stopping e2adapter
176      Run And Return Rc And Output    ${stop_e2adapter}
177      Sleep  5s
178
179 Flush And Populate DB
180     [Arguments]    ${set_new_timestamp}=${True}
181     Log To Console  Flushing and populating DB
182     ${flush}=  cleanup_db.flush    ${set_new_timestamp}
183     Sleep  2s
184     Should Be Equal As Strings  ${flush}  True
185
186 Stop All Pods Except Simulator
187     Stop E2 Manager
188     Stop Dbass
189     Stop E2
190     Stop Routing Manager
191     Stop e2adapter
192
193 Send eNB Setup Request
194     Log To Console  Sending eNB setup request form e2adapter
195     ${send_enb_setup}       Evaluate    "kubectl -n ricplt exec -it ${e2adapter} cli send-e2setup-req 10.0.2.15"
196     Sleep    3s
197     Run And Return Rc And Output    ${send_enb_setup}
198
199 Start Redis Monitor
200     Log To Console  Starting redis monitor log
201     ${redis_monitor_log_filename}      Evaluate      "redis_monitor.${SUITE NAME}.log".replace(" ","-")
202     Set Suite Variable  ${redis_monitor_log_filename}
203     Remove File  ${EXECDIR}/${redis_monitor_log_filename}
204     Start Process    kubectl -n ricplt exec -it statefulset-ricplt-dbaas-server-0 redis-cli MONITOR>${EXECDIR}/${redis_monitor_log_filename}  shell=yes
205
206 Stop Redis Monitor
207     Log To Console  Stopping redis monitor log
208     log_scripts.kill_redis_monitor_root_process
209
210
211 Redis Monitor Logs - Verify Publish To Manipulation Channel
212     [Arguments]       ${ran_name}    ${event}
213     Log To Console  Verify Publish To Manipulation Channel
214     Sleep    3s
215     ${result}=  log_scripts.verify_redis_monitor_manipulation_message   ${EXECDIR}/${redis_monitor_log_filename}  ${ran_name}    ${event}
216     Should Be Equal As Strings    ${result}      True
217
218 Redis Monitor Logs - Verify Publish To Connection Status Channel
219     [Arguments]       ${ran_name}    ${event}
220     Log To Console    Verify Publish To Connection Status Channel
221     Sleep    3s
222     ${result}=  log_scripts.verify_redis_monitor_connection_status_message   ${EXECDIR}/${redis_monitor_log_filename}  ${ran_name}    ${event}
223     Should Be Equal As Strings    ${result}      True
224
225 Redis Monitor Logs - Verify NOT Published To Manipulation Channel
226     [Arguments]       ${ran_name}    ${event}
227     Log To Console  Verify NOT Published To Manipulation Channel
228     Sleep    3s
229     ${result}=  log_scripts.verify_redis_monitor_manipulation_message   ${EXECDIR}/${redis_monitor_log_filename}  ${ran_name}    ${event}
230     Should Be Equal As Strings    ${result}      False