msg_args = {"host": host_state.host,
"requested": volume_size,
"available": free}
- if free < volume_size:
- LOG.warning(_LW("Insufficient free space for volume creation "
- "on host %(host)s (requested / avail): "
- "%(requested)s/%(available)s"), msg_args)
- return free >= volume_size
- else:
- LOG.debug("Space information for volume creation "
- "on host %(host)s (requested / avail): "
- "%(requested)s/%(available)s", msg_args)
# Only evaluate using max_over_subscription_ratio if
# thin_provisioning_support is True. Check if the ratio of
# provisioned capacity over total capacity has exceeded over
# subscription ratio.
if (host_state.thin_provisioning_support and
- host_state.max_over_subscription_ratio >= 1):
+ host_state.max_over_subscription_ratio > 1):
provisioned_ratio = ((host_state.provisioned_capacity_gb +
volume_size) / total)
if provisioned_ratio >= host_state.max_over_subscription_ratio:
free_virtual = free * host_state.max_over_subscription_ratio
return free_virtual >= volume_size
- return free >= volume_size
+ if free < volume_size:
+ LOG.warning(_LW("Insufficient free space for volume creation "
+ "on host %(host)s (requested / avail): "
+ "%(requested)s/%(available)s"), msg_args)
+ return False
+
+ LOG.debug("Space information for volume creation "
+ "on host %(host)s (requested / avail): "
+ "%(requested)s/%(available)s", msg_args)
+
+ return True
'service': service})
self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ @mock.patch('cinder.utils.service_is_up')
+ def test_filter_over_subscription_less_than_1(self, _mock_serv_is_up):
+ _mock_serv_is_up.return_value = True
+ filt_cls = self.class_map['CapacityFilter']()
+ filter_properties = {'size': 200,
+ 'capabilities:thin_provisioning_support':
+ '<is> True',
+ 'capabilities:thick_provisioning_support':
+ '<is> False'}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1',
+ {'total_capacity_gb': 500,
+ 'free_capacity_gb': 100,
+ 'provisioned_capacity_gb': 400,
+ 'max_over_subscription_ratio': 0.8,
+ 'reserved_percentage': 0,
+ 'thin_provisioning_support': True,
+ 'thick_provisioning_support': False,
+ 'updated_at': None,
+ 'service': service})
+ self.assertFalse(filt_cls.host_passes(host, filter_properties))
+
@mock.patch('cinder.utils.service_is_up')
def test_filter_over_subscription_fails(self, _mock_serv_is_up):
_mock_serv_is_up.return_value = True
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,
'free_capacity_gb': 200,
- 'provisioned_capacity_gb': 500,
- 'max_over_subscription_ratio': 1.0,
+ 'provisioned_capacity_gb': 700,
+ 'max_over_subscription_ratio': 1.5,
'reserved_percentage': 5,
'thin_provisioning_support': True,
'thick_provisioning_support': False,
def test_filter_over_subscription_fails2(self, _mock_serv_is_up):
_mock_serv_is_up.return_value = True
filt_cls = self.class_map['CapacityFilter']()
- filter_properties = {'size': 30,
+ filter_properties = {'size': 2000,
'capabilities:thin_provisioning_support':
'<is> True',
'capabilities:thick_provisioning_support':
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,
'free_capacity_gb': 30,
- 'provisioned_capacity_gb': 500,
- 'max_over_subscription_ratio': 1.0,
+ 'provisioned_capacity_gb': 9000,
+ 'max_over_subscription_ratio': 20,
'reserved_percentage': 0,
'thin_provisioning_support': True,
'thick_provisioning_support': False,
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,
'free_capacity_gb': 100,
- 'provisioned_capacity_gb': 500,
+ 'provisioned_capacity_gb': 1000,
'max_over_subscription_ratio': 2.0,
'reserved_percentage': 5,
'thin_provisioning_support': True,
service = {'disabled': False}
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,
- 'free_capacity_gb': 100,
- 'provisioned_capacity_gb': 400,
+ 'free_capacity_gb': 0,
+ 'provisioned_capacity_gb': 800,
'max_over_subscription_ratio': 2.0,
'reserved_percentage': 5,
'thin_provisioning_support': True,
'service': service})
self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ @mock.patch('cinder.utils.service_is_up')
+ def test_filter_reserved_thin_true_passes(self, _mock_serv_is_up):
+ _mock_serv_is_up.return_value = True
+ filt_cls = self.class_map['CapacityFilter']()
+ filter_properties = {'size': 100,
+ 'capabilities:thin_provisioning_support':
+ '<is> True',
+ 'capabilities:thick_provisioning_support':
+ '<is> False'}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1',
+ {'total_capacity_gb': 500,
+ 'free_capacity_gb': 80,
+ 'provisioned_capacity_gb': 600,
+ 'max_over_subscription_ratio': 2.0,
+ 'reserved_percentage': 5,
+ 'thin_provisioning_support': True,
+ 'thick_provisioning_support': False,
+ 'updated_at': None,
+ 'service': service})
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+
@mock.patch('cinder.utils.service_is_up')
def test_filter_reserved_thin_thick_true_fails2(self, _mock_serv_is_up):
_mock_serv_is_up.return_value = True
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,
'free_capacity_gb': 99,
- 'provisioned_capacity_gb': 400,
+ 'provisioned_capacity_gb': 1000,
'max_over_subscription_ratio': 2.0,
'reserved_percentage': 5,
'thin_provisioning_support': True,