Merge "Handle more exceptions raised in reserve_resource()"

This commit is contained in:
Jenkins 2017-08-03 10:24:27 +00:00 committed by Gerrit Code Review
commit ce9e40ad3c
3 changed files with 50 additions and 11 deletions

View File

@ -262,8 +262,7 @@ class ManagerService(service_utils.RPCServer):
reservation['start_date'] = lease['start_date']
reservation['end_date'] = lease['end_date']
self._create_reservation(reservation)
except (exceptions.UnsupportedResourceType,
common_ex.BlazarException):
except Exception:
LOG.exception("Failed to create reservation for a lease. "
"Rollback the lease and associated "
"reservations")

View File

@ -72,17 +72,12 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
def reserve_resource(self, reservation_id, values):
"""Create reservation."""
min_hosts = self._convert_int_param(values.get('min'), 'min')
max_hosts = self._convert_int_param(values.get('max'), 'max')
self._check_params(values)
if 0 <= min_hosts and min_hosts <= max_hosts:
count_range = str(min_hosts) + '-' + str(max_hosts)
else:
raise manager_ex.InvalidRange()
host_ids = self._matching_hosts(
values['hypervisor_properties'],
values['resource_properties'],
count_range,
values['count_range'],
values['start_date'],
values['end_date'],
)
@ -98,7 +93,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
'aggregate_id': pool_instance.id,
'resource_properties': values['resource_properties'],
'hypervisor_properties': values['hypervisor_properties'],
'count_range': count_range,
'count_range': values['count_range'],
'status': 'pending',
}
host_reservation = db_api.host_reservation_create(host_rsrv_values)
@ -401,3 +396,17 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
else:
raise manager_ex.MalformedParameter(param=name)
return param
def _check_params(self, values):
min_hosts = self._convert_int_param(values.get('min'), 'min')
max_hosts = self._convert_int_param(values.get('max'), 'max')
if 0 <= min_hosts and min_hosts <= max_hosts:
values['count_range'] = str(min_hosts) + '-' + str(max_hosts)
else:
raise manager_ex.InvalidRange()
if 'hypervisor_properties' not in values:
raise manager_ex.MissingParameter(param='hypervisor_properties')
if 'resource_properties' not in values:
raise manager_ex.MissingParameter(param='resource_properties')

View File

@ -362,7 +362,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
]
host_allocation_create.assert_has_calls(calls)
def test_create_reservation_with_missing_param(self):
def test_create_reservation_with_missing_param_min(self):
values = {
'lease_id': u'018c1b43-e69e-4aef-a543-09681539cf4c',
'max': u'2',
@ -378,6 +378,37 @@ class PhysicalHostPluginTestCase(tests.TestCase):
u'441c1476-9f8f-4700-9f30-cd9b6fef3509',
values)
def test_create_reservation_with_missing_param_max(self):
values = {
'lease_id': u'018c1b43-e69e-4aef-a543-09681539cf4c',
'min': u'2',
'hypervisor_properties': '["=", "$memory_mb", "256"]',
'resource_properties': '',
'start_date': datetime.datetime(2017, 3, 1, 20, 00),
'end_date': datetime.datetime(2017, 3, 2, 20, 00),
'resource_type': plugin.RESOURCE_TYPE,
}
self.assertRaises(
manager_exceptions.MissingParameter,
self.fake_phys_plugin.reserve_resource,
u'441c1476-9f8f-4700-9f30-cd9b6fef3509',
values)
def test_create_reservation_with_missing_param_properties(self):
values = {
'lease_id': u'018c1b43-e69e-4aef-a543-09681539cf4c',
'min': u'1',
'max': u'2',
'start_date': datetime.datetime(2017, 3, 1, 20, 00),
'end_date': datetime.datetime(2017, 3, 2, 20, 00),
'resource_type': plugin.RESOURCE_TYPE,
}
self.assertRaises(
manager_exceptions.MissingParameter,
self.fake_phys_plugin.reserve_resource,
u'441c1476-9f8f-4700-9f30-cd9b6fef3509',
values)
def test_create_reservation_with_invalid_param(self):
values = {
'lease_id': u'018c1b43-e69e-4aef-a543-09681539cf4c',