Skip to content

Commit

Permalink
Remove non-exception from EXCEPTION_DETAIL_MAPPINGS
Browse files Browse the repository at this point in the history
Removes a non-exception from the map and adds tests to check the
consistency of message_field.Action and .Detail fields.

Updates test-requirements and lower-constraints to use the most
recent version of ddt allowed by current upper-constraints.  (An
included test uses the idata decorator, which allows passing an
iterator to the test data.)

Closes-bug: #1822025
Change-Id: I0cad6589b145fac430942ccbb27279db7b3b152f
  • Loading branch information
ostackbrian committed Apr 3, 2019
1 parent e27d781 commit a5b5d8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 0 additions & 1 deletion cinder/message/message_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class Detail(object):
'BackupLimitExceeded',
'SnapshotLimitExceeded'],
NOT_ENOUGH_SPACE_FOR_IMAGE: ['ImageTooBig'],
UNMANAGE_ENC_NOT_SUPPORTED: ['UnmanageEncVolNotSupported'],
}


Expand Down
26 changes: 26 additions & 0 deletions cinder/tests/unit/message/test_message_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# under the License.

import ddt
import inspect
from itertools import chain

from oslo_config import cfg

Expand All @@ -23,6 +25,30 @@

@ddt.ddt
class MessageFieldTest(test.TestCase):
def test_unique_action_ids(self):
"""Assert that no action_id is duplicated."""
action_ids = [x[0] for x in message_field.Action.ALL]
self.assertEqual(len(action_ids), len(set(action_ids)))

def test_unique_detail_ids(self):
"""Assert that no detail_id is duplicated."""
detail_ids = [x[0] for x in message_field.Detail.ALL]
self.assertEqual(len(detail_ids), len(set(detail_ids)))

known_exceptions = [
name for name, _ in
inspect.getmembers(exception, inspect.isclass)]
mapped_exceptions = list(chain.from_iterable(
message_field.Detail.EXCEPTION_DETAIL_MAPPINGS.values()))

@ddt.idata(mapped_exceptions)
def test_exception_detail_map_no_unknown_exceptions(self, exc):
"""Assert that only known exceptions are in the map."""
self.assertIn(exc, self.known_exceptions)


@ddt.ddt
class MessageFieldFunctionsTest(test.TestCase):

@ddt.data({'id': '001', 'content': 'schedule allocate volume'},
{'id': '002', 'content': 'attach volume'},
Expand Down
2 changes: 1 addition & 1 deletion lower-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contextlib2==0.5.5
coverage==4.0
cryptography==2.1
cursive==0.2.1
ddt==1.0.1
ddt==1.2.1
debtcollector==1.19.0
decorator==3.4.0
defusedxml==0.5.0
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0

coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT
ddt>=1.2.1 # MIT
fixtures>=3.0.0 # Apache-2.0/BSD
mock>=2.0.0 # BSD
os-api-ref>=1.4.0 # Apache-2.0
Expand Down

0 comments on commit a5b5d8e

Please sign in to comment.