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