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