Merge "glance-replicator: size: Handle no args better"

This commit is contained in:
Jenkins 2016-07-22 19:28:44 +00:00 committed by Gerrit Code Review
commit 5f6dc003ae
2 changed files with 9 additions and 3 deletions

View File

@ -330,7 +330,7 @@ def replication_size(options, args):
"""
# Make sure server info is provided
if len(args) < 1:
if args is None or len(args) < 1:
raise TypeError(_("Too few arguments."))
server, port = utils.parse_valid_host_port(args.pop())

View File

@ -310,8 +310,9 @@ def check_no_args(command, args):
try:
glance_replicator.get_image_service = get_image_service
command(options, args)
except TypeError:
no_args_error = True
except TypeError as e:
if str(e) == "Too few arguments.":
no_args_error = True
finally:
glance_replicator.get_image_service = orig_img_service
@ -374,6 +375,11 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
command = glance_replicator.replication_size
self.assertTrue(check_no_args(command, args))
def test_replication_size_with_args_is_None(self):
args = None
command = glance_replicator.replication_size
self.assertTrue(check_no_args(command, args))
def test_replication_size_with_bad_args(self):
args = ['aaa']
command = glance_replicator.replication_size