From cd687bc503561cb06acca53b15242fdea8388242 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Wed, 14 Oct 2015 17:52:46 +0800 Subject: [PATCH] Convert set() to list in ListType ListType should return a list instead of set, As set is not json serializable Change-Id: I06011929022c124883a00cdf5784ed63f79f48a5 --- ironic/api/controllers/v1/types.py | 4 ++-- ironic/tests/unit/api/v1/test_types.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ironic/api/controllers/v1/types.py b/ironic/api/controllers/v1/types.py index fdd45fb4da..ffcaa7b7f1 100644 --- a/ironic/api/controllers/v1/types.py +++ b/ironic/api/controllers/v1/types.py @@ -196,12 +196,12 @@ class ListType(wtypes.UserType): """Validate and convert the input to a ListType. :param value: A comma separated string of values - :returns: A list of values. + :returns: A list of unique values, whose order is not guaranteed. """ items = [v.strip().lower() for v in six.text_type(value).split(',')] # filter() to remove empty items # set() to remove duplicated items - return set(filter(None, items)) + return list(set(filter(None, items))) @staticmethod def frombasetype(value): diff --git a/ironic/tests/unit/api/v1/test_types.py b/ironic/tests/unit/api/v1/test_types.py index 9fb7747c57..ac7ce73e95 100644 --- a/ironic/tests/unit/api/v1/test_types.py +++ b/ironic/tests/unit/api/v1/test_types.py @@ -277,3 +277,4 @@ class TestListType(base.TestCase): v.validate("foo, ,,bar")) self.assertItemsEqual(['foo', 'bar'], v.validate("foo,foo,foo,bar")) + self.assertIsInstance(v.validate('foo,bar'), list)