169
169
cmd = 'pgrep -o -f {}'.format(service)
171
171
cmd = 'pgrep -o {}'.format(service)
172
proc_dir = '/proc/{}'.format(sentry_unit.run(cmd)[0].strip())
173
return self._get_dir_mtime(sentry_unit, proc_dir)
172
cmd = cmd + ' | grep -v pgrep || exit 0'
173
cmd_out = sentry_unit.run(cmd)
174
self.log.debug('CMDout: ' + str(cmd_out))
176
self.log.debug('Pid for %s %s' % (service, str(cmd_out[0])))
177
proc_dir = '/proc/{}'.format(cmd_out[0].strip())
178
return self._get_dir_mtime(sentry_unit, proc_dir)
175
180
def service_restarted(self, sentry_unit, service, filename,
176
181
pgrep_full=False, sleep_time=20):
195
def service_restarted_since(self, sentry_unit, mtime, service,
196
pgrep_full=False, sleep_time=20,
198
"""Check if service was been started after a given time.
201
sentry_unit (sentry): The sentry unit to check for the service on
202
mtime (float): The epoch time to check against
203
service (string): service name to look for in process table
204
pgrep_full (boolean): Use full command line search mode with pgrep
205
sleep_time (int): Seconds to sleep before looking for process
206
retry_count (int): If service is not found, how many times to retry
209
bool: True if service found and its start time it newer than mtime,
210
False if service is older than mtime or if service was
213
self.log.debug('Checking %s restarted since %s' % (service, mtime))
214
time.sleep(sleep_time)
215
proc_start_time = self._get_proc_start_time(sentry_unit, service,
217
while retry_count > 0 and not proc_start_time:
218
self.log.debug('No pid file found for service %s, will retry %i '
219
'more times' % (service, retry_count))
221
proc_start_time = self._get_proc_start_time(sentry_unit, service,
223
retry_count = retry_count - 1
225
if not proc_start_time:
226
self.log.warn('No proc start time found, assuming service did '
229
if proc_start_time >= mtime:
230
self.log.debug('proc start time is newer than provided mtime'
231
'(%s >= %s)' % (proc_start_time, mtime))
234
self.log.warn('proc start time (%s) is older than provided mtime '
235
'(%s), service did not restart' % (proc_start_time,
239
def config_updated_since(self, sentry_unit, filename, mtime,
241
"""Check if file was modified after a given time.
244
sentry_unit (sentry): The sentry unit to check the file mtime on
245
filename (string): The file to check mtime of
246
mtime (float): The epoch time to check against
247
sleep_time (int): Seconds to sleep before looking for process
250
bool: True if file was modified more recently than mtime, False if
251
file was modified before mtime,
253
self.log.debug('Checking %s updated since %s' % (filename, mtime))
254
time.sleep(sleep_time)
255
file_mtime = self._get_file_mtime(sentry_unit, filename)
256
if file_mtime >= mtime:
257
self.log.debug('File mtime is newer than provided mtime '
258
'(%s >= %s)' % (file_mtime, mtime))
261
self.log.warn('File mtime %s is older than provided mtime %s'
262
% (file_mtime, mtime))
265
def validate_service_config_changed(self, sentry_unit, mtime, service,
266
filename, pgrep_full=False,
267
sleep_time=20, retry_count=2):
268
"""Check service and file were updated after mtime
271
sentry_unit (sentry): The sentry unit to check for the service on
272
mtime (float): The epoch time to check against
273
service (string): service name to look for in process table
274
filename (string): The file to check mtime of
275
pgrep_full (boolean): Use full command line search mode with pgrep
276
sleep_time (int): Seconds to sleep before looking for process
277
retry_count (int): If service is not found, how many times to retry
280
u = OpenStackAmuletUtils(ERROR)
282
mtime = u.get_sentry_time(self.cinder_sentry)
283
self.d.configure('cinder', {'verbose': 'True', 'debug': 'True'})
284
if not u.validate_service_config_changed(self.cinder_sentry,
287
'/etc/cinder/cinder.conf')
288
amulet.raise_status(amulet.FAIL, msg='update failed')
290
bool: True if both service and file where updated/restarted after
291
mtime, False if service is older than mtime or if service was
292
not found or if filename was modified before mtime.
294
self.log.debug('Checking %s restarted since %s' % (service, mtime))
295
time.sleep(sleep_time)
296
service_restart = self.service_restarted_since(sentry_unit, mtime,
298
pgrep_full=pgrep_full,
300
retry_count=retry_count)
301
config_update = self.config_updated_since(sentry_unit, filename, mtime,
303
return service_restart and config_update
305
def get_sentry_time(self, sentry_unit):
306
"""Return current epoch time on a sentry"""
308
return float(sentry_unit.run(cmd)[0])
190
310
def relation_error(self, name, data):
191
311
return 'unexpected relation data in {} - {}'.format(name, data)