# Path: lighthouse/haproxy/stanzas/backend.py
# class BackendStanza(Stanza):
#     """
#     Stanza subclass representing a "backend" stanza.
# 
#     A backend stanza defines the nodes (or "servers") belonging to a given
#     cluster as well as how routing/load balancing between those nodes happens.
# 
#     A given cluster can define custom directives via a list of lines in their
#     haproxy config with the key "backend".
#     """
# 
#     def __init__(self, cluster):
#         super(BackendStanza, self).__init__("backend")
#         self.header = "backend %s" % cluster.name
# 
#         if not cluster.nodes:
#             logger.warning(
#                 "Cluster %s has no nodes, backend stanza may be blank.",
#                 cluster.name
#             )
# 
#         backend_lines = cluster.haproxy.get("backend", [])
#         self.add_lines(backend_lines)
#         for node in cluster.nodes:
#             http_mode = bool("mode http" in backend_lines)
#             self.add_line(
#                 "server %(name)s %(host)s:%(port)s %(cookie)s %(options)s" % {
#                     "name": node.name,
#                     "host": node.ip,
#                     "port": node.port,
#                     "cookie": "cookie " + node.name if http_mode else "",
#                     "options": cluster.haproxy.get("server_options", "")
#                 }
#             )


    import unittest2 as unittest
    import unittest
from mock import Mock
from lighthouse.haproxy.stanzas.backend import BackendStanza
try:
except ImportError:




class BackendStanzaTests(unittest.TestCase):

    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"
            ]
        }


# Path: lighthouse/haproxy/stanzas/backend.py
# class BackendStanza(Stanza):
#     """
#     Stanza subclass representing a "backend" stanza.
# 
#     A backend stanza defines the nodes (or "servers") belonging to a given
#     cluster as well as how routing/load balancing between those nodes happens.
# 
#     A given cluster can define custom directives via a list of lines in their
#     haproxy config with the key "backend".
#     """
# 
#     def __init__(self, cluster):
#         super(BackendStanza, self).__init__("backend")
#         self.header = "backend %s" % cluster.name
# 
#         if not cluster.nodes:
#             logger.warning(
#                 "Cluster %s has no nodes, backend stanza may be blank.",
#                 cluster.name
#             )
# 
#         backend_lines = cluster.haproxy.get("backend", [])
#         self.add_lines(backend_lines)
#         for node in cluster.nodes:
#             http_mode = bool("mode http" in backend_lines)
#             self.add_line(
#                 "server %(name)s %(host)s:%(port)s %(cookie)s %(options)s" % {
#                     "name": node.name,
#                     "host": node.ip,
#                     "port": node.port,
#                     "cookie": "cookie " + node.name if http_mode else "",
#                     "options": cluster.haproxy.get("server_options", "")
#                 }
#             )


# Path: tests/haproxy/stanzas/backend_tests.py
    import unittest2 as unittest
    import unittest
from mock import Mock
from lighthouse.haproxy.stanzas.backend import BackendStanza

try:
except ImportError:




class BackendStanzaTests(unittest.TestCase):

    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)