def test_create_dir_object_exists(self): td = tempfile.mkdtemp() the_path = os.path.join(td, "vol0", "bar") the_dir = os.path.join(the_path, "dir") try: os.makedirs(the_path) with open(the_dir, "wb") as fd: fd.write("1234") gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "dir/z", self.lg) # Not created, dir object path is different, just checking assert gdf._obj == "z" def _mock_do_chown(p, u, g): assert u == DEFAULT_UID assert g == DEFAULT_GID dc = gluster.swift.common.DiskFile.do_chown gluster.swift.common.DiskFile.do_chown = _mock_do_chown try: gdf._create_dir_object(the_dir) finally: gluster.swift.common.DiskFile.do_chown = dc assert os.path.isdir(the_dir) assert the_dir in _metadata finally: shutil.rmtree(td)
def test_create_dir_object(self): td = tempfile.mkdtemp() the_dir = os.path.join(td, "vol0", "bar", "dir") try: gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "dir/z", self.lg) # Not created, dir object path is different, just checking assert gdf._obj == "z" gdf._create_dir_object(the_dir) assert os.path.isdir(the_dir) assert the_dir in _metadata finally: shutil.rmtree(td)
def test_create_dir_object_no_md(self): td = tempfile.mkdtemp() the_cont = os.path.join(td, "vol0", "bar") the_dir = "dir" try: os.makedirs(the_cont) gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", os.path.join(the_dir, "z"), self.lg) # Not created, dir object path is different, just checking assert gdf._obj == "z" gdf._create_dir_object(the_dir) full_dir_path = os.path.join(the_cont, the_dir) assert os.path.isdir(full_dir_path) assert full_dir_path not in _metadata finally: shutil.rmtree(td)
def test_create_dir_object_with_md(self): td = tempfile.mkdtemp() the_cont = os.path.join(td, "vol0", "bar") the_dir = "dir" try: os.makedirs(the_cont) gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", os.path.join(the_dir, "z"), self.lg) # Not created, dir object path is different, just checking assert gdf._obj == "z" dir_md = {'Content-Type': 'application/directory', X_OBJECT_TYPE: DIR_OBJECT} gdf._create_dir_object(the_dir, dir_md) full_dir_path = os.path.join(the_cont, the_dir) assert os.path.isdir(full_dir_path) assert full_dir_path in _metadata finally: shutil.rmtree(td)