Merge "Python3 code compatibility: division, round"

This commit is contained in:
Jenkins 2016-03-23 11:30:40 +00:00 committed by Gerrit Code Review
commit ca50c2f7a5
12 changed files with 50 additions and 18 deletions

View File

@ -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))

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import division
import json
import os

View File

@ -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

View File

@ -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:

View File

@ -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)),

View File

@ -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": {

View File

@ -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'

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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(

View File

@ -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)