diff --git a/manila/scheduler/filters/json.py b/manila/scheduler/filters/json.py index e654ae749d..1ff92f9c6d 100644 --- a/manila/scheduler/filters/json.py +++ b/manila/scheduler/filters/json.py @@ -137,7 +137,9 @@ class JsonFilter(base_host.BaseHostFilter): # and scheduler_hints. try: query = filter_properties['scheduler_hints']['query'] - except KeyError: + # If filter_properties['scheduler_hints'] is None, and TypeError + # will occur, add TypeError exception here. + except (KeyError, TypeError): query = None if not query: return True diff --git a/manila/tests/scheduler/filters/test_json.py b/manila/tests/scheduler/filters/test_json.py index 9b506825ed..ba90c523b5 100644 --- a/manila/tests/scheduler/filters/test_json.py +++ b/manila/tests/scheduler/filters/test_json.py @@ -264,6 +264,14 @@ class HostFiltersTestCase(test.TestCase): self.assertRaises(KeyError, self.filter.host_passes, host, filter_properties) + def test_json_filter_type_errror_passes(self): + filter_properties = { + 'scheduler_hints': None + } + host = fakes.FakeHostState('host1', + {'capabilities': {'enabled': True}}) + self.assertTrue(self.filter.host_passes, (host, filter_properties)) + def test_json_filter_empty_filters_pass(self): host = fakes.FakeHostState('host1', {'capabilities': {'enabled': True}}) diff --git a/releasenotes/notes/bug-1959472-fix-type-error-jsonfilter-fc7f87c288cc69.yaml b/releasenotes/notes/bug-1959472-fix-type-error-jsonfilter-fc7f87c288cc69.yaml new file mode 100644 index 0000000000..65a29a413a --- /dev/null +++ b/releasenotes/notes/bug-1959472-fix-type-error-jsonfilter-fc7f87c288cc69.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fix the bug of TypeError with JsonFilter. If the scheduler_hints + value is None, the TypeError exception may occur when creating share + with JsonFilter. The TypeError exception is added to solve this problem.