From 6dec4463635091eed01f4e96f7a83715c3735986 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 13 Feb 2019 11:49:36 -0500 Subject: [PATCH] Use math.gcd starting with python 3.5 fractions.gcd is deprecated started in python 3.5 so this change uses math.gcd if on py3 and fractions.gcd if on py2. Change-Id: Ib3dd924e967bc9b48d81dc81e1fcdeba0120985c --- nova/virt/hardware.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 9eaa17ae2f..a6ae6ae3d4 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -15,6 +15,7 @@ import collections import fractions import itertools +import math from oslo_log import log as logging from oslo_serialization import jsonutils @@ -743,8 +744,12 @@ def _pack_instance_onto_cores(host_cell, instance_cell, threads) and 2 (number of 'orphan' CPUs) and get 2 as the number of threads. """ - return fractions.gcd(threads_per_core, _orphans(instance_cell, - threads_per_core)) + # fractions.gcd is deprecated in favor of math.gcd starting in py35 + if six.PY2: + gcd = fractions.gcd + else: + gcd = math.gcd + return gcd(threads_per_core, _orphans(instance_cell, threads_per_core)) def _get_pinning(threads_no, sibling_set, instance_cores): """Determines pCPUs/vCPUs mapping