def test_dir_operation(self): mgr = fs_mgr() f = mgr.get_fs_by_name("test_dir") f.create_dir("test") dir_list = f.ls_dir() found = False for each_dir in dir_list: if each_dir["name"] == "test": found = True self.assertEquals(each_dir["mode"], 0777) self.assertEquals(each_dir["abspath"], "/mnt/test_dir/test") self.assertEquals(each_dir["relpath"], "test") self.assertEquals(each_dir["user"], "root") self.assertEquals(each_dir["group"], "root") self.assertTrue(found) f.mod_dir_mode("test", 0666) dir_list = f.ls_dir() for each_dir in dir_list: if each_dir["name"] == "test": self.assertEquals(each_dir["mode"], 0666) f.mod_dir_owner("test", "root", "root") usage_list = f.dir_usage_stat("test") found = False for each_usage in usage_list: if each_usage["abspath"] == "/mnt/test_dir/test": found = True self.assertTrue(found) f.delete_dir("test")
def setUp(self): mgr = fs_mgr() dev_file = get_block_dev() if dev_file == "": return mgr.mkfs_on_dev("ext4", dev_file) mgr.add_fs("test_dir", "ext4", dev_file, comment="test")
def del_fs(request): user = request.client_addr fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs_mrg.del_fs(fs_name, user) return Response(status=200)
def del_fs(request): user=request.client_addr fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs_mrg.del_fs(fs_name,user) return Response(status=200)
def get_fs_ls(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, get_fs_ls_schema) path = params["path"] ls_info = fs.ls_dir(path) return ls_info
def del_quota_user(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, del_quoat_group_schema) user = params["user"] fs.quota_group_set(user,0,0,0,0) return Response(status=200)
def del_quota_user(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, del_quoat_group_schema) user = params["user"] fs.quota_group_set(user, 0, 0, 0, 0) return Response(status=200)
def get_fs(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) fs_info = { 'name': fs.name, 'conf': fs.fs_conf, 'available': fs.is_available(), 'usage': fs.usage_info() } return fs_info
def change_fs(request): params = get_params_from_request(request, change_fs_schema) fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) if (params['opt']) == 'grow': fs.grow_size() return Response(status=200) else: return Response(status=403)
def get_fs(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) fs_info = { 'name':fs.name, 'conf':fs.fs_conf, 'available':fs.is_available(), 'usage': fs.usage_info() } return fs_info
def change_fs(request): params = get_params_from_request(request, change_fs_schema) fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) if(params['opt']) == 'grow' : fs.grow_size() return Response(status=200) else : return Response(status=403)
def test_quota_operation(self): mgr = fs_mgr() f = mgr.get_fs_by_name("test_quota") f.quota_check() ureport = f.quota_user_report() found = False for uquota in ureport: if uquota["name"] == "root": found = True self.assertEquals(uquota["block_softlimit"], 0) self.assertEquals(uquota["block_hardlimit"], 0) self.assertEquals(uquota["inode_softlimit"], 0) self.assertEquals(uquota["inode_hardlimit"], 0) self.assertTrue(found) greport = f.quota_group_report() found = False for gquota in greport: if gquota["name"] == "root": found = True self.assertEquals(gquota["block_softlimit"], 0) self.assertEquals(gquota["block_hardlimit"], 0) self.assertEquals(gquota["inode_softlimit"], 0) self.assertEquals(gquota["inode_hardlimit"], 0) self.assertTrue(found) f.quota_user_set("root", 1000, 1500, 2000, 2500) f.quota_group_set("root", 3000, 3500, 4000, 4500) f.quota_check() ureport = f.quota_user_report() found = False for uquota in ureport: if uquota["name"] == "root": found = True self.assertEquals(uquota["block_softlimit"], 1000) self.assertEquals(uquota["block_hardlimit"], 1500) self.assertEquals(uquota["inode_softlimit"], 2000) self.assertEquals(uquota["inode_hardlimit"], 2500) self.assertTrue(found) greport = f.quota_group_report() found = False for gquota in greport: if gquota["name"] == "root": found = True self.assertEquals(gquota["block_softlimit"], 3000) self.assertEquals(gquota["block_hardlimit"], 3500) self.assertEquals(gquota["inode_softlimit"], 4000) self.assertEquals(gquota["inode_hardlimit"], 4500) self.assertTrue(found)
def get_fs_list(request): fs_mrg = fsmgr.fs_mgr() files = fs_mrg.get_fs_list() fs_dict = [] for fs in files: fs_info = { 'name':fs.name, 'conf':fs.fs_conf, 'available':fs.is_available(), } fs_dict.append(fs_info) return fs_dict
def put_quota_user(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, put_quoat_group_schema) user = params["user"] block_softlimit = params["block_softlimit"] block_hardlimit = params["block_hardlimit"] inode_softlimit = params["inode_softlimit"] inode_hardlimit = params["inode_hardlimit"] fs.quota_user_set(user,block_softlimit,block_hardlimit,inode_softlimit,inode_hardlimit) return Response(status=200)
def add_quota_group(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, add_quoat_group_schema) group = params["group"] block_softlimit = params["block_softlimit"] block_hardlimit = params["block_hardlimit"] inode_softlimit = params["inode_softlimit"] inode_hardlimit = params["inode_hardlimit"] fs.quota_group_set(group,block_softlimit,block_hardlimit,inode_softlimit,inode_hardlimit) return Response(status=200)
def get_fs_list(request): fs_mrg = fsmgr.fs_mgr() files = fs_mrg.get_fs_list() fs_dict = [] for fs in files: fs_info = { 'name': fs.name, 'conf': fs.fs_conf, 'available': fs.is_available(), } fs_dict.append(fs_info) return fs_dict
def put_quota_user(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, put_quoat_group_schema) user = params["user"] block_softlimit = params["block_softlimit"] block_hardlimit = params["block_hardlimit"] inode_softlimit = params["inode_softlimit"] inode_hardlimit = params["inode_hardlimit"] fs.quota_user_set(user, block_softlimit, block_hardlimit, inode_softlimit, inode_hardlimit) return Response(status=200)
def add_quota_group(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, add_quoat_group_schema) group = params["group"] block_softlimit = params["block_softlimit"] block_hardlimit = params["block_hardlimit"] inode_softlimit = params["inode_softlimit"] inode_hardlimit = params["inode_hardlimit"] fs.quota_group_set(group, block_softlimit, block_hardlimit, inode_softlimit, inode_hardlimit) return Response(status=200)
def test_add_fs(self): mgr = fs_mgr() dev_file = get_nfs_src() if dev_file == "": return mgr.mkfs_on_dev("nfs", dev_file) mgr.add_fs("test_nfs", "nfs", dev_file, comment="test") for fs in mgr.get_fs_list(): if fs.name == "test_nfs": break; else: raise Exception("there is no file system name test_nfs") f = mgr.get_fs_by_name("test_nfs") self.assertEquals(f.fs_conf["dev_file"], dev_file) self.assertEquals(f.fs_conf["comment"], "test") self.assertTrue(f.is_available()) self.assertTrue(f.usage_info()["total"] > 0) self.assertTrue(len(f.fs_meta_dump()) != 0) with open("/etc/fstab", "r") as fstab: self.assertTrue("/mnt/test_nfs" in fstab.read()) mgr.del_fs("test_nfs")
def test_add_fs(self): mgr = fs_mgr() dev_file = get_nfs_src() if dev_file == "": return mgr.mkfs_on_dev("nfs", dev_file) mgr.add_fs("test_nfs", "nfs", dev_file, comment="test") for fs in mgr.get_fs_list(): if fs.name == "test_nfs": break else: raise Exception("there is no file system name test_nfs") f = mgr.get_fs_by_name("test_nfs") self.assertEquals(f.fs_conf["dev_file"], dev_file) self.assertEquals(f.fs_conf["comment"], "test") self.assertTrue(f.is_available()) self.assertTrue(f.usage_info()["total"] > 0) self.assertTrue(len(f.fs_meta_dump()) != 0) with open("/etc/fstab", "r") as fstab: self.assertTrue("/mnt/test_nfs" in fstab.read()) mgr.del_fs("test_nfs")
def file_opt_owner(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, get_fs_ls_schema) path = params["path"] if (params['opt']) == 'mod_owner': user = params["user"] group = params["group"] fs.mod_dir_owner(path, user, group, request.client_addr) return Response(status=200) elif params['opt'] == 'mod_mode': mode = params["mode"] fs.mod_dir_mode(path, mode, request.client_addr) return Response(status=200) elif params['opt'] == 'quota_check': mode = params["mode"] fs.quota_check() return Response(status=200) else: return Response(status=403)
def file_opt_owner(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) params = get_params_from_request(request, get_fs_ls_schema) path = params["path"] if(params['opt']) == 'mod_owner' : user = params["user"] group = params["group"] fs.mod_dir_owner(path,user,group,request.client_addr) return Response(status=200) elif params['opt'] == 'mod_mode' : mode = params["mode"] fs.mod_dir_mode(path,mode,request.client_addr) return Response(status=200) elif params['opt'] == 'quota_check' : mode = params["mode"] fs.quota_check() return Response(status=200) else : return Response(status=403)
def tearDown(self): mgr = fs_mgr() mgr.del_fs("test_quota")
def mk_fs(request): fs_mrg = fsmgr.fs_mgr() params = get_params_from_request(request, mk_fs_schema) fs_mrg.mkfs_on_dev(params["type"], params["dev"], params["options"]) return Response(status=200)
def test_mkfs_no_option(self): mgr = fs_mgr() dev_file = get_block_dev() if dev_file == "": return mgr.mkfs_on_dev("xfs", dev_file)
def mk_fs(request): fs_mrg = fsmgr.fs_mgr() params = get_params_from_request(request, mk_fs_schema) fs_mrg.mkfs_on_dev(params["type"],params["dev"],params["options"]) return Response(status=200)
def tearDown(self): mgr = fs_mgr() mgr.del_fs("test_dir")
def test_type_list(self): mgr = fs_mgr() self.assertTrue("xfs" in mgr.fs_type_list())
def get_fs_meda(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) meta_info = fs.fs_meta_dump() return meta_info
def get_quota_user_list(request): fs_name = request.matchdict['fsname'] fs_mrg = fsmgr.fs_mgr() fs = fs_mrg.get_fs_by_name(fs_name) quota_user_info = fs.quota_user_report() return quota_user_info
def get_fs_type_list(request): fs_mrg = fsmgr.fs_mgr() type_list = fs_mrg.fs_type_list() return type_list
def add_fs(request): fs_mrg = fsmgr.fs_mgr() params = get_params_from_request(request, add_fs_schema) fs_mrg.add_fs(params["fsname"],params["type"],params["dev"],\ params["mountoption"],params["checkonboot"],params["user"]) return Response(status=200)
def test_type_list(self): mgr = fs_mgr() self.assertTrue("nfs" in mgr.fs_type_list())
def test_mkfs_no_option(self): mgr = fs_mgr() nfs_source = get_nfs_src() if nfs_source == "": return mgr.mkfs_on_dev("nfs", nfs_source)