def test_use_of_chance_weigher_via_host_manager(self): # ensure we don't lose any hosts when weighing with # the ChanceWeigher hm = host_manager.HostManager() fake_backends = [host_manager.BackendState('fake_be%s' % x, None) for x in range(1, 5)] weighed_backends = hm.get_weighed_backends(fake_backends, {}, 'ChanceWeigher') self.assertEqual(4, len(weighed_backends))
def test_post_select_populate(self): # Test addition of certain filter props after a node is selected. retry = {'backends': [], 'num_attempts': 1} filter_properties = {'retry': retry} sched = fakes.FakeFilterScheduler() backend_state = host_manager.BackendState('host', None) backend_state.total_capacity_gb = 1024 sched._post_select_populate_filter_properties(filter_properties, backend_state) self.assertEqual('host', filter_properties['retry']['backends'][0]) self.assertEqual(1024, backend_state.total_capacity_gb)
def test_get_filtered_objects_info_and_debug_log_none_returned(self): all_filters = [FilterA, FilterA, FilterB] fake_backends = [ host_manager.BackendState('fake_be%s' % x, None) for x in range(1, 4) ] filt_props = { "request_spec": { 'volume_id': fake.VOLUME_ID, 'volume_properties': { 'project_id': fake.PROJECT_ID, 'size': 2048, 'host': 'host4' } } } with mock.patch.object(base_filter, 'LOG') as mock_log: result = self.handler.get_filtered_objects(all_filters, fake_backends, filt_props) self.assertFalse(result) msg = "with volume ID '%s'" % fake.VOLUME_ID # FilterA should leave Host1 and Host2; FilterB should leave None. exp_output = ("FilterA: (start: 3, end: 2), " "FilterA: (start: 2, end: 1)") cargs = mock_log.info.call_args[0][0] self.assertIn(msg, cargs) self.assertIn(exp_output, cargs) exp_output = ("[('FilterA', ['fake_be2', 'fake_be3']), " "('FilterA', ['fake_be3']), " + "('FilterB', None)]") cargs = mock_log.debug.call_args[0][0] self.assertIn(msg, cargs) self.assertIn(exp_output, cargs)