update tests for process checking on systemd systems; misc cleanup.

This commit is contained in:
Ryan Beisner 2015-06-20 15:27:28 +00:00
parent dcec2c9ef3
commit 4232f473ed
3 changed files with 121 additions and 12 deletions

View File

@ -6,7 +6,7 @@ lint:
hooks tests unit_tests
@charm proof
unit_test:
test:
@# Bundletester expects unit tests here.
@echo Starting unit tests...
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests

View File

@ -166,15 +166,32 @@ class CephOsdBasicDeployment(OpenStackAmuletDeployment):
'password',
self.demo_tenant)
def test_100_services(self):
def test_100_ceph_processes(self):
"""Verify that the expected service processes are running
on each ceph unit."""
# Process name and quantity of processes to expect on each unit
ceph_processes = {
'ceph-mon': 1,
'ceph-mon': 1,
'ceph-osd': 2
}
# Units with process names and PID quantities expected
expected_processes = {
self.ceph0_sentry: ceph_processes,
self.ceph1_sentry: ceph_processes,
self.ceph2_sentry: ceph_processes,
self.ceph_osd_sentry: {'ceph-osd': 2}
}
actual_pids = u.get_unit_process_ids(expected_processes)
ret = u.validate_unit_process_ids(expected_processes, actual_pids)
if ret:
amulet.raise_status(amulet.FAIL, msg=ret)
def test_102_services(self):
"""Verify the expected services are running on the service units."""
ceph_services = [
'ceph-mon-all',
'ceph-mon id=`hostname`',
'ceph-osd-all',
'ceph-osd id={}'.format(u.get_ceph_osd_id_cmd(0)),
'ceph-osd id={}'.format(u.get_ceph_osd_id_cmd(1))
]
services = {
self.mysql_sentry: ['mysql'],
@ -186,17 +203,31 @@ class CephOsdBasicDeployment(OpenStackAmuletDeployment):
self.cinder_sentry: ['cinder-api',
'cinder-scheduler',
'cinder-volume'],
self.ceph0_sentry: ceph_services,
self.ceph1_sentry: ceph_services,
self.ceph2_sentry: ceph_services
}
if self._get_openstack_release() < self.vivid_kilo:
# For upstart systems only. Ceph services under systemd
# are checked by process name instead.
ceph_services = [
'ceph-mon-all',
'ceph-mon id=`hostname`',
'ceph-osd-all',
'ceph-osd id={}'.format(u.get_ceph_osd_id_cmd(0)),
'ceph-osd id={}'.format(u.get_ceph_osd_id_cmd(1))
]
services[self.ceph0_sentry] = ceph_services
services[self.ceph1_sentry] = ceph_services
services[self.ceph2_sentry] = ceph_services
#!? add check for ceph_osd_sentry upstart services
ret = u.validate_services_by_name(services)
if ret:
amulet.raise_status(amulet.FAIL, msg=ret)
def test_200_ceph_osd_ceph_relation(self):
"""Verify the ceph-osd to ceph relation data."""
u.log.debug('Checking ceph-osd:ceph mon relation data...')
unit = self.ceph_osd_sentry
relation = ['mon', 'ceph:osd']
expected = {

View File

@ -445,3 +445,81 @@ class AmuletUtils(object):
cmd, code, output))
return msg
return None
def get_process_id_list(self, sentry_unit, process_name):
"""Get a list of process ID(s) from a single sentry juju unit
for a single process name.
:param sentry_unit: Pointer to amulet sentry instance (juju unit)
:param process_name: Process name
:returns: List of process IDs
"""
cmd = 'pidof {}'.format(process_name)
output, code = sentry_unit.run(cmd)
if code != 0:
msg = ('{} `{}` returned {} '
'{}'.format(sentry_unit.info['unit_name'],
cmd, code, output))
raise RuntimeError(msg)
return str(output).split()
def get_unit_process_ids(self, unit_processes):
"""Construct a dict containing unit sentries, process names, and
process IDs."""
pid_dict = {}
for sentry_unit, process_list in unit_processes.iteritems():
pid_dict[sentry_unit] = {}
for process in process_list:
pids = self.get_process_id_list(sentry_unit, process)
pid_dict[sentry_unit].update({process: pids})
return pid_dict
def validate_unit_process_ids(self, expected, actual):
"""Validate process id quantities for services on units."""
self.log.debug('Checking units for running processes...')
self.log.debug('Expected PIDs: {}'.format(expected))
self.log.debug('Actual PIDs: {}'.format(actual))
if len(actual) != len(expected):
msg = ('Unit count mismatch. expected, actual: {}, '
'{} '.format(len(expected), len(actual)))
return msg
for (e_sentry, e_proc_names) in expected.iteritems():
e_sentry_name = e_sentry.info['unit_name']
if e_sentry in actual.keys():
a_proc_names = actual[e_sentry]
else:
msg = ('Expected sentry ({}) not found in actual dict data.'
'{}'.format(e_sentry_name, e_sentry))
return msg
if len(e_proc_names.keys()) != len(a_proc_names.keys()):
msg = ('Process name count mismatch. expected, actual: {}, '
'{}'.format(len(expected), len(actual)))
return msg
for (e_proc_name, e_pids_length), (a_proc_name, a_pids) in \
zip(e_proc_names.items(), a_proc_names.items()):
if e_proc_name != a_proc_name:
msg = ('Process name mismatch. expected, actual: {}, '
'{}'.format(e_proc_name, a_proc_name))
return msg
a_pids_length = len(a_pids)
if e_pids_length != a_pids_length:
msg = ('PID count mismatch. {} ({}) expected, actual: {}, '
'{} ({})'.format(e_sentry_name,
e_proc_name,
e_pids_length,
a_pids_length,
a_pids))
return msg
else:
msg = ('PID check OK: {} {} {}: '
'{}'.format(e_sentry_name,
e_proc_name,
e_pids_length,
a_pids))
self.log.debug(msg)
return None