From ed07d4aae7ea157223e50cd4d464d17438a0229f Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Tue, 15 Mar 2016 15:18:54 +0300 Subject: [PATCH] Python3 code compatibility: division, round Make division transparent-compatible (from __future__ import division, // for strict int result) Do not use round due to different types of result objects blueprint fuel-qa-python3-compatibility Related-bug: #1556791 Change-Id: I7bb173c6f97ac046af45c3f52cc32846a93a8981 --- fuelweb_test/helpers/checkers.py | 7 +++++-- fuelweb_test/helpers/rally.py | 2 ++ fuelweb_test/helpers/utils.py | 20 ++++++++++--------- fuelweb_test/models/fuel_web_client.py | 4 +++- fuelweb_test/testrail/report.py | 4 +++- .../test_fuel_plugin_contrail.py | 4 ++++ fuelweb_test/tests/test_admin_node.py | 4 +++- fuelweb_test/tests/test_ha_one_controller.py | 4 +++- fuelweb_test/tests/test_multiple_networks.py | 4 +++- fuelweb_test/tests/test_services.py | 2 ++ system_test/actions/base.py | 7 ++++++- system_test/core/factory.py | 6 +++++- 12 files changed, 50 insertions(+), 18 deletions(-) diff --git a/fuelweb_test/helpers/checkers.py b/fuelweb_test/helpers/checkers.py index a679ef484..711558da5 100644 --- a/fuelweb_test/helpers/checkers.py +++ b/fuelweb_test/helpers/checkers.py @@ -11,6 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from __future__ import division + import hashlib import json import os @@ -159,7 +162,7 @@ def check_ceph_image_size(ip, expected_size, device='vdc'): ssh_manager.check_call(ip=ip, cmd="df -m"))) raise Exception() logger.debug("Partitions: {part}".format(part=ret)) - assert_true(abs(float(ret[0].rstrip()) / float(expected_size) - 1) < 0.1, + assert_true(abs(float(ret[0].rstrip()) / expected_size - 1) < 0.1, "size {0} is not equal" " to {1}".format(ret[0].rstrip(), expected_size)) @@ -169,7 +172,7 @@ def check_ceph_image_size(ip, expected_size, device='vdc'): def check_cinder_image_size(ip, expected_size, device='vdc3'): ret = get_mongo_partitions(ip, device)[0].rstrip().rstrip('G') cinder_size = float(ret) * 1024 - assert_true(abs(cinder_size / float(expected_size) - 1) < 0.1, + assert_true(abs(cinder_size / expected_size - 1) < 0.1, "size {0} is not equal" " to {1}".format(ret[0].rstrip(), expected_size)) diff --git a/fuelweb_test/helpers/rally.py b/fuelweb_test/helpers/rally.py index 05b12c8ba..e5d7330a6 100644 --- a/fuelweb_test/helpers/rally.py +++ b/fuelweb_test/helpers/rally.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import json import os diff --git a/fuelweb_test/helpers/utils.py b/fuelweb_test/helpers/utils.py index 8e5781595..d9113241a 100644 --- a/fuelweb_test/helpers/utils.py +++ b/fuelweb_test/helpers/utils.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import ConfigParser # pylint: disable=no-name-in-module from distutils import version @@ -594,17 +596,17 @@ def node_freemem(remote, unit='MB'): swap_free = run_on_remote(remote, cmd_swap_free)[0] ret = { "mem": { - "total": int(mem_free.split()[1]) / denominator, - "used": int(mem_free.split()[2]) / denominator, - "free": int(mem_free.split()[3]) / denominator, - "shared": int(mem_free.split()[4]) / denominator, - "buffers": int(mem_free.split()[5]) / denominator, - "cached": int(mem_free.split()[6]) / denominator + "total": int(mem_free.split()[1]) // denominator, + "used": int(mem_free.split()[2]) // denominator, + "free": int(mem_free.split()[3]) // denominator, + "shared": int(mem_free.split()[4]) // denominator, + "buffers": int(mem_free.split()[5]) // denominator, + "cached": int(mem_free.split()[6]) // denominator }, "swap": { - "total": int(swap_free.split()[1]) / denominator, - "used": int(swap_free.split()[2]) / denominator, - "free": int(swap_free.split()[3]) / denominator, + "total": int(swap_free.split()[1]) // denominator, + "used": int(swap_free.split()[2]) // denominator, + "free": int(swap_free.split()[3]) // denominator, } } return ret diff --git a/fuelweb_test/models/fuel_web_client.py b/fuelweb_test/models/fuel_web_client.py index 89a6239d6..1f2593555 100644 --- a/fuelweb_test/models/fuel_web_client.py +++ b/fuelweb_test/models/fuel_web_client.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import re import time import traceback @@ -1696,7 +1698,7 @@ class FuelWebClient(object): @staticmethod def get_range(ip_network, ip_range=0): net = list(netaddr.IPNetwork(str(ip_network))) - half = len(net) / 2 + half = len(net) // 2 if ip_range == 0: return [[str(net[2]), str(net[-2])]] elif ip_range == 1: diff --git a/fuelweb_test/testrail/report.py b/fuelweb_test/testrail/report.py index 483fba6c0..fb12c95fc 100755 --- a/fuelweb_test/testrail/report.py +++ b/fuelweb_test/testrail/report.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import functools import re import time @@ -163,7 +165,7 @@ def get_job_parameter(jenkins_build_data, parameter): def get_version_from_parameters(jenkins_build_data): custom_version = get_job_parameter(jenkins_build_data, 'CUSTOM_VERSION') if custom_version: - swarm_timestamp = jenkins_build_data['timestamp'] / 1000 \ + swarm_timestamp = jenkins_build_data['timestamp'] // 1000 \ if 'timestamp' in jenkins_build_data else None return (TestRailSettings.milestone, time.strftime("%D %H:%M", time.localtime(swarm_timestamp)), diff --git a/fuelweb_test/tests/plugins/plugin_contrail/test_fuel_plugin_contrail.py b/fuelweb_test/tests/plugins/plugin_contrail/test_fuel_plugin_contrail.py index cfbabe8a5..d9a101e13 100644 --- a/fuelweb_test/tests/plugins/plugin_contrail/test_fuel_plugin_contrail.py +++ b/fuelweb_test/tests/plugins/plugin_contrail/test_fuel_plugin_contrail.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import os import os.path import time @@ -179,7 +181,9 @@ class ContrailPlugin(TestBasic): nailgun_nodes = \ self.fuel_web.client.list_cluster_nodes(self.cluster_id) base_os_disk = 40960 + # pylint: disable=round-builtin base_os_disk_gb = ("{0}G".format(round(base_os_disk / 1024, 1))) + # pylint: enable=round-builtin logger.info('disk size is {0}'.format(base_os_disk_gb)) disk_part = { "vda": { diff --git a/fuelweb_test/tests/test_admin_node.py b/fuelweb_test/tests/test_admin_node.py index bdfcf9a73..78eb9805b 100644 --- a/fuelweb_test/tests/test_admin_node.py +++ b/fuelweb_test/tests/test_admin_node.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import datetime import random import re @@ -153,7 +155,7 @@ class TestLogrotateBase(TestBasic): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if data >= prefix[s]: - value = float(data) / prefix[s] + value = data / prefix[s] return format(value, '.1f'), s return data, 'B' diff --git a/fuelweb_test/tests/test_ha_one_controller.py b/fuelweb_test/tests/test_ha_one_controller.py index fbae2b490..56b9011ba 100644 --- a/fuelweb_test/tests/test_ha_one_controller.py +++ b/fuelweb_test/tests/test_ha_one_controller.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import re from devops.helpers.helpers import wait @@ -674,7 +676,7 @@ class NodeDiskSizes(TestBasic): for disk in node['meta']['disks']: assert_equal(disk['size'], disk_size, 'Disk size') - hdd_size = "{} TB HDD".format(float(disk_size * 3 / (10 ** 9)) / 1000) + hdd_size = "{} TB HDD".format((disk_size * 3 / (10 ** 9)) / 1000) notifications = self.fuel_web.client.get_notifications() for node in nailgun_nodes: # assert /api/notifications diff --git a/fuelweb_test/tests/test_multiple_networks.py b/fuelweb_test/tests/test_multiple_networks.py index 99bc7b1d4..b588b25a2 100644 --- a/fuelweb_test/tests/test_multiple_networks.py +++ b/fuelweb_test/tests/test_multiple_networks.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import json from devops.helpers.helpers import wait @@ -603,7 +605,7 @@ class TestMultipleClusterNets(TestBasic): # floating range public2_cidr = self.env.d_env.get_network(name='public2').ip new_settings_float = { - 'floating_ranges': [[str(public2_cidr[public2_cidr.numhosts / 2]), + 'floating_ranges': [[str(public2_cidr[public2_cidr.numhosts // 2]), str(public2_cidr[-2])]] } self.fuel_web.client.update_network(cluster_id, new_settings_float) diff --git a/fuelweb_test/tests/test_services.py b/fuelweb_test/tests/test_services.py index 348d814ef..cf9f41d42 100644 --- a/fuelweb_test/tests/test_services.py +++ b/fuelweb_test/tests/test_services.py @@ -528,7 +528,9 @@ class CeilometerHAOneControllerMongo(OSTFCeilometerHelper): logger.debug('disk size is {0}'.format(disk_mb)) mongo_disk_mb = 11116 os_disk_mb = disk_mb - mongo_disk_mb + # pylint: disable=round-builtin mongo_disk_gb = ("{0}G".format(round(mongo_disk_mb / 1024, 1))) + # pylint: enable=round-builtin disk_part = { "vda": { "os": os_disk_mb, diff --git a/system_test/actions/base.py b/system_test/actions/base.py index a91dfd098..8849ba957 100644 --- a/system_test/actions/base.py +++ b/system_test/actions/base.py @@ -11,6 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from __future__ import division + import time from proboscis import SkipTest @@ -90,8 +93,10 @@ class PrepareActions(object): def _finish_case(self): """Finish test case""" case_time = time.time() - self._start_time - minutes = int(round(case_time)) / 60 + minutes = case_time // 60 + # pylint: disable=round-builtin seconds = int(round(case_time)) % 60 + # pylint: enable=round-builtin name = getattr(self, "__doc__", self.__class__.__name__).splitlines()[0] finish_case = "[ FINISH {} CASE TOOK {} min {} sec ]".format( diff --git a/system_test/core/factory.py b/system_test/core/factory.py index df000c5da..4691a85af 100644 --- a/system_test/core/factory.py +++ b/system_test/core/factory.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import division + import functools import types @@ -34,8 +36,10 @@ def step_start_stop(func): logger.info("\n{header}\n".format(header=header)) result = func(*args, **kwargs) spent_time = timer.spent_time - minutes = int(round(spent_time)) / 60 + minutes = spent_time // 60 + # pylint: disable=round-builtin seconds = int(round(spent_time)) % 60 + # pylint: enable=round-builtin finish_step = "[ FINISH {} STEP TOOK {} min {} sec ]".format( step_name, minutes, seconds) footer = "<<< {:-^142} >>>".format(finish_step)