From dd2382c613db6f3dd72a25c74d5f765006aea31f Mon Sep 17 00:00:00 2001 From: kshithijiyer Date: Wed, 1 Apr 2020 10:44:54 +0530 Subject: [Libfix] Remove rpyc_get_connection() dependency from code Problem: `g.rpyc_get_connection()` has a limitaion where it can't convert python2 calls to python3 calls. Due to this a large number of testcases fail when executed from a python2 machine on a python3 only setup or visa versa with the below stack trace: ``` E ========= Remote Traceback (1) ========= E Traceback (most recent call last): E File "/root/tmp.tL8Eqx7d8l/rpyc/core/protocol.py", line 323, in _dispatch_request E res = self._HANDLERS[handler](self, *args) E File "/root/tmp.tL8Eqx7d8l/rpyc/core/protocol.py", line 591, in _handle_inspect E if hasattr(self._local_objects[id_pack], '____conn__'): E File "/root/tmp.tL8Eqx7d8l/rpyc/lib/colls.py", line 110, in __getitem__ E return self._dict[key][0] E KeyError: (b'rpyc.core.service.SlaveService', 94282642994712, 140067150858560) ``` Solution: The solution here is to modify the code to not use `g.rpyc_get_connection()`. The following changes are done to accomplish it: 1)Remove code which uses g.rpyc_get_connection() and use generic logic in functions: a. do_bricks_exist_in_shd_volfile() b. get_disk_usage() c. mount_volume() d. list_files() f. append_string_to_file() 2)Create files which can be uploaded and executed on clients/servers to avoid rpc calls in functions: a. calculate_hash() b. validate_files_in_dir() 3)Modify setup.py to push the below files to `/usr/share/glustolibs/scripts/`: a.compute_hash.py b.walk_dir.py Change-Id: I00a81a88382bf3f8b366753eebdb2999260788ca Signed-off-by: kshithijiyer --- glustolibs-gluster/scripts/compute_hash.py | 26 ++++++++++++++++++++++++++ glustolibs-gluster/scripts/walk_dir.py | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 glustolibs-gluster/scripts/compute_hash.py create mode 100644 glustolibs-gluster/scripts/walk_dir.py (limited to 'glustolibs-gluster/scripts') diff --git a/glustolibs-gluster/scripts/compute_hash.py b/glustolibs-gluster/scripts/compute_hash.py new file mode 100644 index 000000000..b5ae2f83b --- /dev/null +++ b/glustolibs-gluster/scripts/compute_hash.py @@ -0,0 +1,26 @@ +# Copyright (C) 2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from __future__ import print_function +import ctypes +import sys + +filename = sys.argv[1] +glusterfs = ctypes.cdll.LoadLibrary("libglusterfs.so.0") +computed_hash = ctypes.c_uint32(glusterfs.gf_dm_hashfn(filename, + len(filename))) + +print(computed_hash.value) diff --git a/glustolibs-gluster/scripts/walk_dir.py b/glustolibs-gluster/scripts/walk_dir.py new file mode 100644 index 000000000..02d115b0b --- /dev/null +++ b/glustolibs-gluster/scripts/walk_dir.py @@ -0,0 +1,26 @@ +# Copyright (C) 2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from __future__ import print_function +import os +import sys + +rootdir = sys.argv[1] + +list_of_levels = [] +for level in os.walk(rootdir): + list_of_levels.append(level) +print(list_of_levels) -- cgit