summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2020-04-20 14:41:59 +0530
committerBala Konda Reddy M <bala12352@gmail.com>2020-04-20 10:10:13 +0000
commit5d9a0ab8e46475af390272a0916e9f075153ca4b (patch)
tree7f177334ee3c24d60983d27da0aeaf912a29d32c /tests
parentedca79c9161256c2722a27d89f64bd2ac6103e9a (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')
-rw-r--r--tests/functional/glusterd/test_add_brick_when_quorum_not_met.py2
-rw-r--r--tests/functional/glusterd/test_add_identical_brick_new_node.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/tests/functional/glusterd/test_add_brick_when_quorum_not_met.py b/tests/functional/glusterd/test_add_brick_when_quorum_not_met.py
index 7d8aad0e0..2cb21227b 100644
--- a/tests/functional/glusterd/test_add_brick_when_quorum_not_met.py
+++ b/tests/functional/glusterd/test_add_brick_when_quorum_not_met.py
@@ -100,7 +100,7 @@ class TestAddBrickWhenQuorumNotMet(GlusterBaseClass):
# bring down glusterd of half nodes
num_of_servers = len(self.servers)
- num_of_nodes_to_bring_down = num_of_servers/2
+ num_of_nodes_to_bring_down = num_of_servers//2
for node in range(num_of_nodes_to_bring_down, num_of_servers):
ret = stop_glusterd(self.servers[node])
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])