diff --git a/blazar/plugins/oshosts/host_plugin.py b/blazar/plugins/oshosts/host_plugin.py index 2bf5d227..dd6c5f9b 100644 --- a/blazar/plugins/oshosts/host_plugin.py +++ b/blazar/plugins/oshosts/host_plugin.py @@ -15,7 +15,7 @@ # under the License. import datetime -from random import Random +import random import retrying from novaclient import exceptions as nova_exceptions @@ -654,12 +654,12 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): allocated_host_ids.append(host['id']) if len(not_allocated_host_ids) >= int(min_host): if CONF[self.resource_type].randomize_host_selection: - Random.shuffle(not_allocated_host_ids) + random.shuffle(not_allocated_host_ids) return not_allocated_host_ids[:int(max_host)] all_host_ids = allocated_host_ids + not_allocated_host_ids if len(all_host_ids) >= int(min_host): if CONF[self.resource_type].randomize_host_selection: - Random.shuffle(all_host_ids) + random.shuffle(all_host_ids) return all_host_ids[:int(max_host)] else: return [] diff --git a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py index 86ebf510..18b27d2e 100644 --- a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py +++ b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py @@ -2431,7 +2431,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.addCleanup(CONF.clear_override, 'cleaning_time') self.assertEqual(['host1', 'host2', 'host3'], result) - @mock.patch.object(random.Random, "shuffle") + @mock.patch.object(random, "shuffle") def test_random_matching_hosts_not_allocated_hosts(self, mock_shuffle): def host_allocation_get_all_by_values(**kwargs): if kwargs['compute_host_id'] == 'host1': @@ -2465,7 +2465,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): group=plugin.RESOURCE_TYPE) mock_shuffle.assert_called_once_with(['host2', 'host3']) - @mock.patch.object(random.Random, "shuffle") + @mock.patch.object(random, "shuffle") def test_random_matching_hosts_allocated_hosts(self, mock_shuffle): def host_allocation_get_all_by_values(**kwargs): if kwargs['compute_host_id'] == 'host1': @@ -2499,7 +2499,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): group=plugin.RESOURCE_TYPE) mock_shuffle.assert_called_once_with(['host1', 'host2', 'host3']) - @mock.patch.object(random.Random, "shuffle") + @mock.patch.object(random, "shuffle") def test_random_matching_hosts_allocated_cleaning_time(self, mock_shuffle): def host_allocation_get_all_by_values(**kwargs): if kwargs['compute_host_id'] == 'host1': diff --git a/releasenotes/notes/fix-host-randomization-bcab5276ef6199e6.yaml b/releasenotes/notes/fix-host-randomization-bcab5276ef6199e6.yaml new file mode 100644 index 00000000..e6ed412f --- /dev/null +++ b/releasenotes/notes/fix-host-randomization-bcab5276ef6199e6.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes functionality of host randomization feature. + `LP#2099927 `__