resync tests/charmhelpers for updated svc restarted checks

This commit is contained in:
Ryan Beisner 2015-08-27 17:59:57 +00:00
parent 2039aa5ede
commit 8035665b9a
2 changed files with 42 additions and 26 deletions

View File

@ -543,7 +543,6 @@ class NeutronAPIBasicDeployment(OpenStackAmuletDeployment):
u.log.debug("Checking that service restarted: {}".format(s)) u.log.debug("Checking that service restarted: {}".format(s))
if not u.validate_service_config_changed(sentry, mtime, s, if not u.validate_service_config_changed(sentry, mtime, s,
conf_file, conf_file,
pgrep_full=True,
retry_count=4, retry_count=4,
retry_sleep_time=20, retry_sleep_time=20,
sleep_time=20): sleep_time=20):

View File

@ -269,27 +269,27 @@ class AmuletUtils(object):
"""Get last modification time of directory.""" """Get last modification time of directory."""
return sentry_unit.directory_stat(directory)['mtime'] return sentry_unit.directory_stat(directory)['mtime']
def _get_proc_start_time(self, sentry_unit, service, pgrep_full=False): def _get_proc_start_time(self, sentry_unit, service, pgrep_full=None):
"""Get process' start time. """Get start time of a process based on the last modification time
of the /proc/pid directory.
Determine start time of the process based on the last modification
time of the /proc/pid directory. If pgrep_full is True, the process
name is matched against the full command line.
""" """
if pgrep_full: if pgrep_full is True or pgrep_full is False:
cmd = 'pgrep -o -f {}'.format(service) # /!\ DEPRECATION WARNING (beisner):
else: # No longer implemented, as pidof is now used instead of pgrep.
cmd = 'pgrep -o {}'.format(service) # https://bugs.launchpad.net/charm-helpers/+bug/1474030
cmd = cmd + ' | grep -v pgrep || exit 0' self.log.warn('/!\\ DEPRECATION WARNING: pgrep_full bool is no '
cmd_out = sentry_unit.run(cmd) 'longer implemented re: lp 1474030.')
self.log.debug('CMDout: ' + str(cmd_out))
if cmd_out[0]: pid_list = self.get_process_id_list(sentry_unit, service)
self.log.debug('Pid for %s %s' % (service, str(cmd_out[0]))) pid = pid_list[0]
proc_dir = '/proc/{}'.format(cmd_out[0].strip()) proc_dir = '/proc/{}'.format(pid)
return self._get_dir_mtime(sentry_unit, proc_dir) self.log.debug('Pid for {} on {}: {}'.format(
service, sentry_unit.info['unit_name'], pid))
return self._get_dir_mtime(sentry_unit, proc_dir)
def service_restarted(self, sentry_unit, service, filename, def service_restarted(self, sentry_unit, service, filename,
pgrep_full=False, sleep_time=20): pgrep_full=None, sleep_time=20):
"""Check if service was restarted. """Check if service was restarted.
Compare a service's start time vs a file's last modification time Compare a service's start time vs a file's last modification time
@ -299,6 +299,11 @@ class AmuletUtils(object):
# /!\ DEPRECATION WARNING (beisner): # /!\ DEPRECATION WARNING (beisner):
# This is prone to races in that no before-time is known. # This is prone to races in that no before-time is known.
# Use validate_service_config_changed instead. # Use validate_service_config_changed instead.
# NOTE(beisner) pgrep_full is no longer implemented, as pidof is now
# used instead of pgrep. pgrep_full is still passed through to ensure
# deprecation WARNS. lp1474030
self.log.warn('/!\\ DEPRECATION WARNING: use ' self.log.warn('/!\\ DEPRECATION WARNING: use '
'validate_service_config_changed instead of ' 'validate_service_config_changed instead of '
'service_restarted due to known races.') 'service_restarted due to known races.')
@ -311,7 +316,7 @@ class AmuletUtils(object):
return False return False
def service_restarted_since(self, sentry_unit, mtime, service, def service_restarted_since(self, sentry_unit, mtime, service,
pgrep_full=False, sleep_time=20, pgrep_full=None, sleep_time=20,
retry_count=2, retry_sleep_time=30): retry_count=2, retry_sleep_time=30):
"""Check if service was been started after a given time. """Check if service was been started after a given time.
@ -319,7 +324,7 @@ class AmuletUtils(object):
sentry_unit (sentry): The sentry unit to check for the service on sentry_unit (sentry): The sentry unit to check for the service on
mtime (float): The epoch time to check against mtime (float): The epoch time to check against
service (string): service name to look for in process table service (string): service name to look for in process table
pgrep_full (boolean): Use full command line search mode with pgrep pgrep_full: No longer implemented, passed for WARNs
sleep_time (int): Seconds to sleep before looking for process sleep_time (int): Seconds to sleep before looking for process
retry_count (int): If service is not found, how many times to retry retry_count (int): If service is not found, how many times to retry
@ -328,8 +333,12 @@ class AmuletUtils(object):
False if service is older than mtime or if service was False if service is older than mtime or if service was
not found. not found.
""" """
# NOTE(beisner) pgrep_full is no longer implemented, as pidof is now
# used instead of pgrep. pgrep_full is still passed through to ensure
# deprecation WARNS. lp1474030
unit_name = sentry_unit.info['unit_name'] unit_name = sentry_unit.info['unit_name']
self.log.debug('Checking %s restarted since %s on ' self.log.debug('Checking that %s service restarted since %s on '
'%s' % (service, mtime, unit_name)) '%s' % (service, mtime, unit_name))
time.sleep(sleep_time) time.sleep(sleep_time)
proc_start_time = None proc_start_time = None
@ -378,12 +387,15 @@ class AmuletUtils(object):
bool: True if file was modified more recently than mtime, False if bool: True if file was modified more recently than mtime, False if
file was modified before mtime, file was modified before mtime,
""" """
self.log.debug('Checking %s updated since %s' % (filename, mtime)) self.log.debug('Checking that %s file updated since '
'%s' % (filename, mtime))
unit_name = sentry_unit.info['unit_name']
time.sleep(sleep_time) time.sleep(sleep_time)
file_mtime = self._get_file_mtime(sentry_unit, filename) file_mtime = self._get_file_mtime(sentry_unit, filename)
if file_mtime >= mtime: if file_mtime >= mtime:
self.log.debug('File mtime is newer than provided mtime ' self.log.debug('File mtime is newer than provided mtime '
'(%s >= %s)' % (file_mtime, mtime)) '(%s >= %s) on %s (OK)' % (file_mtime, mtime,
unit_name))
return True return True
else: else:
self.log.warn('File mtime %s is older than provided mtime %s' self.log.warn('File mtime %s is older than provided mtime %s'
@ -391,7 +403,7 @@ class AmuletUtils(object):
return False return False
def validate_service_config_changed(self, sentry_unit, mtime, service, def validate_service_config_changed(self, sentry_unit, mtime, service,
filename, pgrep_full=False, filename, pgrep_full=None,
sleep_time=20, retry_count=2, sleep_time=20, retry_count=2,
retry_sleep_time=30): retry_sleep_time=30):
"""Check service and file were updated after mtime """Check service and file were updated after mtime
@ -401,7 +413,7 @@ class AmuletUtils(object):
mtime (float): The epoch time to check against mtime (float): The epoch time to check against
service (string): service name to look for in process table service (string): service name to look for in process table
filename (string): The file to check mtime of filename (string): The file to check mtime of
pgrep_full (boolean): Use full command line search mode with pgrep pgrep_full: No longer implemented, passed for WARNs
sleep_time (int): Initial sleep in seconds to pass to test helpers sleep_time (int): Initial sleep in seconds to pass to test helpers
retry_count (int): If service is not found, how many times to retry retry_count (int): If service is not found, how many times to retry
retry_sleep_time (int): Time in seconds to wait between retries retry_sleep_time (int): Time in seconds to wait between retries
@ -421,6 +433,11 @@ class AmuletUtils(object):
mtime, False if service is older than mtime or if service was mtime, False if service is older than mtime or if service was
not found or if filename was modified before mtime. not found or if filename was modified before mtime.
""" """
# NOTE(beisner) pgrep_full is no longer implemented, as pidof is now
# used instead of pgrep. pgrep_full is still passed through to ensure
# deprecation WARNS. lp1474030
service_restart = self.service_restarted_since( service_restart = self.service_restarted_since(
sentry_unit, mtime, sentry_unit, mtime,
service, service,