def test_goodness_weigher_passing_host(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState( 'host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': '100' } }) host_state_2 = fakes.FakeBackendState( 'host2', { 'host': 'host2.example.com', 'capabilities': { 'goodness_function': '0' } }) host_state_3 = fakes.FakeBackendState( 'host3', { 'host': 'host3.example.com', 'capabilities': { 'goodness_function': '100 / 2' } }) weight_properties = {} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(100, weight) weight = weigher._weigh_object(host_state_2, weight_properties) self.assertEqual(0, weight) weight = weigher._weigh_object(host_state_3, weight_properties) self.assertEqual(50, weight)
def test_extend_volume(self, mock_extend, mock_consume, mock_backend_passes): volume = fake_volume.fake_volume_obj(self.context, **{'size': 1}) fake_backend = fake_scheduler.FakeBackendState('host1', {}) mock_backend_passes.return_value = fake_backend self.manager.extend_volume(self.context, volume, 2, 'fake_reservation') mock_consume.assert_called_once_with({'size': 1}) mock_extend.assert_called_once_with(self.context, volume, 2, 'fake_reservation')
def test_goodness_weigher_host_rating_out_of_bounds(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState('host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': '-10' } }) host_state_2 = fakes.FakeBackendState('host2', { 'host': 'host2.example.com', 'capabilities': { 'goodness_function': '200' } }) weight_properties = {} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(0, weight) weight = weigher._weigh_object(host_state_2, weight_properties) self.assertEqual(0, weight)
def test_goodness_weigher_with_no_goodness_function(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState('host1', { 'host': 'host.example.com', 'capabilities': { 'foo': '50' } }) weight_properties = {} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(0, weight)
def test_goodness_weigher_extra_specs_substitution(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState( 'host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': '10 + extra.foo' } }) weight_properties = {'volume_type': {'extra_specs': {'foo': 50}}} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(60, weight)
def test_goodness_weigher_invalid_substitution(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState('host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': '10 + stats.my_val' }, 'foo': 50 }) weight_properties = {} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(0, weight)
def test_goodness_weigher_stats_substitution(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState('host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': 'stats.free_capacity_gb > 20' }, 'free_capacity_gb': 50 }) weight_properties = {} weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(100, weight)
def test_manage_existing_snapshot(self, mock_manage_existing_snapshot, mock_consume, mock_backend_passes): volume = fake_volume.fake_volume_obj(self.context, **{'size': 1}) fake_backend = fake_scheduler.FakeBackendState('host1', {}) mock_backend_passes.return_value = fake_backend self.manager.manage_existing_snapshot(self.context, volume, 'fake_snapshot', 'fake_ref', None) mock_consume.assert_called_once_with({'size': 1}) mock_manage_existing_snapshot.assert_called_once_with( self.context, 'fake_snapshot', 'fake_ref', volume.service_topic_queue)
def test_goodness_weigher_untyped_volume(self): weigher = goodness.GoodnessWeigher() host_state = fakes.FakeBackendState('host1', { 'host': 'host.example.com', 'capabilities': { 'goodness_function': '67' } }) weight_properties = { 'volume_type': None, } weight = weigher._weigh_object(host_state, weight_properties) self.assertEqual(67, weight)