summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgii Karataev <gkaratae@redhat.com>2019-10-04 16:32:57 +0200
committerGeorgii Karataev <gkaratae@redhat.com>2019-10-24 15:56:33 +0200
commite973b997f8aa5c783a5955fbb9c1421424e633e5 (patch)
tree9dba5da5189470dcfba6bc167f49a8798da47764
parentf6da61ad955d6f4f77ccef723f7eb68068b957c2 (diff)
Fix flavor choosing in beakerd
Current beakerd chooses flavor only according to its disk size. It was caused by bad sorting implementation. This is now should be fixed and sorting will also consider the ram size and id. Change-Id: I928ec15fd4ae7de92b05d0cfe7e815c110ef6343
-rw-r--r--IntegrationTests/src/bkr/inttest/server/test_beakerd.py16
-rw-r--r--Server/bkr/server/tools/beakerd.py7
2 files changed, 8 insertions, 15 deletions
diff --git a/IntegrationTests/src/bkr/inttest/server/test_beakerd.py b/IntegrationTests/src/bkr/inttest/server/test_beakerd.py
index b90c755..662d5e1 100644
--- a/IntegrationTests/src/bkr/inttest/server/test_beakerd.py
+++ b/IntegrationTests/src/bkr/inttest/server/test_beakerd.py
@@ -2014,29 +2014,23 @@ class TestProvisionVirtRecipes(DatabaseTestCase):
# https://bugzilla.redhat.com/show_bug.cgi?id=1397649
def test_cheapest_OpenStack_flavor_should_be_picked(self):
- beakerd.process_new_recipes()
- beakerd.update_dirty_jobs()
- beakerd.queue_processed_recipesets()
- beakerd.update_dirty_jobs()
- beakerd.provision_virt_recipes()
- beakerd.update_dirty_jobs()
+ self._run_beakerd_once()
with session.begin():
recipe = Recipe.query.get(self.recipe.id)
self.assertIsNotNone(recipe,
"Failed to get recipe ID %s" % self.recipe.id)
self.assertIsNotNone(recipe.resource,
"Recipe ID %s does not have a resource" % self.recipe.id)
- instance = self.virt_manager.novaclient.servers.get(
- recipe.resource.instance_id)
+ instance = self.virt_manager.novaclient.servers.get(recipe.resource.instance_id)
available_flavors = self.virt_manager.available_flavors()
# remove the flavor that has no disk
# and flavor with really small disk
for flavor in available_flavors:
if flavor.disk < 10:
available_flavors.remove(flavor)
- # cheapest flavor is smallest disk and smallest ram
- smallest_disk_list = sorted(available_flavors, key=lambda flavor: flavor.disk)
- cheapest_flavor = sorted(smallest_disk_list, key=lambda flavor: flavor.ram)[0]
+ # cheapest flavor has the smallest disk and ram
+ # id guarantees consistency of our results
+ cheapest_flavor = min(available_flavors, key=lambda flavor: (flavor.ram, flavor.disk, flavor.id))
instance_flavor = self.virt_manager.novaclient.flavors.get(instance.flavor['id'])
self.assertEquals(instance_flavor.ram, cheapest_flavor.ram)
self.assertEquals(instance_flavor.id, cheapest_flavor.id)
diff --git a/Server/bkr/server/tools/beakerd.py b/Server/bkr/server/tools/beakerd.py
index fc10bbe..4cb93e1 100644
--- a/Server/bkr/server/tools/beakerd.py
+++ b/Server/bkr/server/tools/beakerd.py
@@ -520,10 +520,9 @@ def provision_virt_recipe(recipe_id):
recipe.id)
recipe.virt_status = RecipeVirtStatus.precluded
return
- # cheapest flavor is smallest disk and smallest ram
- smallest_disk_list = sorted(possible_flavors, key=lambda flavor: flavor.disk)
- possible_flavors = sorted(smallest_disk_list, key=lambda flavor: flavor.ram)
- flavor = possible_flavors[0]
+ # cheapest flavor has the smallest disk and ram
+ # id guarantees consistency of our results
+ flavor = min(possible_flavors, key=lambda flavor: (flavor.ram, flavor.disk, flavor.id))
vm_name = '%srecipe-%s' % (
ConfigItem.by_name(u'guest_name_prefix').current_value(u'beaker-'),
recipe.id)