Skip to content

Commit

Permalink
Fix case no webservice option in settings file
Browse files Browse the repository at this point in the history
Ref #307, add missing default options
  • Loading branch information
algorys committed Apr 12, 2018
1 parent fee3bdf commit f8b0d33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 4 additions & 1 deletion alignak_app/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def login(self, username=None, password=None, proxies=None, check=False):
)

if self.connected and not check:
self.ws_client.login(self.user['token'])
if settings.get_config('Alignak', 'webservice'):
self.ws_client.login(self.user['token'])
else:
logger.info('No configured Web Service.')

return self.connected

Expand Down
31 changes: 17 additions & 14 deletions alignak_app/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Settings(object):
"""

# Default configurations
default_parameters = {
default_settings = {
'Alignak': {
'username': '',
'password': '',
Expand All @@ -63,8 +63,11 @@ class Settings(object):

},
'Alignak-app': {
'locale': 'en_US',
'display': 'min',
'problems': False,
'requests_interval': 30,
'tab_order': 'h,p,s',
'requests_interval': 20,
'notification_duration': 30,
'spy_interval': 30,
'update_status': 30,
Expand Down Expand Up @@ -120,24 +123,24 @@ def get_config(self, section, option, boolean=False):
if self.app_config.get(section, option):
return self.app_config.getboolean(section, option)

return self.default_parameters[section][option]
return self.default_settings[section][option]
except (NoOptionError, NoSectionError) as e: # pragma: no cover - not testable
logger.error('%s', str(e))
logger.error('Replace by default %s: %s',
section, self.default_parameters[section][option])
return self.default_parameters[section][option]
logger.warning('%s', str(e))
logger.info('Replace by default %s: %s',
section, self.default_settings[section][option])
return self.default_settings[section][option]
else:
try:
if self.app_config.get(section, option):
return self.app_config.get(section, option)

return self.default_parameters[section][option]
except (NoOptionError, NoSectionError, InterpolationError) \
as e: # pragma: no cover - not testable
logger.error('%s', str(e))
logger.error('Replace by default %s: %s',
section, self.default_parameters[section][option])
return self.default_parameters[section][option]
return self.default_settings[section][option]
# pragma: no cover - not testable
except (NoOptionError, NoSectionError, InterpolationError) as e:
logger.warning('%s', str(e))
logger.info('Replace by default %s: %s',
section, self.default_settings[section][option])
return self.default_settings[section][option]

def set_config(self, section, option, new_value):
"""
Expand Down

0 comments on commit f8b0d33

Please sign in to comment.