Exemplo n.º 1
0
    def test_custom_bind_address(self):
        cluster = Mock()
        cluster.name = "datastore"
        cluster.haproxy = {
            "port": 99
        }

        stanza = FrontendStanza(cluster, bind_address="127.0.0.1")

        self.assertEqual(
            stanza.lines,
            [
                "bind 127.0.0.1:99",
                "default_backend datastore"
            ]
        )
Exemplo n.º 2
0
    def test_default_bind_address_is_blank(self):
        cluster = Mock()
        cluster.name = "datastore"
        cluster.haproxy = {
            "port": 99
        }

        stanza = FrontendStanza(cluster)

        self.assertEqual(stanza.header, "frontend datastore")
        self.assertEqual(
            stanza.lines,
            [
                "bind :99",
                "default_backend datastore"
            ]
        )
Exemplo n.º 3
0
    def test_no_nodes(self):
        node = Mock(host="server1.int", ip="10.0.1.12", port=8000)
        node.name = "server1.int:8000"

        cluster = Mock()
        cluster.name = "accounts"
        cluster.haproxy = {
            "backend": [
                "timeout server 2000",
            ]
        }
        cluster.nodes = []

        stanza = BackendStanza(cluster)

        self.assertEqual(
            str(stanza),
            """backend accounts
\ttimeout server 2000"""
        )
Exemplo n.º 4
0
    def test_custom_frontend_lines(self):
        cluster = Mock()
        cluster.name = "datastore"
        cluster.haproxy = {
            "port": 99,
            "frontend": [
                "foo bar bazz",  # skipped as invalid
                "acl is_api path_beg /api",
            ]
        }

        stanza = FrontendStanza(cluster)

        self.assertEqual(
            stanza.lines,
            [
                "acl is_api path_beg /api",
                "bind :99",
                "default_backend datastore"
            ]
        )
Exemplo n.º 5
0
    def test_tcp_mode(self):
        tcp_node = Mock(host="server1.int", ip="10.0.1.12", port=8000)
        tcp_node.name = "server1.int:8000"

        cluster = Mock()
        cluster.name = "redis_cache"
        cluster.nodes = [tcp_node]
        cluster.haproxy = {
            "backend": [
                "mode tcp"
            ]
        }

        stanza = BackendStanza(cluster)

        self.assertEqual(
            str(stanza),
            """backend redis_cache
\tmode tcp
\tserver server1.int:8000 10.0.1.12:8000  """
        )
Exemplo n.º 6
0
    def test_includes_cookie_in_http_mode(self):
        http_node = Mock(host="server1.int", ip="10.0.1.12", port=8000)
        http_node.name = "server1.int:8000"

        cluster = Mock()
        cluster.name = "accounts"
        cluster.nodes = [http_node]
        cluster.haproxy = {
            "backend": [
                "mode http"
            ]
        }

        stanza = BackendStanza(cluster)

        self.assertEqual(
            str(stanza),
            """backend accounts
\tmode http
\tserver server1.int:8000 10.0.1.12:8000 cookie server1.int:8000 """
        )
Exemplo n.º 7
0
    def test_custom_backend_lines(self):
        node = Mock(host="server1.int", ip="10.0.1.12", port=8000)
        node.name = "server1.int:8000"

        cluster = Mock()
        cluster.name = "accounts"
        cluster.haproxy = {
            "backend": [
                "timeout server 2000",
                "fee foo fi",  # skipped as invalid
            ]
        }
        cluster.nodes = [node]

        stanza = BackendStanza(cluster)

        self.assertEqual(
            str(stanza),
            """backend accounts
\ttimeout server 2000
\tserver server1.int:8000 10.0.1.12:8000  """
        )