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 Delete eNb Request
56     Sleep  1s
57     DELETE    ${enb_url}/${enb_ran_name}
58
59 Update eNb Request
60     [Arguments]    ${request}=${update_enb_request_body}
61     Sleep  1s
62     PUT    ${enb_url}/${enb_ran_name}   ${request}
63
64 Set General Configuration request
65     Sleep  1s
66     PUT    ${set_general_configuration}   ${set_general_configuration_body}
67
68 Update Gnb request not valid
69     Sleep  1s
70     PUT    ${update_gnb_url}   ${update_gnb_body_notvalid}
71
72 Remove log files
73     Remove File  ${EXECDIR}/${gnb_log_filename}
74     Remove File  ${EXECDIR}/${e2mgr_log_filename}
75     Remove File  ${EXECDIR}/${e2t_log_filename}
76
77 Save logs
78     Sleep   1s
79     Run     ${Save_sim_log}
80     Run     ${Save_e2mgr_log}
81     Run     ${Save_e2t_log}
82
83 Prepare Enviorment
84      [Arguments]     ${need_to_restart_pods}=${False}     ${set_new_timestamp}=${True}
85      Init logs
86      Flush And Populate DB    ${set_new_timestamp}
87      Run keyword if  ${need_to_restart_pods}==${True}   Restart RM and GNB Simulator
88      Wait until keyword succeeds  2 min    10 sec    Validate Required Dockers
89
90 Restart RM and GNB Simulator
91     Restart routing manager
92     Wait until keyword succeeds  2 min    10 sec    Validate Required Dockers
93     Restart simulator
94
95
96 Init logs
97     ${starting_timestamp}    Evaluate   datetime.datetime.now(datetime.timezone.utc).isoformat("T")   modules=datetime
98     ${e2t_log_filename}      Evaluate      "e2t.${SUITE NAME}.log".replace(" ","-")
99     ${e2mgr_log_filename}    Evaluate      "e2mgr.${SUITE NAME}.log".replace(" ","-")
100     ${gnb_log_filename}      Evaluate      "gnb.${SUITE NAME}.log".replace(" ","-")
101     ${Save_sim_log}          Evaluate  "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${gnbe2_sim_pod}) > ${gnb_log_filename}"
102     ${Save_e2mgr_log}        Evaluate   "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${e2mgr_pod}) > ${e2mgr_log_filename}"
103     ${Save_e2t_log}          Evaluate   "kubectl -n ricplt logs --since-time=${starting_timestamp} $(${e2term_pod}) > ${e2t_log_filename}"
104     Set Suite Variable  ${e2t_log_filename}
105     Set Suite Variable  ${e2mgr_log_filename}
106     Set Suite Variable  ${gnb_log_filename}
107     Set Suite Variable  ${Save_sim_log}
108     Set Suite Variable  ${Save_e2mgr_log}
109     Set Suite Variable  ${Save_e2t_log}
110
111 Validate Required Dockers
112     [Arguments]    ${required_number_of_dockers}=${pods_number}
113     Log To Console  Validating all required dockers are up
114     ${result}=  Run And Return Rc And Output     ${verify_all_pods_are_ready_command}
115     Should Be Equal As Integers    ${result[1]}    ${required_number_of_dockers}
116
117 Start E2
118      Log to Console  Starting E2Term
119      Run And Return Rc And Output    ${start_e2}
120      Sleep  5s
121
122 Stop E2
123      Log to Console  Stopping E2Term
124      Run And Return Rc And Output    ${stop_e2}
125      Sleep  5s
126
127 Start E2 Manager
128      Log to Console  Starting E2Mgr
129      Run And Return Rc And Output    ${start_e2mgr}
130      Sleep  5s
131
132 Stop E2 Manager
133      Log to Console  Stopping E2Mgr
134      Run And Return Rc And Output    ${stop_e2mgr}
135      Sleep  5s
136
137 Start Dbass
138      Log to Console  Starting redis
139      Run And Return Rc And Output    ${dbass_start}
140      Sleep  5s
141
142 Stop Dbass
143      Log to Console  Stopping redis
144      Run And Return Rc And Output    ${dbass_stop}
145      Sleep  5s
146
147 Stop Simulator
148     log to console  Stopping gnbe2 simulator
149     Run And Return Rc And Output    ${stop_simu}
150     Sleep  90s
151
152 Start Simulator
153     log to console  Starting gnbe2 simulator
154     Run And Return Rc And Output    ${start_simu}
155
156 Restart simulator
157    Log to Console  Restarting gnbe2 simulator
158    Stop Simulator
159    Start Simulator
160
161 Start Routing Manager
162     Log to Console  Starting routing manager
163     Run And Return Rc And Output    ${start_routing_manager}
164     Sleep  5s
165
166 Stop Routing Manager
167     Log to Console  Stopping routing manager
168     Run And Return Rc And Output    ${stop_routing_manager}
169     Sleep  5s
170
171 Restart Routing Manager
172     Log to Console  Restarting routing manager
173     Stop Routing Manager
174     Start Routing Manager
175
176 Start e2adapter
177      Log to Console  Starting e2adapter
178      Run And Return Rc And Output    ${start_e2adapter}
179      Sleep  5s
180
181 Stop e2adapter
182      Log to Console  Stopping e2adapter
183      Run And Return Rc And Output    ${stop_e2adapter}
184      Sleep  90s
185
186 Restart e2adapter
187     Log to Console  Restarting e2adapter
188     Stop e2adapter
189     Start e2adapter
190
191 Flush And Populate DB
192     [Arguments]    ${set_new_timestamp}=${True}
193     Log To Console  Flushing and populating DB
194     ${flush}=  cleanup_db.flush    ${set_new_timestamp}
195     Sleep  2s
196     Should Be Equal As Strings  ${flush}  True
197
198 Stop All Pods Except Simulator
199     Stop E2 Manager
200     Stop Dbass
201     Stop E2
202     Stop Routing Manager
203     Stop e2adapter
204
205 Send eNB Setup Request
206     Log To Console  Sending eNB setup request form e2adapter
207     Restart e2adapter
208     Wait until keyword succeeds  2 min    3 sec    Validate Required Dockers
209     ${e2adapter_pod} =    Run And Return Rc And Output   kubectl get pods -n ricplt | /bin/grep e2adapter | /bin/grep Running | awk '{{print $1}}'
210     ${send_enb_setup}    Evaluate    "kubectl -n ricplt exec -it ${e2adapter_pod[1]} cli send-e2setup-req 10.0.2.15"
211     Run And Return Rc And Output    ${send_enb_setup}
212
213 Start Redis Monitor
214     Log To Console  Starting redis monitor log
215     ${redis_monitor_log_filename}      Evaluate      "redis_monitor.${SUITE NAME}.log".replace(" ","-")
216     Set Suite Variable  ${redis_monitor_log_filename}
217     Remove File  ${EXECDIR}/${redis_monitor_log_filename}
218     Start Process    kubectl -n ricplt exec -it statefulset-ricplt-dbaas-server-0 redis-cli MONITOR>${EXECDIR}/${redis_monitor_log_filename}  shell=yes
219
220 Stop Redis Monitor
221     Log To Console  Stopping redis monitor log
222     log_scripts.kill_redis_monitor_root_process
223
224
225 Redis Monitor Logs - Verify Publish To Manipulation Channel
226     [Arguments]       ${ran_name}    ${event}
227     Log To Console  Verify Publish 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}      True
231
232 Redis Monitor Logs - Verify Publish To Connection Status Channel
233     [Arguments]       ${ran_name}    ${event}
234     Log To Console    Verify Publish To Connection Status Channel
235     Sleep    3s
236     ${result}=  log_scripts.verify_redis_monitor_connection_status_message   ${EXECDIR}/${redis_monitor_log_filename}  ${ran_name}    ${event}
237     Should Be Equal As Strings    ${result}      True
238
239 Redis Monitor Logs - Verify NOT Published To Manipulation Channel
240     [Arguments]       ${ran_name}    ${event}
241     Log To Console  Verify NOT Published To Manipulation Channel
242     Sleep    3s
243     ${result}=  log_scripts.verify_redis_monitor_manipulation_message   ${EXECDIR}/${redis_monitor_log_filename}  ${ran_name}    ${event}
244     Should Be Equal As Strings    ${result}      False