Merge "Lease creation/updation should fail for invalid affinity"
This commit is contained in:
@@ -402,16 +402,16 @@ reservation:
|
|||||||
type: object
|
type: object
|
||||||
reservation_affinity:
|
reservation_affinity:
|
||||||
description: |
|
description: |
|
||||||
The affinity of instances to reserve.
|
The affinity of instances to reserve. The value should be ``True``, ``False`` or ``None``.
|
||||||
in: body
|
in: body
|
||||||
required: true
|
required: true
|
||||||
type: boolean
|
type: trilean
|
||||||
reservation_affinity_optional:
|
reservation_affinity_optional:
|
||||||
description: |
|
description: |
|
||||||
The affinity of instances to reserve.
|
The affinity of instances to reserve. The value should be ``True``, ``False`` or ``None``.
|
||||||
in: body
|
in: body
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: trilean
|
||||||
reservation_aggregate_id:
|
reservation_aggregate_id:
|
||||||
description: |
|
description: |
|
||||||
The aggregate ID of the reservation.
|
The aggregate ID of the reservation.
|
||||||
|
@@ -43,6 +43,8 @@ RESERVATION_PREFIX = 'reservation'
|
|||||||
FLAVOR_EXTRA_SPEC = "aggregate_instance_extra_specs:" + RESERVATION_PREFIX
|
FLAVOR_EXTRA_SPEC = "aggregate_instance_extra_specs:" + RESERVATION_PREFIX
|
||||||
INSTANCE_DELETION_TIMEOUT = 10 * 60 * 1000 # 10 minutes
|
INSTANCE_DELETION_TIMEOUT = 10 * 60 * 1000 # 10 minutes
|
||||||
|
|
||||||
|
NONE_VALUES = ('None', 'none', None)
|
||||||
|
|
||||||
|
|
||||||
class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
||||||
"""Plugin for virtual instance resources."""
|
"""Plugin for virtual instance resources."""
|
||||||
@@ -399,6 +401,12 @@ class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise mgr_exceptions.MalformedParameter(six.text_type(e))
|
raise mgr_exceptions.MalformedParameter(six.text_type(e))
|
||||||
|
|
||||||
|
if 'affinity' in values:
|
||||||
|
if (values['affinity'] not in NONE_VALUES and
|
||||||
|
not strutils.is_valid_boolstr(values['affinity'])):
|
||||||
|
raise mgr_exceptions.MalformedParameter(
|
||||||
|
param='affinity (must be a bool value or None)')
|
||||||
|
|
||||||
def reserve_resource(self, reservation_id, values):
|
def reserve_resource(self, reservation_id, values):
|
||||||
self._check_missing_reservation_params(values)
|
self._check_missing_reservation_params(values)
|
||||||
self._validate_reservation_params(values)
|
self._validate_reservation_params(values)
|
||||||
|
@@ -142,6 +142,17 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
|||||||
'server_group_id': 2,
|
'server_group_id': 2,
|
||||||
'aggregate_id': 3})
|
'aggregate_id': 3})
|
||||||
|
|
||||||
|
@ddt.data("abc", 2, "2")
|
||||||
|
def test_affinity_error(self, value):
|
||||||
|
plugin = instance_plugin.VirtualInstancePlugin()
|
||||||
|
inputs = self.get_input_values(2, 4018, 10, 1, value,
|
||||||
|
'2030-01-01 08:00', '2030-01-01 08:00',
|
||||||
|
'lease-1', '')
|
||||||
|
self.assertRaises(mgr_exceptions.MalformedParameter,
|
||||||
|
plugin.reserve_resource, 'reservation_id', inputs)
|
||||||
|
self.assertRaises(mgr_exceptions.MalformedParameter,
|
||||||
|
plugin.update_reservation, 'reservation_id', inputs)
|
||||||
|
|
||||||
@ddt.data(-1, 0, '0', 'one')
|
@ddt.data(-1, 0, '0', 'one')
|
||||||
def test_error_with_amount(self, value):
|
def test_error_with_amount(self, value):
|
||||||
plugin = instance_plugin.VirtualInstancePlugin()
|
plugin = instance_plugin.VirtualInstancePlugin()
|
||||||
@@ -400,7 +411,8 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
|||||||
expected_query = ['vcpus >= 2', 'memory_mb >= 2048', 'local_gb >= 100']
|
expected_query = ['vcpus >= 2', 'memory_mb >= 2048', 'local_gb >= 100']
|
||||||
mock_host_get_query.assert_called_once_with(expected_query)
|
mock_host_get_query.assert_called_once_with(expected_query)
|
||||||
|
|
||||||
def test_pickup_host_with_no_affinity(self):
|
@ddt.data('None', 'none', None)
|
||||||
|
def test_pickup_host_with_no_affinity(self, value):
|
||||||
def fake_get_reservation_by_host(host_id, start, end):
|
def fake_get_reservation_by_host(host_id, start, end):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -435,7 +447,7 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
|||||||
'memory_mb': 4096,
|
'memory_mb': 4096,
|
||||||
'disk_gb': 200,
|
'disk_gb': 200,
|
||||||
'amount': 2,
|
'amount': 2,
|
||||||
'affinity': None,
|
'affinity': value,
|
||||||
'resource_properties': '',
|
'resource_properties': '',
|
||||||
'start_date': datetime.datetime(2030, 1, 1, 8, 00),
|
'start_date': datetime.datetime(2030, 1, 1, 8, 00),
|
||||||
'end_date': datetime.datetime(2030, 1, 1, 12, 00)
|
'end_date': datetime.datetime(2030, 1, 1, 12, 00)
|
||||||
|
Reference in New Issue
Block a user