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