blob: 8cbccbc0f46dde13b947cefa50a19cdcbe0c5034 [file] [log] [blame]
Thiyagarajan Subramanie84935d2020-04-23 17:45:44 +05301#!/bin/bash
2
3#Copyright 2018-present Open Networking Foundation
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### BEGIN INIT INFO
18# Provides: validate_onl_installation.sh
19# Required-Start: $all
20# Required-Stop: $network $local_fs $syslog
21# Default-Start: 2 3 4 5
22# Default-Stop: 0 1 6
23# Short-Description: This script validates ONL installation by checking if expected interfaces and
24# services are UP and RUNNING.
25# Description:
26# Following are the interafces and services considered for validation:
27# 1. Based on the device type(asfvolt16/asgvolt64) this script validates whether
28# eth2.<VLAN_ID>/eth1.<VLAN_ID> is up and running
29# 3. Validate system services
30# a. openolt driver
31# b. dev_mgmt_daemon
32# c. onlp
33# d. sshd
34# e. dhclient
35# returns the current status if service is up or not.
36### END INIT INFO
37
38#------------------------------------------------------------------------------
39# GLOBAL VARIABLES
40#------------------------------------------------------------------------------
41
42# Time interval in seconds to execute each function call for validation.
43TIME_INTERVAL=2
44
45# Total time required to validate all services.
46TOTAL_VALIDATION_TIME=20
47
48# Root path where required bal directories are located
49BRCM_DIR='/broadcom'
50
51# Path to vlan config file
52VLAN_CONFIG_FILE="${BRCM_DIR}/vlan.config"
53
54# vlan id for asfvolt16
55ASFVOLT16_VLAN_ID_ETH2=
56
57# vlan id for asgvolt64
58ASGVOLT64_VLAN_ID_ETH1=
59
60OLT_MODEL=$(cat /sys/devices/virtual/dmi/id/board_name)
61ASF16_MODEL="ASXvOLT16"
62# interfaces
63ETH1=eth1
64ETH2=eth2
65
66#------------------------------------------------------------------------------
67# Function Name: does_logger_exist
68# Description:
69# This function check if logger exist and executable.
70#
71# Globals:
72# None
73#
74# Arguments:
75# None
76#
77# Returns:
78# returns 0 if exist and executable else 1
79#------------------------------------------------------------------------------
80does_logger_exist()
81{
82cmd=/usr/bin/logger
83if [ -x ${cmd} ]; then
84 return 0
85 else
86 return 1
87 fi
88}
89
90#------------------------------------------------------------------------------
91# Function Name: info_message
92# Description:
93# This function print the info message information to the console
94#
95# Globals:
96# None
97#
98# Arguments:
99# string message
100#
101# Returns:
102# None
103#------------------------------------------------------------------------------
104info_message()
105{
106 echo "INFO: $1"
107 logger -p user.info "$1"
108}
109
110#------------------------------------------------------------------------------
111# Function Name: error_message
112# Description:
113# This function print the error message information to the console
114#
115# Globals:
116# None
117#
118# Arguments:
119# string message
120#
121# Returns:
122# returns 1
123#------------------------------------------------------------------------------
124error_message()
125{
126 echo "ERROR: $1"
127 logger -p user.err "$1"
128 return 1
129}
130
131#------------------------------------------------------------------------------
132# Function Name: is_interface_up_running
133# Description:
134# This function validate the interface whether it is UP and RUNNING or DOWN.
135#
136# Globals:
137# None
138#
139# Arguments:
140# interface name
141#
142# Returns:
143# returns 0 if interface is up and running and returns 1 if interface is down
144#------------------------------------------------------------------------------
145is_interface_up_running()
146{
147 info_message "Validating interface - $1"
148 interface_name=$1
149 ifconfig ${interface_name} | grep -q "UP BROADCAST RUNNING MULTICAST"
150 if [ $? -eq 0 ]; then
151 info_message "${interface_name} UP & RUNNING"
152 echo "---------------------------------------------------------------------"
153 return 0
154 else
155 error_message "${interface_name} is DOWN"
156 echo "---------------------------------------------------------------------"
157 return 1
158 fi
159}
160
161#------------------------------------------------------------------------------
162# Function Name : validate_interfaces
163# Description:
164# This function validate interfaces ${ETH2}.${ASFVOLT16_VLAN_ID_ETH2} and
165# ${ETH3}.${ASFVOLT16_VLAN_ID_ETH3} or ${ETH1}.${ASGVOLT64_VLAN_ID_ETH1} and
166# ${ETH2}.${ASGVOLT64_VLAN_ID_ETH2} based on OLT model.
167# Basically it validates if these interfaces are UP and RUNNING or not
168#
169# Globals:
170# ASFVOLT16_VLAN_ID_ETH2, ASFVOLT16_VLAN_ID_ETH3, ASGVOLT64_VLAN_ID_ETH1,
171# ASGVOLT64_VLAN_ID_ETH2, ETH1, ETH2, ETH3
172#
173#
174# Arguments:
175# None
176#
177# Returns:
178# return 1 if interface are down else returns 0
179#------------------------------------------------------------------------------
180validate_interfaces()
181{
182 # Validating interfaces whether they are UP and RUNNING or not
183 if [ "${OLT_MODEL}" = ${ASF16_MODEL} ]; then
184 is_interface_up_running ${ETH2}.${ASFVOLT16_VLAN_ID_ETH2}
185 if [ $? -eq 0 ]; then
186 return 0
187 else
188 return 1
189 fi
190 else
191 is_interface_up_running ${ETH1}.${ASGVOLT64_VLAN_ID_ETH1}
192 if [ $? -eq 0 ]; then
193 return 0
194 else
195 return 1
196 fi
197 fi
198}
199
200#------------------------------------------------------------------------------
201# Function Name: validate_system_services
202# Description:
203# This function checks if the below services/processes are running or not.
204# 1. dev_mgmt_daemon
205# 2. openolt
206# 3. onlp
207# 4. sshd
208# 5. dhclient
209# Globals:
210# ASFVOLT16_VLAN_ID_ETH2, ASFVOLT16_VLAN_ID_ETH3, ASGVOLT64_VLAN_ID_ETH1,
211# ASGVOLT64_VLAN_ID_ETH2, ETH1, ETH2, ETH3
212#
213#
214# Arguments:
215# None
216#
217# Returns:
218# returns 0
219#------------------------------------------------------------------------------
220validate_system_services()
221{
222 echo "---------------------------------------------------------------------"
223 echo "Validating Services"
224 echo "---------------------------------------------------------------------"
225
226 dhclient_interface dhclient_val1
227 for service_name in dev_mgmt_daemon openolt onlpd ssh ${dhclient_val1}
228 do
229 echo "---------------------------------------------------------------------"
230 ps -ef | grep -v grep | grep ${service_name}
231 #service ${service_name} status
232 if [ $? -eq 0 ]; then
233 info_message "${service_name} service is running"
234 else
235 error_message "${service_name} is not running"
236 return 1
237 fi
238 echo "---------------------------------------------------------------------"
239 done
240 return 0
241}
242
243#------------------------------------------------------------------------------
244# Function Name: dhclient_interface
245# Description:
246# This function sets values to which tagged interface dhclient service need
247# to be tested based on the OLT model package.
248#
249# Globals:
250# ASFVOLT16_VLAN_ID_ETH2, ASFVOLT16
251# ASGVOLT64_VLAN_ID_ETH1, ETH1, ETH2
252#
253# Arguments:
254# None
255#
256# Returns:
257# None
258#------------------------------------------------------------------------------
259dhclient_interface()
260{
261 local value1=$1
262 if [ "${OLT_MODEL}" = ${ASF16_MODEL} ]; then
263 dhclient1=dhclient.${ETH2}.${ASFVOLT16_VLAN_ID_ETH2}
264 eval $value1="'$dhclient1'"
265 else
266 dhclient2=dhclient.${ETH1}.${ASGVOLT64_VLAN_ID_ETH1}
267 eval $value1="'$dhclient2'"
268 fi
269
270}
271
272#------------------------------------------------------------------------------
273# Function Name: check_services
274# Description:
275# This function checks if the expected services like onlp, sshd, dev_mgmt_daemon, dhclient
276# and also checks that physical and vlan interfaces are up.
277# This script times out and returns an error code of 1 if all vaildations don't turn out to be successful
278# in counter a number is equal to 20
279#
280# Globals:
281# VLAN_CONFIG_FILE, ASFVOLT16_VLAN_ID_ETH2, ASGVOLT64_VLAN_ID_ETH1,
282# TIME_INTERVAL, ASFVOLT16
283#
284# Arguments:
285# None
286#
287# Returns:
288# None
289#------------------------------------------------------------------------------
290check_services()
291{
292 if [ -f ${VLAN_CONFIG_FILE} ]; then
293 ASFVOLT16_VLAN_ID_ETH2=$(awk '/asfvolt16_vlan_id_eth2/{print $0}' ${VLAN_CONFIG_FILE} | awk -F "=" '{print $2}')
294 ASGVOLT64_VLAN_ID_ETH1=$(awk '/asgvolt64_vlan_id_eth1/{print $0}' ${VLAN_CONFIG_FILE} | awk -F "=" '{print $2}')
295 if [ "${OLT_MODEL}" = ${ASF16_MODEL} ]; then
296 if [ ${ASFVOLT16_VLAN_ID_ETH2} -gt 4094 ] || [ ${ASFVOLT16_VLAN_ID_ETH2} -lt 1 ]; then
297 error_message "vlan ids not in range"
298 exit 1
299 fi
300 else
301 if [ ${ASGVOLT64_VLAN_ID_ETH1} -gt 4094 ] || [ ${ASGVOLT64_VLAN_ID_ETH1} -lt 1 ]; then
302 error_message "vlan ids not in range"
303 exit 1
304 fi
305 fi
306 else
307 error_message "${VLAN_CONFIG_FILE} does not exist"
308 exit 1
309 fi
310 echo "*********************************************************************"
311 info_message "Validating ONL Installation"
312 echo "*********************************************************************"
313 for func_name in validate_interfaces validate_system_services
314 do
315 counter=0
316 while true; do
317 sleep ${TIME_INTERVAL}
318 $func_name
319 if [ $? -eq 0 ]; then
320 break
321 fi
322 if [ $counter -eq $TOTAL_VALIDATION_TIME ]; then
323 error_message "Time out ,vlan interfaces or all services may not be up"
324 return 1
325 fi
326 counter=$((counter+${TIME_INTERVAL}))
327 done
328 done
329 return 0
330}
331
332does_logger_exist
333if [ $? -eq 0 ]; then
334 check_services
335else
336 error_message "logger does not exist"
337 exit 1
338fi