def test__other(self):
        _path = "/dev/null"
        if not os.path.exists(_path):
            logging.warn("%s does not exist. Skip this test." % _path)

        st_mode = Factory.lstat(_path)[0]
        self.assertEquals(Factory.guess_filetype(st_mode), G.TYPE_OTHER)
    def test_02_list__multi_generated_file(self):
        listfile = os.path.join(self.workdir, "file.list")
        listfile2 = os.path.join(self.workdir, "file2.list")
        config = init_config(listfile)

        line = "%s/file*.list\n" % self.workdir
        open(listfile, "w").write(line)
        open(listfile2, "w").write(line)

        collector = FilelistCollector(listfile, config)
        fos = collector.list(listfile)
        fos_ref = [Factory.create(listfile), Factory.create(listfile2)]

        self.assertEquals(sorted(fos), sorted(fos_ref))
Exemple #3
0
    def test_update(self):
        modifier = RpmAttributeModifier()

        f = F.create("/bin/bash")
        new_f = modifier.update(f)

        self.assertTrue(getattr(new_f, "rpm_attr", False))
    def test__symlink_missing(self):
        fo = B.Bunch(path=self.missinglink)
        fo = Factory.create_from_real_object(fo)

        self.assertTrue(isinstance(fo, FO.SymlinkObject))
        self.assertEquals(fo.type(), G.TYPE_SYMLINK)
        self.assertEquals(fo.path, self.missinglink)
    def test__file_w_mode(self):
        mode = "0600"

        fo = B.Bunch(path=self.file, mode=mode)
        fo = Factory.create_from_real_object(fo)

        self.assertEquals(fo.mode, mode)
    def test_copy__exists(self):
        fo = Factory.create(self.testfile1)
        dest = self.testfile1 + ".2"

        FileOps.copy(fo, dest)

        self.assertFalse(FileOps.copy(fo, dest))
    def test__dir_wo_metadata(self):
        fo = B.Bunch(path=self.dir)
        fo = Factory.create_from_real_object(fo)

        self.assertTrue(isinstance(fo, FO.DirObject))
        self.assertEquals(fo.type(), G.TYPE_DIR)
        self.assertEquals(fo.path, self.dir)
        self.assertEquals(fo.mode, self.dir_mode)
Exemple #8
0
    def test_pred__not_exist(self):
        filter = NotExistFilter()
        path = "/bin/sh"

        assert os.path.exists(path)

        fo = Factory.create(path)
        self.assertFalse(filter.pred(fo))
    def test__file_wo_metadata(self):
        fo = B.Bunch(path=self.file)
        fo = Factory.create_from_real_object(fo)

        self.assertTrue(isinstance(fo, FO.FileObject))
        self.assertEquals(fo.type(), G.TYPE_FILE)
        self.assertEquals(fo.path, self.file)
        self.assertEquals(fo.mode, self.file_mode)
    def test__file_w_uid_and_gid(self):
        uid = 1
        gid = 1

        fo = B.Bunch(path=self.file, uid=uid, gid=gid)
        fo = Factory.create_from_real_object(fo)

        self.assertEquals(fo.uid, uid)
        self.assertEquals(fo.gid, gid)
    def test__create_wo_attrs(self):
        fo = Factory.create(self.path)

        self.assertTrue(isinstance(fo, FO.DirObject))
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
        self.assertEquals(fo.path, self.path)
Exemple #12
0
    def test_pred__unsupported__fileobjects(self):
        username = pwd.getpwuid(os.getuid()).pw_name
        paths = ["/dev/null", "/dev/zero"] + glob.glob("/tmp/orbit-%s/linc-*" % username)[:3]  # device files  # socket

        paths = [p for p in paths if os.path.exists(p)]

        for p in paths:
            fo = Factory.create(p)
            self.assertTrue(self.filter.pred(fo))
    def test_copy_impl_and_remove(self):
        fo = Factory.create(self.testfile1)
        dest = self.testfile1 + ".2"

        FileOps.copy_impl(fo, dest)
        self.assertTrue(os.path.exists(dest))

        FileOps.remove(dest)
        self.assertFalse(os.path.exists(dest))
Exemple #14
0
    def test_pred__permitted_to_read(self):
        filter = ReadAccessFilter()
        pred = lambda f: os.path.exists(f) and os.access(f, os.R_OK)

        path = random.choice([p for p in ("/etc/hosts", "/etc/resolv.conf",
                                          "/etc/sysctl.conf")
                              if pred(p)])

        fo = Factory.create(path)
        self.assertFalse(filter.pred(fo))
    def test__dir_w_mode(self):
        mode = "0700"

        fo = B.Bunch(path=self.dir, mode=mode)
        fo = Factory.create_from_real_object(fo)

        self.assertTrue(isinstance(fo, FO.DirObject))
        self.assertEquals(fo.type(), G.TYPE_DIR)
        self.assertEquals(fo.path, self.dir)
        self.assertEquals(fo.mode, mode)
    def test__create_w_linkto(self):
        linkto = "/etc/hosts"
        fo = Factory.create(self.path, linkto=linkto)

        self.assertTrue(isinstance(fo, FO.SymlinkObject))
        self.assertEquals(fo.path, self.path)
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
        self.assertEquals(fo.linkto, linkto)
    def test__create_w_content(self):
        content = "Hello, world\n"
        fo = Factory.create(self.path, content=content)

        self.assertTrue(isinstance(fo, FO.FileObject))
        self.assertEquals(fo.path, self.path)
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
        self.assertEquals(fo.content, content)
    def test__create_w_src(self):
        src = "/etc/hosts"
        fo = Factory.create(self.path, src=src)

        self.assertTrue(isinstance(fo, FO.FileObject))
        self.assertEquals(fo.path, self.path)
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
        self.assertEquals(fo.src, src)
    def test__create_w_filetype_dir(self):
        filetype = FO.typestr_to_type("dir")
        fo = Factory.create(self.path, filetype=filetype)

        self.assertTrue(isinstance(fo, FO.DirObject))
        self.assertEquals(fo.type(), G.TYPE_DIR)
        self.assertEquals(fo.path, self.path)
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
    def test__create_w_filetype_symlink(self):
        filetype = FO.typestr_to_type("symlink")
        fo = Factory.create(self.path, filetype=filetype)

        self.assertTrue(isinstance(fo, FO.SymlinkObject))
        self.assertEquals(fo.type(), G.TYPE_SYMLINK)
        self.assertEquals(fo.path, self.path)
        self.assertEquals(fo.mode, fo.defaults.mode)
        self.assertEquals(fo.uid, fo.defaults.uid)
        self.assertEquals(fo.gid, fo.defaults.gid)
        self.assertEquals(fo.checksum, fo.defaults.checksum)
Exemple #21
0
    def test_pred__supported__fileobjects(self):
        paths = [
            "/etc/resolv.conf", "/etc/hosts",  # normal files
            "/etc",  # dirs
            "/etc/rc",  "/etc/init.d", "/etc/grub.conf"  # symlinks
        ]
        paths = [p for p in paths if os.path.exists(p)]

        for p in paths:
            fo = Factory.create(p)
            self.assertFalse(self.filter.pred(fo))
    def _parse(self, bobj):
        """
        :param bobj: A Bunch object holds path and attrs (metadata) of files.
        """
        path = bobj.get("path", False)

        if not path or path.startswith("#"):
            return []
        else:
            paths = "*" in path and glob.glob(path) or [path]
            attrs = bobj.get("attrs", dict())

            return [Factory.create(p, self.use_rpmdb, **attrs) for p in paths]
    def test_02__parse__single_virtual_file(self):
        listfile = "/a/b/c/path.conf"
        config = init_config(listfile)

        line = " %s,create=1,content=\"generated file\" \n" % listfile

        collector = FilelistCollector(listfile, config)
        fos = collector._parse(line)
        fos_ref = [Factory.create(listfile, False,
                                  create=1, content="generated file")]

        self.assertNotEquals(fos, [])
        self.assertEquals(fos, fos_ref)
    def test__file_dir_and_symlink(self):
        st_mode = Factory.lstat(self.file)[0]
        self.assertEquals(Factory.guess_filetype(st_mode), G.TYPE_FILE)

        st_mode = Factory.lstat(self.dir)[0]
        self.assertEquals(Factory.guess_filetype(st_mode), G.TYPE_DIR)

        st_mode = Factory.lstat(self.symlink)[0]
        self.assertEquals(Factory.guess_filetype(st_mode), G.TYPE_SYMLINK)
    def test_04_collect__single_real_file__no_rpms_own(self):
        path = random.choice(SYSTEM_FILES_EXIST_AND_NO_RPMS_OWN)

        listfile = os.path.join(self.workdir, "file.list")
        config = init_config(listfile)

        open(listfile, "w").write(path + "\n")

        collector = FilelistCollector(listfile, config)

        fos = collector.collect()
        fo_ref = Factory.create(path, use_rpmdb=(not config.no_rpmdb))

        self.assertEquals(fos[0].path, path)
        self.assertEquals(fos, [fo_ref])
    def test_03_list__multi_real_files(self):
        listfile = os.path.join(self.workdir, "file.list")
        config = init_config(listfile)

        open(listfile, "w").write("\n".join(PATHS))

        collector = FilelistCollector(listfile, config)

        ur = not config.no_rpmdb
        fos = collector.list(listfile)
        fos_ref = sorted(
            Factory.create(p, use_rpmdb=ur) for p in PATHS_EXPANDED
        )

        self.assertEquals(sorted(fos), fos_ref)
    def test_08_collect__single_real_file__ignore_owner_mod(self):
        listfile = path = os.path.join(self.workdir, "file.list")

        config = init_config(listfile)
        config.ignore_owner = True

        open(listfile, "w").write(path + "\n")

        collector = FilelistCollector(listfile, config)

        fos = collector.collect()
        fo_ref = Factory.create(path, False)

        self.assertEquals(fos[0].uid, 0)
        self.assertEquals(fos[0].gid, 0)
    def _parse(self, line):
        """Parse the line and returns FileObjects list generator.
        """
        # remove extra white spaces at the top and the end.
        line = line.rstrip().strip()

        if not line or line.startswith("#"):
            return []
        else:
            try:
                (paths, attrs) = P.parse_line_of_filelist(line)
            except ValueError:
                print "line=" + line
                raise

            return [Factory.create(p, self.use_rpmdb, **attrs) for p in paths]
    def test_07_collect__single_real_file__destdir_mod(self):
        listfile = path = os.path.join(self.workdir, "file.list")

        config = init_config(listfile)
        config.destdir = self.workdir

        open(listfile, "w").write(path + "\n")

        collector = FilelistCollector(listfile, config)

        fos = collector.collect()
        fo_ref = Factory.create(path, False)

        self.assertEquals(
            os.path.join(self.workdir, fos[0].path),
            fo_ref.path
        )
    def test_09_collect__single_real_file__rpmattr(self):
        path = random.choice(["/etc/hosts", "/etc/services"])

        listfile = os.path.join(self.workdir, "file.list")
        config = init_config(listfile)
        config.driver = "autotools.single.rpm"

        open(listfile, "w").write(path + "\n")

        collector = FilelistCollector(listfile, config)

        fos = collector.collect()
        fo_ref = Factory.create(path, False)

        ## should differ as RpmConflictsFilter works.
        #self.assertEquals(fos, [fo_ref])
        self.assertTrue("rpm_attr" in fos[0])