Check that list of upgraders without duplicates
The list of upgraders specified via command-line should not have duplicates added test for incompatibility check Change-Id: I24952a9e64034c3a98adbeae67a3c3a8dd7e1b67 Partial-Bug: #1495454
This commit is contained in:
parent
d32e186c82
commit
4012dca9c4
|
@ -24,6 +24,7 @@ from fuel_upgrade.logger import configure_logger
|
|||
|
||||
from fuel_upgrade import errors
|
||||
from fuel_upgrade import messages
|
||||
from fuel_upgrade import utils
|
||||
|
||||
from fuel_upgrade.checker_manager import CheckerManager
|
||||
from fuel_upgrade.config import build_config
|
||||
|
@ -110,6 +111,13 @@ def parse_args(args):
|
|||
)
|
||||
)
|
||||
|
||||
# check input systems have no duplicates
|
||||
if len(rv.systems) != len(set(rv.systems)):
|
||||
parser.error(
|
||||
'the following systems are listed more than one times: "{0}"'
|
||||
.format(', '.join(sorted(utils.get_non_unique(rv.systems))))
|
||||
)
|
||||
|
||||
return rv
|
||||
|
||||
|
||||
|
|
|
@ -66,3 +66,31 @@ class TestAdminPassword(BaseTestCase):
|
|||
messages.no_password_provided):
|
||||
args = self.get_args(self.default_args)
|
||||
run_upgrade(args)
|
||||
|
||||
|
||||
class TestArgumentsParser(BaseTestCase):
|
||||
default_args = ['--src', '/path']
|
||||
|
||||
def test_parse_list_of_systems(self):
|
||||
systems = ['host-system', 'docker']
|
||||
args = parse_args(systems + self.default_args)
|
||||
self.assertEqual(systems, args.systems)
|
||||
|
||||
@mock.patch('argparse.ArgumentParser.error')
|
||||
def test_error_if_systems_have_duplicates(self, error_mock):
|
||||
parse_args(
|
||||
['host-system', 'docker', 'openstack', 'openstack', 'docker'] +
|
||||
self.default_args
|
||||
)
|
||||
self.assertEqual(1, error_mock.call_count)
|
||||
self.assertEqual(1, len(error_mock.call_args[0]))
|
||||
self.assertIn('"docker, openstack"', error_mock.call_args[0][0])
|
||||
|
||||
@mock.patch('argparse.ArgumentParser.error')
|
||||
def test_error_if_systems_are_incompatible(self, error_mock):
|
||||
parse_args(
|
||||
['docker', 'docker-init'] + self.default_args
|
||||
)
|
||||
self.assertEqual(1, error_mock.call_count)
|
||||
self.assertEqual(1, len(error_mock.call_args[0]))
|
||||
self.assertIn('"docker-init, docker"', error_mock.call_args[0][0])
|
||||
|
|
|
@ -22,6 +22,7 @@ import textwrap
|
|||
import urllib2
|
||||
|
||||
import requests
|
||||
import six
|
||||
import yaml
|
||||
|
||||
import mock
|
||||
|
@ -774,3 +775,14 @@ class TestHttpRetry(BaseTestCase):
|
|||
self.assertEqual(result, 'return value')
|
||||
self.called_times(method, 2)
|
||||
self.called_once(msleep)
|
||||
|
||||
|
||||
class TestGetNonUnique(BaseTestCase):
|
||||
def test_get_duplicates(self):
|
||||
self.assertItemsEqual([2, 3], utils.get_non_unique([2, 2, 2, 3, 3, 1]))
|
||||
|
||||
def test_empty_if_no_duplicates(self):
|
||||
self.assertEqual([], list(utils.get_non_unique(six.moves.range(3))))
|
||||
|
||||
def test_empty_if_empty_input(self):
|
||||
self.assertEqual([], list(utils.get_non_unique([])))
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
from fnmatch import fnmatch
|
||||
import functools
|
||||
import glob
|
||||
|
@ -33,6 +34,7 @@ from distutils.version import StrictVersion
|
|||
|
||||
from mako.template import Template
|
||||
import requests
|
||||
import six
|
||||
from six.moves import range
|
||||
import yaml
|
||||
|
||||
|
@ -863,3 +865,12 @@ class http_retry(object):
|
|||
time.sleep(self._interval)
|
||||
|
||||
return _wrapped
|
||||
|
||||
|
||||
def get_non_unique(iterable):
|
||||
"""returns the non unique items without keeping the order."""
|
||||
|
||||
counter = collections.defaultdict(int)
|
||||
for i in iterable:
|
||||
counter[i] += 1
|
||||
return [k for k, v in six.iteritems(counter) if v > 1]
|
||||
|
|
Loading…
Reference in New Issue