Beispiel #1
0
 def test_unix(self):
     with unix_socket_path() as name:
         server, client = unix_socketpair(name)
         with nested(closing(server), closing(client)):
             cons = thisproc.connections(kind='unix')
             assert not (cons[0].laddr and cons[0].raddr)
             assert not (cons[1].laddr and cons[1].raddr)
             if NETBSD:
                 # On NetBSD creating a UNIX socket will cause
                 # a UNIX connection to  /var/run/log.
                 cons = [c for c in cons if c.raddr != '/var/run/log']
             self.assertEqual(len(cons), 2)
             if LINUX or FREEBSD:
                 # remote path is never set
                 self.assertEqual(cons[0].raddr, "")
                 self.assertEqual(cons[1].raddr, "")
                 # one local address should though
                 self.assertEqual(name, cons[0].laddr or cons[1].laddr)
             elif OPENBSD:
                 # No addresses whatsoever here.
                 for addr in (cons[0].laddr, cons[0].raddr, cons[1].laddr,
                              cons[1].raddr):
                     self.assertEqual(addr, "")
             else:
                 # On other systems either the laddr or raddr
                 # of both peers are set.
                 self.assertEqual(cons[0].laddr or cons[1].laddr, name)
                 self.assertEqual(cons[0].raddr or cons[1].raddr, name)
Beispiel #2
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     assert not thisproc.connections(kind='tcp4')
     server, client = tcp_socketpair(AF_INET, addr=addr)
     with nested(closing(server), closing(client)):
         cons = thisproc.connections(kind='tcp4')
         self.assertEqual(len(cons), 2)
         self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED)
         self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED)
Beispiel #3
0
 def test_tcp(self):
     addr = ("127.0.0.1", get_free_port())
     server, client = tcp_socketpair(AF_INET, addr=addr)
     with nested(closing(server), closing(client)):
         cons = psutil.Process().connections(kind='all')
         server_conn, client_conn = self.distinguish_tcp_socks(cons, addr)
         self.check_socket(server, conn=server_conn)
         self.check_socket(client, conn=client_conn)
         self.assertEqual(server_conn.status, psutil.CONN_ESTABLISHED)
         self.assertEqual(client_conn.status, psutil.CONN_ESTABLISHED)
Beispiel #4
0
    def test_unix(self):
        with unix_socket_path() as name:
            server, client = unix_socketpair(name)
            with nested(closing(server), closing(client)):
                cons = psutil.Process().connections(kind='unix')
                self.assertEqual(len(cons), 2)
                server_conn, client_conn = self.distinguish_unix_socks(cons)
                self.check_socket(server, conn=server_conn)

                self.check_socket(client, conn=client_conn)
                self.assertEqual(server_conn.laddr, name)
                # TODO: https://github.com/giampaolo/psutil/issues/1035
                self.assertIn(server_conn.raddr, ("", None))
                # TODO: https://github.com/giampaolo/psutil/issues/1035
                self.assertIn(client_conn.laddr, ("", None))