diff options
author | kshithijiyer <kshithij.ki@gmail.com> | 2020-04-20 14:41:59 +0530 |
---|---|---|
committer | Bala Konda Reddy M <bala12352@gmail.com> | 2020-04-20 10:10:13 +0000 |
commit | 5d9a0ab8e46475af390272a0916e9f075153ca4b (patch) | |
tree | 7f177334ee3c24d60983d27da0aeaf912a29d32c /tests/functional/glusterd/test_add_identical_brick_new_node.py | |
parent | edca79c9161256c2722a27d89f64bd2ac6103e9a (diff) |
[py2py3] Fixing a bunch of python3 incompatibilities
Problem:
There are two python2 to python3 incompatibilities
present in test_add_brick_when_quorum_not_met.py
and test_add_identical_brick_new_node.py.
In test_add_brick_when_quorum_not_met.py the testcase
fails with the below error:
> for node in range(num_of_nodes_to_bring_down, num_of_servers):
E TypeError: 'float' object cannot be interpreted as an integer
This is because a = 10 / 5 returns a float in python3
but it returns a int in python2 as shown below:
Python 2.7.15 (default, Oct 15 2018, 15:26:09)
[GCC 8.2.1 20180801 (Red Hat 8.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 10/5
>>> type(a)
<type 'int'>
Python 3.7.3 (default, Mar 27 2019, 13:41:07)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 10/5
>>> type(a)
<class 'float'>
In test_add_identical_brick_new_node.py testcase
fails with the below error:
> add_bricks.append(string.replace(bricks_list[0],
self.servers[0], self.servers[1]))
E AttributeError: module 'string' has no attribute 'replace'
This is because string is depriciated in python3 and
is replaced with str.
Solution:
For the first issue we would need to change
a = 10/5 to a = 10//5 as it is constant
across both python versions.
For the second issue adding try except
block as shown below would be suffice:
except AttributeError:
add_bricks.append(str.replace(bricks_list[0],
self.servers[0],
self.servers[1]))
Change-Id: I9ec325760b279032af3748101bd2bfc58589d57d
Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
Diffstat (limited to 'tests/functional/glusterd/test_add_identical_brick_new_node.py')
-rw-r--r-- | tests/functional/glusterd/test_add_identical_brick_new_node.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/functional/glusterd/test_add_identical_brick_new_node.py b/tests/functional/glusterd/test_add_identical_brick_new_node.py index ce643fbae..849894943 100644 --- a/tests/functional/glusterd/test_add_identical_brick_new_node.py +++ b/tests/functional/glusterd/test_add_identical_brick_new_node.py @@ -115,8 +115,14 @@ class TestAddIdenticalBrick(GlusterBaseClass): # Replace just host IP to create identical brick add_bricks = [] - add_bricks.append(string.replace(bricks_list[0], - self.servers[0], self.servers[1])) + try: + add_bricks.append(string.replace(bricks_list[0], + self.servers[0], + self.servers[1])) + except AttributeError: + add_bricks.append(str.replace(bricks_list[0], + self.servers[0], + self.servers[1])) ret, _, _ = add_brick(self.mnode, self.volname, add_bricks) self.assertEqual(ret, 0, "Failed to add the bricks to the volume") g.log.info("Successfully added bricks to volume %s", add_bricks[0]) |