Charmhelper sync and move to using charm helper service restart check

This commit is contained in:
Liam Young 2015-02-18 10:13:00 +00:00
parent 85aa81ebfc
commit 8fb25fce43
5 changed files with 66 additions and 49 deletions

View File

@ -22,7 +22,7 @@ bin/charm_helpers_sync.py:
> bin/charm_helpers_sync.py > bin/charm_helpers_sync.py
sync: bin/charm_helpers_sync.py sync: bin/charm_helpers_sync.py
@$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-hooks.yaml # @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-hooks.yaml
@$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-tests.yaml @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-tests.yaml
publish: lint unit_test publish: lint unit_test

View File

@ -1,4 +1,4 @@
branch: lp:charm-helpers branch: lp:~gnuoy/charm-helpers/1422386
destination: tests/charmhelpers destination: tests/charmhelpers
include: include:
- contrib.amulet - contrib.amulet

View File

@ -103,41 +103,41 @@ class CinderBasicDeployment(OpenStackAmuletDeployment):
# Wait for relations to settle # Wait for relations to settle
sleep(120) sleep(120)
def service_restarted(self, sentry_unit, service, filename, # def service_restarted(self, sentry_unit, service, filename,
pgrep_full=False, sleep_time=60): # pgrep_full=False, sleep_time=60):
"""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
(such as a config file for that service) to determine if the service # (such as a config file for that service) to determine if the service
has been restarted (within 60s by default), return when verified.""" # has been restarted (within 60s by default), return when verified."""
#
# NOTE(beisner): prev rev utilized sleep_time as an arbitrary wait with # # NOTE(beisner): prev rev utilized sleep_time as an arbitrary wait with
# no debug feedback. Added checking timeout loop logic & debug output. # # no debug feedback. Added checking timeout loop logic & debug output.
# Increased default timeout to 60s due to test failures. # # Increased default timeout to 60s due to test failures.
#
# NOTE(beisner): need to move to charmhelpers, and adjust calls here. # # NOTE(beisner): need to move to charmhelpers, and adjust calls here.
# It is backward compatible with prev rev by coreycb. # # It is backward compatible with prev rev by coreycb.
#
proc_start_time = u._get_proc_start_time(sentry_unit, # proc_start_time = u._get_proc_start_time(sentry_unit,
service, pgrep_full) # service, pgrep_full)
file_mtime = u._get_file_mtime(sentry_unit, filename) # file_mtime = u._get_file_mtime(sentry_unit, filename)
#
tries = 0 # tries = 0
while proc_start_time < file_mtime and tries < (sleep_time/30): # while proc_start_time < file_mtime and tries < (sleep_time/30):
sleep(30) # sleep(30)
proc_start_time = u._get_proc_start_time(sentry_unit, # proc_start_time = u._get_proc_start_time(sentry_unit,
service, pgrep_full) # service, pgrep_full)
file_mtime = u._get_file_mtime(sentry_unit, filename) # file_mtime = u._get_file_mtime(sentry_unit, filename)
u.log.debug('proc restart wait: {} {}'.format(tries, service)) # u.log.debug('proc restart wait: {} {}'.format(tries, service))
tries += 1 # tries += 1
#
u.log.debug('proc-file time diff for {},{}: {}'.format(service, # u.log.debug('proc-file time diff for {},{}: {}'.format(service,
filename, proc_start_time - file_mtime)) # filename, proc_start_time - file_mtime))
#
if proc_start_time >= file_mtime: # if proc_start_time >= file_mtime:
return True # return True
else: # else:
u.log.debug('service not restarted within ()s: {}'.format( # u.log.debug('service not restarted within ()s: {}'.format(
service, sleep_time)) # service, sleep_time))
return False # return False
def authenticate_cinder_admin(self, username, password, tenant): def authenticate_cinder_admin(self, username, password, tenant):
"""Authenticates admin user with cinder.""" """Authenticates admin user with cinder."""
@ -524,16 +524,16 @@ class CinderBasicDeployment(OpenStackAmuletDeployment):
self.d.configure('cinder', {'verbose': 'True'}) self.d.configure('cinder', {'verbose': 'True'})
self.d.configure('cinder', {'debug': 'True'}) self.d.configure('cinder', {'debug': 'True'})
if not self.service_restarted(self.cinder_sentry, 'cinder-api', if not u.service_restarted(self.cinder_sentry, 'cinder-api',
'/etc/cinder/cinder.conf', '/etc/cinder/cinder.conf',
sleep_time=120): sleep_time=120):
self.d.configure('cinder', {'verbose': 'False'}) self.d.configure('cinder', {'verbose': 'False'})
self.d.configure('cinder', {'debug': 'False'}) self.d.configure('cinder', {'debug': 'False'})
msg = "cinder-api service didn't restart after config change" msg = "cinder-api service didn't restart after config change"
amulet.raise_status(amulet.FAIL, msg=msg) amulet.raise_status(amulet.FAIL, msg=msg)
if not self.service_restarted(self.cinder_sentry, 'cinder-volume', if not u.service_restarted(self.cinder_sentry, 'cinder-volume',
'/etc/cinder/cinder.conf', sleep_time=0): '/etc/cinder/cinder.conf', sleep_time=0):
self.d.configure('cinder', {'verbose': 'False'}) self.d.configure('cinder', {'verbose': 'False'})
self.d.configure('cinder', {'debug': 'False'}) self.d.configure('cinder', {'debug': 'False'})
msg = "cinder-volume service didn't restart after conf change" msg = "cinder-volume service didn't restart after conf change"

View File

@ -169,11 +169,14 @@ class AmuletUtils(object):
cmd = 'pgrep -o -f {}'.format(service) cmd = 'pgrep -o -f {}'.format(service)
else: else:
cmd = 'pgrep -o {}'.format(service) cmd = 'pgrep -o {}'.format(service)
proc_dir = '/proc/{}'.format(sentry_unit.run(cmd)[0].strip()) cmd = cmd + ' | grep -v pgrep || exit 0'
return self._get_dir_mtime(sentry_unit, proc_dir) cmd_out = sentry_unit.run(cmd)
if cmd_out[0]:
proc_dir = '/proc/{}'.format(cmd_out[0].strip())
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=False, sleep_time=20, retry_count=2):
"""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
@ -181,8 +184,19 @@ class AmuletUtils(object):
has been restarted. has been restarted.
""" """
time.sleep(sleep_time) time.sleep(sleep_time)
if (self._get_proc_start_time(sentry_unit, service, pgrep_full) >= proc_start_time = self._get_proc_start_time(sentry_unit, service,
self._get_file_mtime(sentry_unit, filename)): pgrep_full)
while retry_count > 0 and not proc_start_time:
self.log.debug('No pid file found for service %s, will retry %i '
'more times' % (service, retry_count))
time.sleep(30)
proc_start_time = self._get_proc_start_time(sentry_unit, service,
pgrep_full)
retry_count = retry_count - 1
if not proc_start_time:
return False
if proc_start_time >= self._get_file_mtime(sentry_unit, filename):
return True return True
else: else:
return False return False

View File

@ -71,16 +71,19 @@ class OpenStackAmuletDeployment(AmuletDeployment):
services.append(this_service) services.append(this_service)
use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph', use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph',
'ceph-osd', 'ceph-radosgw'] 'ceph-osd', 'ceph-radosgw']
# Openstack subordinate charms do not expose an origin option as that
# is controlled by the principle
ignore = ['neutron-openvswitch']
if self.openstack: if self.openstack:
for svc in services: for svc in services:
if svc['name'] not in use_source: if svc['name'] not in use_source + ignore:
config = {'openstack-origin': self.openstack} config = {'openstack-origin': self.openstack}
self.d.configure(svc['name'], config) self.d.configure(svc['name'], config)
if self.source: if self.source:
for svc in services: for svc in services:
if svc['name'] in use_source: if svc['name'] in use_source and svc['name'] not in ignore:
config = {'source': self.source} config = {'source': self.source}
self.d.configure(svc['name'], config) self.d.configure(svc['name'], config)