def test_create_empty_folders(self): managed_folder = os.path.join(self.mount_point_1, self.path_on_mount_point) os.makedirs(managed_folder) new_dirs = [] copy_tuples = [] for depth_2_dir in self.depth_2_dirs: new_dir = os.path.join( os.path.split(os.path.split(depth_2_dir)[0])[1], os.path.split(depth_2_dir)[1]) new_dir = os.path.join(managed_folder, new_dir) new_dirs.append(new_dir) copy_tuples.append((depth_2_dir, new_dir)) x_man = OSDManager.OSDManager(managed_folder) x_man.create_empty_folders(new_dirs) # now copy files manually and check whether the data layout is good for src, dst in copy_tuples: shutil.rmtree(dst, ignore_errors=True) # shutil.copytree requires that the target directory does not exist shutil.copytree(src, dst) self.assertEqual( count_folder_and_files(managed_folder), count_folder_and_files( os.path.join(self.tmp_folder, self.test_files_folder))) self.assertTrue(verify.verify_gms_folder(managed_folder))
def test_get_target_dir(self): osd_man = OSDManager.OSDManager(self.absolute_path_to_managed_folder, value_map=self.value_map) folder_id = os.path.join(self.volume_name, self.path_on_volume, self.some_folder, self.some_sub_folder) target_dir = osd_man.get_target_dir(folder_id) expected_target_dir = os.path.join(self.path_to_mount, self.path_on_volume, self.some_folder) self.assertEqual(expected_target_dir, target_dir)
def test_update(self): managed_folder = os.path.join(self.mount_point_1, self.path_on_mount_point) os.makedirs(managed_folder) new_dirs = [] copy_tuples = [] for depth_2_dir in self.depth_2_dirs: new_dir = os.path.join( os.path.split(os.path.split(depth_2_dir)[0])[1], os.path.split(depth_2_dir)[1]) new_dir = os.path.join(managed_folder, new_dir) new_dirs.append(new_dir) copy_tuples.append((depth_2_dir, new_dir)) x_man = OSDManager.OSDManager(managed_folder) x_man.create_empty_folders(new_dirs) for src, dst in copy_tuples: shutil.rmtree(dst, ignore_errors=True) # shutil.copytree requires that the target directory does not exist shutil.copytree(src, dst) du_source = subprocess.run([ "du", "-s", os.path.join(self.tmp_folder, self.test_files_folder) ], stdout=subprocess.PIPE, universal_newlines=True) size_source = int(str(du_source.stdout).split()[0]) total_size_in_distribution = 0 for osd in x_man.distribution.OSDs.values(): total_size_in_distribution += osd.total_folder_size self.assertNotEqual(size_source, total_size_in_distribution) x_man.update() du_source = subprocess.run([ "du", "-s", os.path.join(self.tmp_folder, self.test_files_folder) ], stdout=subprocess.PIPE, universal_newlines=True) size_source = int(str(du_source.stdout).split()[0]) total_size_in_distribution = 0 for osd in x_man.distribution.OSDs.values(): total_size_in_distribution += osd.total_folder_size self.assertEqual(size_source, total_size_in_distribution)
def test_path_on_volume(self): osd_man = OSDManager.OSDManager(self.absolute_path_to_managed_folder, value_map=self.value_map) self.assertEqual( os.path.join(self.volume_name, self.path_on_volume, self.some_folder), osd_man.get_path_on_volume( os.path.join(self.path_to_mount, self.path_on_volume, self.some_folder))) with self.assertRaises(OSDManager.PathNotManagedException): osd_man.get_path_on_volume(self.absolute_path_random)
def test_read_write(self): managed_folder_1 = os.path.join(self.mount_point_1, self.path_on_mount_point) os.makedirs(managed_folder_1) x_man_1 = OSDManager.OSDManager(managed_folder_1) x_man_1.copy_folders(self.depth_2_dirs) total_size_in_distribution_1 = 0 for osd in x_man_1.distribution.OSDs.values(): total_size_in_distribution_1 += osd.total_folder_size managed_folder_2 = os.path.join(self.mount_point_2, self.path_on_mount_point) x_man_2 = OSDManager.OSDManager(managed_folder_2) total_size_in_distribution_2 = 0 for osd in x_man_2.distribution.OSDs.values(): total_size_in_distribution_2 += osd.total_folder_size self.assertEqual(total_size_in_distribution_1, total_size_in_distribution_2)
def test_copy_folders(self): managed_folder = os.path.join(self.mount_point_1, self.path_on_mount_point) os.makedirs(managed_folder) x_man = OSDManager.OSDManager(managed_folder) x_man.copy_folders(self.depth_2_dirs) self.assertTrue(verify.verify_gms_folder(managed_folder)) self.assertEqual( count_folder_and_files(managed_folder), count_folder_and_files( os.path.join(self.tmp_folder, self.test_files_folder)))
parser.add_argument("--movement-strategy", nargs=1) args = parser.parse_args() if args.debug: print("args: ") print(args) if args.verify: good_layout = verify.verify_gms_folder(vars(args)['target-folder'][0]) print("good_layout: ", good_layout) # if not good_layout: # verify.print_tree(vars(args)['target-folder'][0]) sys.exit(0) x_man = OSDManager.OSDManager(vars(args)['target-folder'][0], debug=args.debug) if args.print: print(x_man) if args.copy: if len(args.source_folders) == 0: print("You must specify folders to copy with --source-folders") sys.exit(1) else: folders = args.source_folders[0].split(',') x_man.copy_folders(folders, environment=args.environment, apply_layout=(not args.random_layout), remote_source=args.remote_source[0],
def test_init_no_xtreemfs_volume(self): dummy_path = '/' with self.assertRaises(OSDManager.NotAXtreemFSVolume): OSDManager.OSDManager(dummy_path)