Python stat.S_IFSOCK Examples

The following are 30 code examples of stat.S_IFSOCK(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module stat , or try the search function .
Example #1
Source File: test_unix_events.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def setUp(self):
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol)
        self.pipe = mock.Mock(spec_set=io.RawIOBase)
        self.pipe.fileno.return_value = 5

        blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
        blocking_patcher.start()
        self.addCleanup(blocking_patcher.stop)

        fstat_patcher = mock.patch('os.fstat')
        m_fstat = fstat_patcher.start()
        st = mock.Mock()
        st.st_mode = stat.S_IFSOCK
        m_fstat.return_value = st
        self.addCleanup(fstat_patcher.stop) 
Example #2
Source File: t3_fsck.py    From s3ql with GNU General Public License v3.0 6 votes vote down vote up
def test_unix_blocks(self):

        inode = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) "
                              "VALUES (?,?,?,?,?,?,?)",
                              (stat.S_IFSOCK | stat.S_IRUSR | stat.S_IWUSR,
                               os.getuid(), os.getgid(), time_ns(), time_ns(), time_ns(), 1))
        self._link(b'test-entry', inode)

        self.fsck.found_errors = False
        self.fsck.check_unix()
        self.assertFalse(self.fsck.found_errors)

        obj_id = self.db.rowid('INSERT INTO objects (refcount, size) VALUES(1, 32)')
        block_id = self.db.rowid('INSERT INTO blocks (refcount, obj_id, size) VALUES(?,?,?)',
                                 (1, obj_id, 0))

        self.db.execute('INSERT INTO inode_blocks (inode, blockno, block_id) VALUES(?,?,?)',
                        (inode, 1, block_id))

        self.fsck.check_unix()
        self.assertTrue(self.fsck.found_errors) 
Example #3
Source File: test_unix_events.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol)
        self.pipe = mock.Mock(spec_set=io.RawIOBase)
        self.pipe.fileno.return_value = 5

        blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
        blocking_patcher.start()
        self.addCleanup(blocking_patcher.stop)

        fstat_patcher = mock.patch('os.fstat')
        m_fstat = fstat_patcher.start()
        st = mock.Mock()
        st.st_mode = stat.S_IFSOCK
        m_fstat.return_value = st
        self.addCleanup(fstat_patcher.stop) 
Example #4
Source File: test_unix_events.py    From annotated-py-projects with MIT License 6 votes vote down vote up
def setUp(self):
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol)
        self.pipe = mock.Mock(spec_set=io.RawIOBase)
        self.pipe.fileno.return_value = 5

        blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
        blocking_patcher.start()
        self.addCleanup(blocking_patcher.stop)

        fstat_patcher = mock.patch('os.fstat')
        m_fstat = fstat_patcher.start()
        st = mock.Mock()
        st.st_mode = stat.S_IFSOCK
        m_fstat.return_value = st
        self.addCleanup(fstat_patcher.stop) 
Example #5
Source File: test_unix_events.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol)
        self.pipe = mock.Mock(spec_set=io.RawIOBase)
        self.pipe.fileno.return_value = 5

        blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
        blocking_patcher.start()
        self.addCleanup(blocking_patcher.stop)

        fstat_patcher = mock.patch('os.fstat')
        m_fstat = fstat_patcher.start()
        st = mock.Mock()
        st.st_mode = stat.S_IFSOCK
        m_fstat.return_value = st
        self.addCleanup(fstat_patcher.stop) 
Example #6
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_perform_with_no_containers(check_docker, fs):
    fs.create_file(check_docker.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--cpu', '0:0']
    with patch('check_docker.check_docker.get_url', return_value=([], 200)):
        with patch('check_docker.check_docker.unknown') as patched:
            check_docker.perform_checks(args)
            assert patched.call_count == 1 
Example #7
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_http(check_docker, fs):
    fs.create_file('/tmp/http', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--status', 'running', '--connection', 'http://127.0.0.1')
    result = check_docker.process_args(args=args)
    assert not check_docker.socketfile_permissions_failure(parsed_args=result) 
Example #8
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_unreadable(check_docker, fs):
    fs.create_file('/tmp/unreadable', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--status', 'running', '--connection', '/tmp/unreadable')
    result = check_docker.process_args(args=args)
    assert check_docker.socketfile_permissions_failure(parsed_args=result) 
Example #9
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_perform(check_docker, fs, args, called):
    fs.create_file(check_docker.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    with patch('check_docker.check_docker.get_containers', return_value=['thing1']):
        with patch('check_docker.check_docker.' + called) as patched:
            check_docker.perform_checks(args)
            assert patched.call_count == 1 
Example #10
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_service_called(check_swarm, fs):
    service_info = {'Spec': {'Mode': {'Replicated': {'Replicas': 1}}}}

    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services', return_value=[service_info]):
        with patch('check_docker.check_swarm.check_service') as patched:
            check_swarm.perform_checks(args)
            assert patched.call_count == 1 
Example #11
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_unwriteable(check_docker, fs):
    fs.create_file('/tmp/unwritable', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--status', 'running', '--connection', '/tmp/unwritable')
    result = check_docker.process_args(args=args)
    assert check_docker.socketfile_permissions_failure(parsed_args=result) 
Example #12
Source File: test_check_docker.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_false(check_docker, fs):
    fs.create_file('/tmp/socket', contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ('--status', 'running', '--connection', '/tmp/socket')
    result = check_docker.process_args(args=args)
    assert not check_docker.socketfile_permissions_failure(parsed_args=result) 
Example #13
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_not_swarm_service(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing4']
    with patch('check_docker.check_swarm.get_url', return_value=('', 406)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC 
Example #14
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_missing_service(check_swarm, fs):
    service_info = {'Spec': {'Name': 'FOO', 'Mode': {'Global': {}}}}
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing3']
    with patch('check_docker.check_swarm.get_url', return_value=([service_info], 200)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC 
Example #15
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_no_services(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing2']
    with patch('check_docker.check_swarm.get_url', return_value=([], 200)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC 
Example #16
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_service_results_FAIL_unknown(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services', return_value=['FOO', 'BAR']):
        with patch('check_docker.check_swarm.get_service_info', return_value=('', 500)):
            check_swarm.perform_checks(args)
            assert check_swarm.rc == cs.UNKNOWN_RC 
Example #17
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_service_results_FAIL_missing(check_swarm, fs):
    service_info = {'Spec': {'Name': 'FOO', 'Mode': {'Global': {}}}}
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing1']
    with patch('check_docker.check_swarm.get_url', return_value=([service_info], 200)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC 
Example #18
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_process_global_service(check_swarm, fs, node_list, service_list, ignore_paused, expected_rc):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    with patch('check_docker.check_swarm.get_nodes', return_value=(node_list, 999)) as patched_get_nodes, \
            patch('check_docker.check_swarm.get_service_tasks', return_value=service_list) as patched_get_service_tasks:
        check_swarm.process_global_service('FOO', ignore_paused)
        assert patched_get_nodes.call_count == 1
        assert patched_get_service_tasks.call_count == 1
        assert check_swarm.rc == expected_rc 
Example #19
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_services_global_ignore_paused(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    service_info = {'Spec': {'Mode': {'Global': {}}}}

    with patch('check_docker.check_swarm.get_service_info', return_value=(service_info, 999)), \
         patch('check_docker.check_swarm.process_global_service') as patched:
        check_swarm.check_service('FOO', True)
        assert patched.call_count == 1
        assert patched.call_args == call(name='FOO', ignore_paused=True) 
Example #20
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_services_routing_global(check_swarm, service_info, expected_func, expected_args, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    with patch('check_docker.check_swarm.get_service_info', return_value=(service_info, 999)), \
         patch('check_docker.check_swarm.{}'.format(expected_func)) as patched:
        check_swarm.check_service('FOO')
        assert patched.call_count == 1
        assert patched.call_args == call(**expected_args) 
Example #21
Source File: devdb.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def get_sock(self, major, minor):
        return self.get(S_IFSOCK, self._rdev(major, minor)) 
Example #22
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_swarm_results_CRITICAL(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--swarm']
    with patch('check_docker.check_swarm.get_swarm_status', return_value=406):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC 
Example #23
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_check_swarm_called(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--swarm']
    with patch('check_docker.check_swarm.check_swarm') as patched:
        check_swarm.perform_checks(args)
        assert patched.call_count == 1 
Example #24
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_http(check_swarm, fs):
    fs.create_file('/tmp/http', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--swarm', '--connection', 'http://127.0.0.1')
    result = check_swarm.process_args(args=args)
    assert not check_swarm.socketfile_permissions_failure(parsed_args=result) 
Example #25
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_unreadable(check_swarm, fs):
    fs.create_file('/tmp/unreadable', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--swarm', '--connection', '/tmp/unreadable')
    result = check_swarm.process_args(args=args)
    assert check_swarm.socketfile_permissions_failure(parsed_args=result) 
Example #26
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_unwriteable(check_swarm, fs):
    fs.create_file('/tmp/unwritable', contents='', st_mode=(stat.S_IFSOCK | 0o000))
    args = ('--swarm', '--connection', '/tmp/unwritable')
    result = check_swarm.process_args(args=args)
    assert check_swarm.socketfile_permissions_failure(parsed_args=result) 
Example #27
Source File: test_check_swarm.py    From check_docker with GNU General Public License v3.0 5 votes vote down vote up
def test_socketfile_failure_false(check_swarm, fs):
    fs.create_file('/tmp/socket', contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ('--swarm', '--connection', '/tmp/socket')
    result = check_swarm.process_args(args=args)
    assert not check_swarm.socketfile_permissions_failure(parsed_args=result) 
Example #28
Source File: mysql_monitor.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def is_sockfile(self, path):
        """Returns whether or not the given path is a socket file."""
        try:
            s = os.stat(path)
        except OSError as error:
            (no, e) = error.args
            if no == errno.ENOENT:
                return False
            self._logger.error("warning: couldn't stat(%r): %s" % (path, e))
            return None
        return s.st_mode & stat.S_IFSOCK == stat.S_IFSOCK 
Example #29
Source File: sftp_attr.py    From imoocc with GNU General Public License v2.0 4 votes vote down vote up
def __str__(self):
        """create a unix-style long description of the file (like ls -l)"""
        if self.st_mode is not None:
            kind = stat.S_IFMT(self.st_mode)
            if kind == stat.S_IFIFO:
                ks = 'p'
            elif kind == stat.S_IFCHR:
                ks = 'c'
            elif kind == stat.S_IFDIR:
                ks = 'd'
            elif kind == stat.S_IFBLK:
                ks = 'b'
            elif kind == stat.S_IFREG:
                ks = '-'
            elif kind == stat.S_IFLNK:
                ks = 'l'
            elif kind == stat.S_IFSOCK:
                ks = 's'
            else:
                ks = '?'
            ks += self._rwx((self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID)
            ks += self._rwx((self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID)
            ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
        else:
            ks = '?---------'
        # compute display date
        if (self.st_mtime is None) or (self.st_mtime == xffffffff):
            # shouldn't really happen
            datestr = '(unknown date)'
        else:
            if abs(time.time() - self.st_mtime) > 15552000:
                # (15552000 = 6 months)
                datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime))
            else:
                datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime))
        filename = getattr(self, 'filename', '?')

        # not all servers support uid/gid
        uid = self.st_uid
        gid = self.st_gid
        size = self.st_size
        if uid is None:
            uid = 0
        if gid is None:
            gid = 0
        if size is None:
            size = 0

        return '%s   1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, size, datestr, filename) 
Example #30
Source File: sftp_attr.py    From imoocc with GNU General Public License v2.0 4 votes vote down vote up
def __str__(self):
        "create a unix-style long description of the file (like ls -l)"
        if self.st_mode is not None:
            kind = stat.S_IFMT(self.st_mode)
            if kind == stat.S_IFIFO:
                ks = 'p'
            elif kind == stat.S_IFCHR:
                ks = 'c'
            elif kind == stat.S_IFDIR:
                ks = 'd'
            elif kind == stat.S_IFBLK:
                ks = 'b'
            elif kind == stat.S_IFREG:
                ks = '-'
            elif kind == stat.S_IFLNK:
                ks = 'l'
            elif kind == stat.S_IFSOCK:
                ks = 's'
            else:
                ks = '?'
            ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID)
            ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID)
            ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
        else:
            ks = '?---------'
        # compute display date
        if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL):
            # shouldn't really happen
            datestr = '(unknown date)'
        else:
            if abs(time.time() - self.st_mtime) > 15552000:
                # (15552000 = 6 months)
                datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime))
            else:
                datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime))
        filename = getattr(self, 'filename', '?')

        # not all servers support uid/gid
        uid = self.st_uid
        gid = self.st_gid
        if uid is None:
            uid = 0
        if gid is None:
            gid = 0

        return '%s   1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, self.st_size, datestr, filename)