Do not crash on unknown services in installutils.stopped_service

https://fedorahosted.org/freeipa/ticket/4835

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Jan Cholasta 2015-01-13 10:59:08 +00:00
parent a63df8f309
commit 5bf1c9a6f7

View File

@ -931,20 +931,22 @@ def stopped_service(service, instance_name=""):
'the next set of commands is being executed.', service, 'the next set of commands is being executed.', service,
log_instance_name) log_instance_name)
service_obj = services.service(service)
# Figure out if the service is running, if not, yield # Figure out if the service is running, if not, yield
if not services.knownservices[service].is_running(instance_name): if not service_obj.is_running(instance_name):
root_logger.debug('Service %s%s is not running, continue.', service, root_logger.debug('Service %s%s is not running, continue.', service,
log_instance_name) log_instance_name)
yield yield
else: else:
# Stop the service, do the required stuff and start it again # Stop the service, do the required stuff and start it again
root_logger.debug('Stopping %s%s.', service, log_instance_name) root_logger.debug('Stopping %s%s.', service, log_instance_name)
services.knownservices[service].stop(instance_name) service_obj.stop(instance_name)
try: try:
yield yield
finally: finally:
root_logger.debug('Starting %s%s.', service, log_instance_name) root_logger.debug('Starting %s%s.', service, log_instance_name)
services.knownservices[service].start(instance_name) service_obj.start(instance_name)
def check_entropy(): def check_entropy():