Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'remotes/origin/pr/2770' into 2.10-dev
  • Loading branch information
dkliban committed Oct 17, 2016
2 parents 89a6163 + fc9f5f9 commit 1d40883
Show file tree
Hide file tree
Showing 76 changed files with 713 additions and 1,619 deletions.
13 changes: 13 additions & 0 deletions .mention-bot
@@ -0,0 +1,13 @@
{
"userBlacklist": [
"barnabycourt",
"beav",
"bowlofeggs",
"jdob",
"jlconnor",
"jwmatthews",
"mccun943",
"pkilambi",
"slagle"
]
}
144 changes: 0 additions & 144 deletions Vagrantfile.example

This file was deleted.

2 changes: 1 addition & 1 deletion agent/setup.py
Expand Up @@ -13,7 +13,7 @@

setup(
name='pulp-agent',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
2 changes: 1 addition & 1 deletion bindings/setup.py
Expand Up @@ -13,7 +13,7 @@

setup(
name='pulp-bindings',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
2 changes: 1 addition & 1 deletion client_admin/setup.py
Expand Up @@ -4,7 +4,7 @@

setup(
name='pulp-client-admin',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
2 changes: 1 addition & 1 deletion client_consumer/setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name='pulp-client-consumer',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
54 changes: 43 additions & 11 deletions client_lib/pulp/client/extensions/exceptions.py
Expand Up @@ -126,8 +126,11 @@ def handle_bad_request(self, e):
'provided the following error message:')
self.prompt.render_failure_message(msg)

self.prompt.render_failure_message(' %s' % e.error_message)
msg = _('More information may be found using the -v flag.')
msg = ' %s' % e.error_message
v_flag_msg = self.handle_v_flags()
if v_flag_msg:
self.prompt.render_failure_message(msg)
msg = v_flag_msg

self.prompt.render_failure_message(msg)
return CODE_BAD_REQUEST
Expand Down Expand Up @@ -197,8 +200,7 @@ def handle_conflict(self, e):
msg += _('Operation: %(o)s') % {'o': r['operation']}
else:
msg = _('The requested operation could not execute due to an unexpected '
'conflict on the server. More information may be found using the '
'-v flag.')
'conflict on the server.') + self.handle_v_flags()

self.prompt.render_failure_message(msg)
return CODE_CONFLICT
Expand Down Expand Up @@ -228,8 +230,7 @@ def handle_connection_error(self, e):

self._log_client_exception(e)

msg = _('An error occurred attempting to contact the server. More information '
'may be found using the -v flag.')
msg = _('An error occurred attempting to contact the server.') + self.handle_v_flags()

self.prompt.render_failure_message(msg)
return CODE_CONNECTION_EXCEPTION
Expand Down Expand Up @@ -326,8 +327,7 @@ def handle_socket_error(self, e):
data = {'server': self.config['server']['host']}
msg = msg % data
else:
msg = _('An error occurred attempting to contact the server. More information '
'may be found using the -v flag.')
msg = _('An error occurred attempting to contact the server.') + self.handle_v_flags()

self.prompt.render_failure_message(msg)
return CODE_SOCKET_ERROR
Expand Down Expand Up @@ -424,10 +424,9 @@ def handle_unexpected(self, e):

self._log_client_exception(e)

msg = _('An unexpected error has occurred. More information '
'may be found using the -v flag.')

msg = _('An unexpected error has occurred.') + self.handle_v_flags()
self.prompt.render_failure_message(msg)

return CODE_UNEXPECTED

def _log_server_exception(self, e):
Expand Down Expand Up @@ -485,3 +484,36 @@ def _certificate_expiration_date(self, full_cert_path):
return str(expiration_date)
except Exception:
return None

def _get_v_flag_count(self):
"""
Estimate number of v flags from logger level.
:rtype: int or None
:return: 0 for normal level, 1 for -v, 2 for -vv, None for others
"""
verbose = _logger.getEffectiveLevel()
verbose_levels = {
logging.DEBUG: 2,
logging.INFO: 1,
logging.FATAL: 0
}
try:
return verbose_levels[verbose]
except KeyError:
return None

def handle_v_flags(self):
"""
By number of v flags return text about using v flags.
:rtype: string
:return: 2 flags = "", 1 flag = "...use -vv...", 0 or other "...use -v flag..."
"""
verbose_level = self._get_v_flag_count()
if verbose_level == 2:
return ""
elif verbose_level == 1:
return _('More information may be found using the -vv flag.')
else:
return _('More information may be found using the -v flag.')
2 changes: 1 addition & 1 deletion client_lib/setup.py
Expand Up @@ -13,7 +13,7 @@

setup(
name='pulp-client-lib',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
41 changes: 41 additions & 0 deletions client_lib/test/unit/client/extensions/test_exceptions.py
@@ -1,9 +1,11 @@
"""
This module contains tests for the pulp.client.extensions.exceptions module.
"""
import logging
import os
from _socket import gaierror
from socket import error as socket_error
from gettext import gettext as _

import mock
from M2Crypto.SSL.Checker import WrongHost
Expand Down Expand Up @@ -416,3 +418,42 @@ def test_certificate_expiration(self):

# Verify
self.assertEqual(date, 'May 9 12:39:37 2013 GMT')

@mock.patch.object(logging.Logger, 'getEffectiveLevel', autospec=True)
def test__get_v_flag_count(self, mock_getEffectiveLevel):
"""Test if _get_v_flag_count() if logger level is -vv flags."""
mock_getEffectiveLevel.return_value = logging.DEBUG
self.assertEqual(2, self.exception_handler._get_v_flag_count())

@mock.patch.object(logging.Logger, 'getEffectiveLevel', autospec=True)
def test__get_v_flag_count_wrong_level(self, mock_getEffectiveLevel):
"""Test if _get_v_flag_count() if logger level is not set by -v flags."""
mock_getEffectiveLevel.return_value = logging.NOTSET
self.assertEqual(None, self.exception_handler._get_v_flag_count())

@mock.patch.object(handler.ExceptionHandler, "_get_v_flag_count", autospec=True)
def test_handle_v_flags_2v(self, mock__get_v_flag_count):
"""Test handle_v_flags with two v flags."""
mock__get_v_flag_count.return_value = 2
self.assertEqual("", self.exception_handler.handle_v_flags())

@mock.patch.object(handler.ExceptionHandler, "_get_v_flag_count", autospec=True)
def test_handle_v_flags_v(self, mock__get_v_flag_count):
"""Test handle_v_flags with v flag."""
mock__get_v_flag_count.return_value = 1
expected_text = _('More information may be found using the -vv flag.')
self.assertEqual(expected_text, self.exception_handler.handle_v_flags())

@mock.patch.object(handler.ExceptionHandler, "_get_v_flag_count", autospec=True)
def test_handle_v_flags_no_v(self, mock__get_v_flag_count):
"""Test handle_v_flags without v flag."""
mock__get_v_flag_count.return_value = 0
expected_text = _('More information may be found using the -v flag.')
self.assertEqual(expected_text, self.exception_handler.handle_v_flags())

@mock.patch.object(handler.ExceptionHandler, "_get_v_flag_count", autospec=True)
def test_handle_v_flags_unknown_v(self, mock__get_v_flag_count):
"""Test handle_v_flags with unknown number of v flag."""
mock__get_v_flag_count.return_value = None
expected_text = _('More information may be found using the -v flag.')
self.assertEqual(expected_text, self.exception_handler.handle_v_flags())
2 changes: 1 addition & 1 deletion common/setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name='pulp-common',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test']),
author='Pulp Team',
Expand Down
2 changes: 1 addition & 1 deletion devel/setup.py
Expand Up @@ -11,7 +11,7 @@

setup(
name='pulp-devel',
version='2.10b4',
version='2.11a1',
license='GPLv2+',
packages=find_packages(exclude=['test', 'test.*']),
author='Pulp Team',
Expand Down

0 comments on commit 1d40883

Please sign in to comment.