File: exceptions.py

package info (click to toggle)
python-haproxyadmin 0.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 1,500; makefile: 165; sh: 1
file content (106 lines) | stat: -rw-r--r-- 3,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
# vim:fenc=utf-8

"""
haproxyadmin.exceptions
~~~~~~~~~~~~~~~~~~~~~~~

This module contains the set of haproxyadmin' exceptions with the following
hierarchy::

    HAProxyBaseError
    ├── CommandFailed
    ├── HAProxyDataError
    │   ├── IncosistentData
    │   └── MultipleCommandResults
    └── HAProxySocketError
        ├── SocketApplicationError
        ├── SocketConnectionError
        ├── SocketPermissionError
        ├── SocketTimeout
        └── SocketTransportError
"""


class HAProxyBaseError(Exception):
    """haproxyadmin base exception.

    :param message: error message.
    :type message: ``string``
    """
    message = ''

    def __init__(self, message=''):
        if message:
            self.message = message
        super(HAProxyBaseError, self).__init__(self.message)


class CommandFailed(HAProxyBaseError):
    """Raised when a command to HAProxy returned an error."""


class HAProxyDataError(HAProxyBaseError):
    """Base DataError class.

    :param results: A structure which contains data returned be each socket.
    :type results: ``list`` of ``list``
    """
    def __init__(self, results):
        self.results = results
        super(HAProxyDataError, self).__init__()


class MultipleCommandResults(HAProxyDataError):
    """Command returned different results per HAProxy process."""
    message = 'Received different result per HAProxy process'


class IncosistentData(HAProxyDataError):
    """Data across all processes is not the same."""
    message = 'Received different data per HAProxy process'


class HAProxySocketError(HAProxyBaseError):
    """Base SocketError class.

    :param socket_file: socket file.
    :type socket_file: ``string``
    """
    def __init__(self, socket_file):
        self.socket_file = socket_file
        self.message = self.message + ' ' + self.socket_file
        super(HAProxySocketError, self).__init__(self.message)


class SocketTimeout(HAProxySocketError):
    """Raised when we timeout on the socket."""
    message = 'Socket timed out'


class SocketPermissionError(HAProxySocketError):
    """Raised when permissions are not granted to access socket file."""
    message = 'No permissions are granted to access socket file'


class SocketConnectionError(HAProxySocketError):
    """Raised when socket file is not bound to a process."""
    message = 'No process is bound to socket file'


class SocketApplicationError(HAProxySocketError):
    """Raised when we connect to a socket and HAProxy is not bound to it."""
    message = 'HAProxy is not bound to socket file'


class SocketTransportError(HAProxySocketError):
    """Raised when endpoint of socket hasn't closed an old connection.

    .. note::
       It only occurs in cases where HAProxy is ~90% CPU utilization for
       processing traffic and we reconnect to the socket too
       fast and as a result HAProxy doesn't have enough time to close the
       previous connection.

    """
    message = 'Transport endpoint is already connected'