Dedicated exception for PR malformed requirements
Create dedicated manager exception MalformedRequirements returns HTTP 400 Malformed requirements %(rqrms)s when the requirements of reservation are malformed Added small bugfix allow to create reservation with one character value of propety Closes-Bug: #1305048 Change-Id: I5e5fa012dd9556182eac8def0124fa683f9b677c
This commit is contained in:
parent
7f9b1516dc
commit
47cd5eb2a5
@ -123,3 +123,8 @@ class HypervisorNotFound(exceptions.ClimateException):
|
|||||||
|
|
||||||
class NotEnoughHostsAvailable(exceptions.ClimateException):
|
class NotEnoughHostsAvailable(exceptions.ClimateException):
|
||||||
msg_fmt = _("Not enough hosts available")
|
msg_fmt = _("Not enough hosts available")
|
||||||
|
|
||||||
|
|
||||||
|
class MalformedRequirements(exceptions.ClimateException):
|
||||||
|
code = 400
|
||||||
|
msg_fmt = _("Malformed requirements %(rqrms)s")
|
||||||
|
@ -382,7 +382,11 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
# TODO(frossigneux) Support the "or" operator
|
# TODO(frossigneux) Support the "or" operator
|
||||||
# Convert text to json
|
# Convert text to json
|
||||||
if isinstance(requirements, six.string_types):
|
if isinstance(requirements, six.string_types):
|
||||||
requirements = json.loads(requirements)
|
try:
|
||||||
|
requirements = json.loads(requirements)
|
||||||
|
except ValueError:
|
||||||
|
raise manager_ex.MalformedRequirements(rqrms=requirements)
|
||||||
|
|
||||||
# Requirement list looks like ['<', '$ram', '1024']
|
# Requirement list looks like ['<', '$ram', '1024']
|
||||||
if self._requirements_with_three_elements(requirements):
|
if self._requirements_with_three_elements(requirements):
|
||||||
result = []
|
result = []
|
||||||
@ -400,7 +404,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
elif isinstance(requirements, list) and not requirements:
|
elif isinstance(requirements, list) and not requirements:
|
||||||
return requirements
|
return requirements
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Malformed requirements')
|
raise manager_ex.MalformedRequirements(rqrms=requirements)
|
||||||
|
|
||||||
def _requirements_with_three_elements(self, requirements):
|
def _requirements_with_three_elements(self, requirements):
|
||||||
"""Return true if requirement list looks like ['<', '$ram', '1024']."""
|
"""Return true if requirement list looks like ['<', '$ram', '1024']."""
|
||||||
@ -411,7 +415,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
isinstance(requirements[2], six.string_types) and
|
isinstance(requirements[2], six.string_types) and
|
||||||
requirements[0] in ['==', '=', '!=', '>=', '<=', '>', '<'] and
|
requirements[0] in ['==', '=', '!=', '>=', '<=', '>', '<'] and
|
||||||
len(requirements[1]) > 1 and requirements[1][0] == '$' and
|
len(requirements[1]) > 1 and requirements[1][0] == '$' and
|
||||||
len(requirements[2]) > 1)
|
len(requirements[2]) > 0)
|
||||||
|
|
||||||
def _requirements_with_and_keyword(self, requirements):
|
def _requirements_with_and_keyword(self, requirements):
|
||||||
return (len(requirements) > 1 and
|
return (len(requirements) > 1 and
|
||||||
|
@ -807,17 +807,20 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
|||||||
|
|
||||||
def test_convert_requirements_with_incorrect_syntax_1(self):
|
def test_convert_requirements_with_incorrect_syntax_1(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError, self.fake_phys_plugin._convert_requirements,
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
'["a", "$memory", "4096"]')
|
'["a", "$memory", "4096"]')
|
||||||
|
|
||||||
def test_convert_requirements_with_incorrect_syntax_2(self):
|
def test_convert_requirements_with_incorrect_syntax_2(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError, self.fake_phys_plugin._convert_requirements,
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
'["=", "memory", "4096"]')
|
'["=", "memory", "4096"]')
|
||||||
|
|
||||||
def test_convert_requirements_with_incorrect_syntax_3(self):
|
def test_convert_requirements_with_incorrect_syntax_3(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError, self.fake_phys_plugin._convert_requirements,
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
'["=", "$memory", 4096]')
|
'["=", "$memory", 4096]')
|
||||||
|
|
||||||
def test_convert_requirements_complex(self):
|
def test_convert_requirements_complex(self):
|
||||||
@ -827,10 +830,18 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
|||||||
|
|
||||||
def test_convert_requirements_complex_with_incorrect_syntax_1(self):
|
def test_convert_requirements_complex_with_incorrect_syntax_1(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError, self.fake_phys_plugin._convert_requirements,
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
'["and", [">", "memory", "4096"], [">", "$disk", "40"]]')
|
'["and", [">", "memory", "4096"], [">", "$disk", "40"]]')
|
||||||
|
|
||||||
def test_convert_requirements_complex_with_incorrect_syntax_2(self):
|
def test_convert_requirements_complex_with_incorrect_syntax_2(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError, self.fake_phys_plugin._convert_requirements,
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
'["fail", [">", "$memory", "4096"], [">", "$disk", "40"]]')
|
'["fail", [">", "$memory", "4096"], [">", "$disk", "40"]]')
|
||||||
|
|
||||||
|
def test_convert_requirements_complex_with_not_json_value(self):
|
||||||
|
self.assertRaises(
|
||||||
|
manager_exceptions.MalformedRequirements,
|
||||||
|
self.fake_phys_plugin._convert_requirements,
|
||||||
|
'something')
|
||||||
|
Loading…
Reference in New Issue
Block a user