def parent_dir_layout(self): """obj: Layout instance of the file's parent directory""" if self._parent_dir_layout is None: layout = Layout(self.parent_dir_pathinfo) self._parent_dir_layout = layout else: layout = self._parent_dir_layout return layout
def validate_files_in_dir(host, rootdir, file_type=k.FILETYPE_ALL, test_type=k.TEST_ALL): """walk a directory tree and check if layout is_complete. Args: host (str): The host of the directory being traversed. rootdir (str): The fully qualified path of the dir being traversed. file_type (int): An or'd set of constants defining the file types to test. FILETYPE_DIR FILETYPE_DIRS FILETYPE_FILE FILETYPE_FILES FILETYPE_ALL test_type (int): An or'd set of constants defining the test types to run. TEST_LAYOUT_IS_COMPLETE TEST_LAYOUT_IS_BALANCED TEST_FILE_EXISTS_ON_HASHED_BRICKS TEST_ALL Examples: # TEST LAYOUTS FOR FILES IN A DIRECTORY validate_files_in_dir(clients[0], '/mnt/glusterfs') validate_files_in_dir(clients[0], '/mnt/glusterfs', file_type=k.FILETYPE_DIRS) validate_files_in_dir(clients[0], '/mnt/glusterfs', file_type=k.FILETYPE_FILES) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_COMPLETE, file_type=(k.FILETYPE_DIRS | k.FILETYPE_FILES)) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_BALANCED) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_BALANCED, file_type=k.FILETYPE_FILES) # TEST FILES IN DIRECTORY EXIST ON HASHED BRICKS validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_FILE_EXISTS_ON_HASHED_BRICKS) """ layout_cache = {} conn = g.rpyc_get_connection(host) for walkies in conn.modules.os.walk(rootdir): g.log.info("TESTING DIRECTORY %s..." % walkies[0]) # check directories if file_type & k.FILETYPE_DIR: for testdir in walkies[1]: fqpath = os.path.join(walkies[0], testdir) gdir = GlusterDir(host, fqpath) if gdir.parent_dir in layout_cache: layout = layout_cache[gdir.parent_dir] else: layout = Layout(gdir.parent_dir_pathinfo) layout_cache[gdir.parent_dir] = layout run_layout_tests(gdir.parent_dir, layout, test_type) if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS: run_hashed_bricks_test(gdir) # check files if file_type & k.FILETYPE_FILE: for file in walkies[2]: fqpath = os.path.join(walkies[0], file) gfile = GlusterFile(host, fqpath) if gfile.parent_dir in layout_cache: layout = layout_cache[gfile.parent_dir] else: layout = Layout(gfile.parent_dir_pathinfo) layout_cache[gfile.parent_dir] = layout run_layout_tests(gfile.parent_dir, layout, test_type) if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS: run_hashed_bricks_test(gfile) return True
def validate_files_in_dir(mnode, rootdir, file_type=k.FILETYPE_ALL, test_type=k.TEST_ALL): """walk a directory tree and check if layout is_complete. Args: mnode (str): The host of the directory being traversed. rootdir (str): The fully qualified path of the dir being traversed. file_type (int): An or'd set of constants defining the file types to test. FILETYPE_DIR FILETYPE_DIRS FILETYPE_FILE FILETYPE_FILES FILETYPE_ALL test_type (int): An or'd set of constants defining the test types to run. TEST_LAYOUT_IS_COMPLETE TEST_LAYOUT_IS_BALANCED TEST_FILE_EXISTS_ON_HASHED_BRICKS TEST_ALL Examples: # TEST LAYOUTS FOR FILES IN A DIRECTORY validate_files_in_dir(clients[0], '/mnt/glusterfs') validate_files_in_dir(clients[0], '/mnt/glusterfs', file_type=k.FILETYPE_DIRS) validate_files_in_dir(clients[0], '/mnt/glusterfs', file_type=k.FILETYPE_FILES) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_COMPLETE, file_type=(k.FILETYPE_DIRS | k.FILETYPE_FILES)) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_BALANCED) validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_LAYOUT_IS_BALANCED, file_type=k.FILETYPE_FILES) # TEST FILES IN DIRECTORY EXIST ON HASHED BRICKS validate_files_in_dir(clients[0], '/mnt/glusterfs', test_type=k.TEST_FILE_EXISTS_ON_HASHED_BRICKS) """ layout_cache = {} script_path = ("/usr/share/glustolibs/scripts/walk_dir.py") if not file_exists(mnode, script_path): if upload_scripts(mnode, script_path, "/usr/share/glustolibs/scripts/"): g.log.info("Successfully uploaded script " "walk_dir.py!") else: g.log.error("Faild to upload walk_dir.py!") return False else: g.log.info("compute_hash.py already present!") cmd = ("/usr/bin/env python {0} {1}".format(script_path, rootdir)) ret, out, _ = g.run(mnode, cmd) if ret: g.log.error('Unable to run the script on node {0}'.format(mnode)) return False for walkies in eval(out): g.log.info("TESTING DIRECTORY %s..." % walkies[0]) # check directories if file_type & k.FILETYPE_DIR: for testdir in walkies[1]: fqpath = os.path.join(walkies[0], testdir) gdir = GlusterDir(mnode, fqpath) if gdir.parent_dir in layout_cache: layout = layout_cache[gdir.parent_dir] else: layout = Layout(gdir.parent_dir_pathinfo) layout_cache[gdir.parent_dir] = layout run_layout_tests(mnode, gdir.parent_dir, layout, test_type) if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS: run_hashed_bricks_test(gdir) # check files if file_type & k.FILETYPE_FILE: for file in walkies[2]: fqpath = os.path.join(walkies[0], file) gfile = GlusterFile(mnode, fqpath) if gfile.parent_dir in layout_cache: layout = layout_cache[gfile.parent_dir] else: layout = Layout(gfile.parent_dir_pathinfo) layout_cache[gfile.parent_dir] = layout run_layout_tests(mnode, gfile.parent_dir, layout, test_type) if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS: run_hashed_bricks_test(gfile) return True