コード例 #1
0
    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)
コード例 #2
0
    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))
コード例 #3
0
ファイル: RpmModifiers.py プロジェクト: ssato/packagemaker
    def test_update(self):
        modifier = RpmAttributeModifier()

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

        self.assertTrue(getattr(new_f, "rpm_attr", False))
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    def test_copy__exists(self):
        fo = Factory.create(self.testfile1)
        dest = self.testfile1 + ".2"

        FileOps.copy(fo, dest)

        self.assertFalse(FileOps.copy(fo, dest))
コード例 #7
0
    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)
コード例 #8
0
ファイル: Filters.py プロジェクト: masatake/packagemaker
    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))
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
0
    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)
コード例 #12
0
ファイル: Filters.py プロジェクト: masatake/packagemaker
    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))
コード例 #13
0
    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))
コード例 #14
0
ファイル: Filters.py プロジェクト: ssato/packagemaker
    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))
コード例 #15
0
    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)
コード例 #16
0
    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)
コード例 #17
0
    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)
コード例 #18
0
    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)
コード例 #19
0
    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)
コード例 #20
0
    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)
コード例 #21
0
ファイル: Filters.py プロジェクト: ssato/packagemaker
    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))
コード例 #22
0
    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]
コード例 #23
0
    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)
コード例 #24
0
    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)
コード例 #25
0
    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])
コード例 #26
0
    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)
コード例 #27
0
    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)
コード例 #28
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]
コード例 #29
0
    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
        )
コード例 #30
0
    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])