Repository: aurora Updated Branches: refs/heads/master 7fd920e0a -> 998993dd8
Validating INSTANCES_SPEC_ARGUMENT option range Bugs closed: AURORA-1296 Reviewed at https://reviews.apache.org/r/34449/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/998993dd Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/998993dd Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/998993dd Branch: refs/heads/master Commit: 998993dd802cf5e94a995aefd7a6c4ec90a1d3af Parents: 7fd920e Author: Maxim Khutornenko <[email protected]> Authored: Wed May 20 10:52:47 2015 -0700 Committer: Maxim Khutornenko <[email protected]> Committed: Wed May 20 10:52:47 2015 -0700 ---------------------------------------------------------------------- .../python/apache/aurora/client/cli/options.py | 6 +++- src/test/python/apache/aurora/client/cli/BUILD | 9 +++++ .../apache/aurora/client/cli/test_options.py | 36 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/998993dd/src/main/python/apache/aurora/client/cli/options.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/client/cli/options.py b/src/main/python/apache/aurora/client/cli/options.py index 07344b3..f8ac252 100644 --- a/src/main/python/apache/aurora/client/cli/options.py +++ b/src/main/python/apache/aurora/client/cli/options.py @@ -71,7 +71,11 @@ def parse_instances(instances): result = set() for part in instances.split(','): x = part.split('-') - result.update(range(int(x[0]), int(x[-1]) + 1)) + start = int(x[0]) + end = int(x[-1]) + 1 + if start >= end: + raise ArgumentTypeError('Invalid instance range: %s' % x) + result.update(range(start, end)) return sorted(result) http://git-wip-us.apache.org/repos/asf/aurora/blob/998993dd/src/test/python/apache/aurora/client/cli/BUILD ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/client/cli/BUILD b/src/test/python/apache/aurora/client/cli/BUILD index 26d11a3..0d85f5f 100644 --- a/src/test/python/apache/aurora/client/cli/BUILD +++ b/src/test/python/apache/aurora/client/cli/BUILD @@ -23,6 +23,7 @@ python_test_suite( ':inspect', ':job', ':config', + ':options', ':plugins', ':quota', ':sla', @@ -224,3 +225,11 @@ python_tests( 'src/main/python/apache/aurora/client/cli', ] ) + +python_tests( + name = 'options', + sources = [ 'test_options.py' ], + dependencies = [ + 'src/main/python/apache/aurora/client/cli', + ] +) http://git-wip-us.apache.org/repos/asf/aurora/blob/998993dd/src/test/python/apache/aurora/client/cli/test_options.py ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/client/cli/test_options.py b/src/test/python/apache/aurora/client/cli/test_options.py new file mode 100644 index 0000000..21d5888 --- /dev/null +++ b/src/test/python/apache/aurora/client/cli/test_options.py @@ -0,0 +1,36 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import unittest +from argparse import ArgumentTypeError + +import pytest + +from apache.aurora.client.cli.options import parse_instances + + +class TestParseInstances(unittest.TestCase): + + def test_parse_instances_with_range(self): + assert parse_instances("0-3") == [0, 1, 2, 3] + + def test_parse_instances_mixed(self): + assert parse_instances("4,1-2,0-0") == [0, 1, 2, 4] + + def test_parse_instances_invalid_ranges(self): + with pytest.raises(ArgumentTypeError): + parse_instances("4-1") + + with pytest.raises(ArgumentTypeError): + parse_instances("1-0")
