From 345b440b2b8f4d3062d38a17e5de7d4688cb9485 Mon Sep 17 00:00:00 2001 From: Artom Lifshitz Date: Fri, 19 Jun 2020 09:13:53 -0400 Subject: [PATCH] Trivial: use condition instead of try/except When getting a service's config, stop using try/except to tell if the conf exists, and instead use a cleaner `if hasattr`. Change-Id: Ib98ff29a38dfaaeff144958c3e0ac3c141429ba9 --- whitebox_tempest_plugin/services/clients.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/whitebox_tempest_plugin/services/clients.py b/whitebox_tempest_plugin/services/clients.py index a4db012e..e4c66f39 100644 --- a/whitebox_tempest_plugin/services/clients.py +++ b/whitebox_tempest_plugin/services/clients.py @@ -80,9 +80,8 @@ class ServiceManager(SSHClient): whitebox- config section. """ super(ServiceManager, self).__init__(hostname) - try: - conf = getattr(CONF, 'whitebox-%s' % service) - except AttributeError: + conf = getattr(CONF, 'whitebox-%s' % service, None) + if conf is None: raise exceptions.MissingServiceSectionException(service=service) self.config_path = getattr(conf, 'config_path', None) self.restart_command = getattr(conf, 'restart_command', None)