コード例 #1
0
 def test_path_lookup_bind_mount(self):
     with tempfile.NamedTemporaryFile(prefix="drgn-tests-") as f:
         old_mnt = path_lookup(self.prog, os.path.abspath(f.name)).mnt
         mount(f.name, f.name, "", MS_BIND, "")
         try:
             new_mnt = path_lookup(self.prog, os.path.abspath(f.name)).mnt
             self.assertNotEqual(old_mnt, new_mnt)
         finally:
             umount(f.name)
コード例 #2
0
 def test_inode_paths(self):
     with tempfile.TemporaryDirectory(prefix="drgn-tests-") as dir:
         path1 = os.fsencode(os.path.abspath(os.path.join(dir, "a")))
         path2 = os.fsencode(os.path.abspath(os.path.join(dir, "b")))
         with open(path1, "w") as f:
             os.link(path1, path2)
             with open(path2, "r") as f:
                 inode = path_lookup(self.prog, path1).dentry.d_inode
                 paths = list(inode_paths(inode))
                 self.assertEqual(len(paths), 2)
                 self.assertTrue(
                     (path1.endswith(paths[0]) and path2.endswith(paths[1]))
                     or (path1.endswith(paths[1]) and path2.endswith(paths[0]))
                 )
                 self.assertIn(inode_path(inode), paths)
コード例 #3
0
ファイル: test_tc.py プロジェクト: osandov/drgn
    def test_qdisc_lookup(self):
        try:
            self.ns.link("add", ifname="dummy0", kind="dummy")
        except NetlinkError:
            self.skipTest(
                "kernel does not support dummy interface (CONFIG_DUMMY)")

        dummy = self.ns.link_lookup(ifname="dummy0")[0]

        # tc qdisc add dev dummy0 root handle 1: prio
        try:
            self.ns.tc(
                "add",
                kind="prio",
                index=dummy,
                handle="1:",
                # default TCA_OPTIONS for sch_prio, see [iproute2] tc/q_prio.c:prio_parse_opt()
                bands=3,
                priomap=[1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
            )
        except NetlinkError:
            self.ns.link("delete", ifname="dummy0")
            self.skipTest(
                "kernel does not support Multi Band Priority Queueing (CONFIG_NET_SCH_PRIO)"
            )
        # tc qdisc add dev dummy0 parent 1:1 handle 10: sfq
        try:
            self.ns.tc("add",
                       kind="sfq",
                       index=dummy,
                       parent="1:1",
                       handle="10:")
        except NetlinkError:
            self.ns.link("delete", ifname="dummy0")
            self.skipTest(
                "kernel does not support Stochastic Fairness Queueing (CONFIG_NET_SCH_SFQ)"
            )
        # tc qdisc add dev dummy0 parent 1:2 handle 20: tbf rate 20kbit buffer 1600 limit 3000
        try:
            self.ns.tc(
                "add",
                kind="tbf",
                index=dummy,
                parent="1:2",
                handle="20:",
                rate=2500,
                burst=1600,
                limit=3000,
            )
        except NetlinkError:
            self.ns.link("delete", ifname="dummy0")
            self.skipTest(
                "kernel does not support Token Bucket Filter (CONFIG_NET_SCH_TBF)"
            )
        # tc qdisc add dev dummy0 parent 1:3 handle 30: sfq
        self.ns.tc("add", kind="sfq", index=dummy, parent="1:3", handle="30:")
        # tc qdisc add dev dummy0 ingress
        try:
            self.ns.tc("add", kind="ingress", index=dummy)
        except NetlinkError:
            self.ns.link("delete", ifname="dummy0")
            self.skipTest(
                "kernel does not support ingress Qdisc (CONFIG_NET_SCH_INGRESS)"
            )

        inode = path_lookup(
            self.prog,
            os.path.realpath(f"/var/run/netns/{self.name}")).dentry.d_inode
        netdev = netdev_get_by_name(get_net_ns_by_inode(inode), "dummy0")

        self.assertEqual(qdisc_lookup(netdev, 0x1).ops.id.string_(), b"prio")
        self.assertEqual(qdisc_lookup(netdev, 0x10).ops.id.string_(), b"sfq")
        self.assertEqual(qdisc_lookup(netdev, 0x20).ops.id.string_(), b"tbf")
        self.assertEqual(qdisc_lookup(netdev, 0x30).ops.id.string_(), b"sfq")
        self.assertEqual(
            qdisc_lookup(netdev, 0xFFFF).ops.id.string_(), b"ingress")

        self.ns.link("delete", ifname="dummy0")
コード例 #4
0
 def test_path_lookup(self):
     with tempfile.NamedTemporaryFile(prefix="drgn-tests-") as f:
         path = path_lookup(self.prog, os.path.abspath(f.name))
         self.assertEqual(
             path.dentry.d_name.name.string_(), os.fsencode(os.path.basename(f.name))
         )