Fix the bug of TypeError with JsonFilter
The default scheduler_hints value is None, and if we don't pass the scheduler_hints , It will report TypeError when creating share with JsonFilter with Rest API. The TypeError exception is added to solve this problem. Change-Id: Iad89491cbbaccac8df161f8f1157c7ebf3291458 Closes-Bug: #1959472
This commit is contained in:
parent
82b9dfe0a6
commit
064046a47f
@ -137,7 +137,9 @@ class JsonFilter(base_host.BaseHostFilter):
|
|||||||
# and scheduler_hints.
|
# and scheduler_hints.
|
||||||
try:
|
try:
|
||||||
query = filter_properties['scheduler_hints']['query']
|
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
|
query = None
|
||||||
if not query:
|
if not query:
|
||||||
return True
|
return True
|
||||||
|
@ -264,6 +264,14 @@ class HostFiltersTestCase(test.TestCase):
|
|||||||
self.assertRaises(KeyError,
|
self.assertRaises(KeyError,
|
||||||
self.filter.host_passes, host, filter_properties)
|
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):
|
def test_json_filter_empty_filters_pass(self):
|
||||||
host = fakes.FakeHostState('host1',
|
host = fakes.FakeHostState('host1',
|
||||||
{'capabilities': {'enabled': True}})
|
{'capabilities': {'enabled': True}})
|
||||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user