"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/tests/unit/common/jinja/lvs/test_jinja_cfg.py" (14 Apr 2021, 39386 Bytes) of package /linux/misc/openstack/octavia-8.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # Copyright 2018 OpenStack Foundation
    2 # All Rights Reserved.
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 
   16 from octavia_lib.common import constants as lib_consts
   17 
   18 from octavia.common import constants
   19 from octavia.common.jinja.lvs import jinja_cfg
   20 from octavia.tests.unit import base
   21 from octavia.tests.unit.common.sample_configs import sample_configs_combined
   22 
   23 from oslo_config import cfg
   24 from oslo_config import fixture as oslo_fixture
   25 
   26 BASE_PATH = '/var/lib/octavia'
   27 
   28 
   29 class TestLvsCfg(base.TestCase):
   30     def setUp(self):
   31         super().setUp()
   32         self.lvs_jinja_cfg = jinja_cfg.LvsJinjaTemplater()
   33         conf = oslo_fixture.Config(cfg.CONF)
   34         conf.config(group="haproxy_amphora", base_path=BASE_PATH)
   35 
   36     def test_udp_get_template(self):
   37         template = self.lvs_jinja_cfg._get_template()
   38         self.assertEqual('keepalivedlvs.cfg.j2', template.name)
   39 
   40     def test_render_template_udp_source_ip(self):
   41         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
   42                "# Configuration for Listener sample_listener_id_1\n\n"
   43                "net_namespace amphora-haproxy\n\n"
   44                "virtual_server 10.0.0.2 80 {\n"
   45                "    lb_algo rr\n"
   46                "    lb_kind NAT\n"
   47                "    protocol UDP\n"
   48                "    persistence_timeout 33\n"
   49                "    persistence_granularity 255.255.0.0\n"
   50                "    delay_loop 30\n"
   51                "    delay_before_retry 30\n"
   52                "    retry 3\n\n\n"
   53                "    # Configuration for Pool sample_pool_id_1\n"
   54                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
   55                "    # Configuration for Member sample_member_id_1\n"
   56                "    real_server 10.0.0.99 82 {\n"
   57                "        weight 13\n"
   58                "        uthreshold 98\n"
   59                "        MISC_CHECK {\n"
   60                "            misc_path \"/var/lib/octavia/lvs/check/"
   61                "udp_check.sh 10.0.0.99 82\"\n"
   62                "            misc_timeout 31\n"
   63                "        }\n"
   64                "    }\n\n"
   65                "    # Configuration for Member sample_member_id_2\n"
   66                "    real_server 10.0.0.98 82 {\n"
   67                "        weight 13\n"
   68                "        uthreshold 98\n"
   69                "        MISC_CHECK {\n"
   70                "            misc_path \"/var/lib/octavia/lvs/check/"
   71                "udp_check.sh 10.0.0.98 82\"\n"
   72                "            misc_timeout 31\n"
   73                "        }\n"
   74                "    }\n\n"
   75                "}\n\n")
   76         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
   77             sample_configs_combined.sample_listener_tuple(
   78                 proto=constants.PROTOCOL_UDP,
   79                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
   80                 persistence_timeout=33,
   81                 persistence_granularity='255.255.0.0',
   82                 monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
   83                 connection_limit=98))
   84         self.assertEqual(exp, rendered_obj)
   85 
   86     def test_render_template_udp_one_packet(self):
   87         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
   88                "# Configuration for Listener sample_listener_id_1\n\n"
   89                "net_namespace amphora-haproxy\n\n"
   90                "virtual_server 10.0.0.2 80 {\n"
   91                "    lb_algo rr\n"
   92                "    lb_kind NAT\n"
   93                "    protocol UDP\n"
   94                "    delay_loop 30\n"
   95                "    delay_before_retry 30\n"
   96                "    retry 3\n\n\n"
   97                "    # Configuration for Pool sample_pool_id_1\n"
   98                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
   99                "    # Configuration for Member sample_member_id_1\n"
  100                "    real_server 10.0.0.99 82 {\n"
  101                "        weight 13\n"
  102                "        uthreshold 98\n"
  103                "        MISC_CHECK {\n"
  104                "            misc_path \"/var/lib/octavia/lvs/check/"
  105                "udp_check.sh 10.0.0.99 82\"\n"
  106                "            misc_timeout 31\n"
  107                "        }\n"
  108                "    }\n\n"
  109                "    # Configuration for Member sample_member_id_2\n"
  110                "    real_server 10.0.0.98 82 {\n"
  111                "        weight 13\n"
  112                "        uthreshold 98\n"
  113                "        MISC_CHECK {\n"
  114                "            misc_path \"/var/lib/octavia/lvs/check/"
  115                "udp_check.sh 10.0.0.98 82\"\n"
  116                "            misc_timeout 31\n"
  117                "        }\n"
  118                "    }\n\n"
  119                "}\n\n")
  120 
  121         listener = sample_configs_combined.sample_listener_tuple(
  122             proto=constants.PROTOCOL_UDP,
  123             monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  124             connection_limit=98,
  125             persistence=False)
  126         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  127         self.assertEqual(exp, rendered_obj)
  128 
  129     def test_render_template_udp_with_health_monitor(self):
  130         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  131                "# Configuration for Listener sample_listener_id_1\n\n"
  132                "net_namespace amphora-haproxy\n\n"
  133                "virtual_server 10.0.0.2 80 {\n"
  134                "    lb_algo rr\n"
  135                "    lb_kind NAT\n"
  136                "    protocol UDP\n"
  137                "    delay_loop 30\n"
  138                "    delay_before_retry 30\n"
  139                "    retry 3\n\n\n"
  140                "    # Configuration for Pool sample_pool_id_1\n"
  141                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  142                "    # Configuration for Member sample_member_id_1\n"
  143                "    real_server 10.0.0.99 82 {\n"
  144                "        weight 13\n"
  145                "        uthreshold 98\n"
  146                "        MISC_CHECK {\n"
  147                "            misc_path \"/var/lib/octavia/lvs/check/"
  148                "udp_check.sh 10.0.0.99 82\"\n"
  149                "            misc_timeout 31\n"
  150                "        }\n"
  151                "    }\n\n"
  152                "    # Configuration for Member sample_member_id_2\n"
  153                "    real_server 10.0.0.98 82 {\n"
  154                "        weight 13\n"
  155                "        uthreshold 98\n"
  156                "        MISC_CHECK {\n"
  157                "            misc_path \"/var/lib/octavia/lvs/check/"
  158                "udp_check.sh 10.0.0.98 82\"\n"
  159                "            misc_timeout 31\n"
  160                "        }\n"
  161                "    }\n\n"
  162                "}\n\n")
  163 
  164         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  165             sample_configs_combined.sample_listener_tuple(
  166                 proto=constants.PROTOCOL_UDP,
  167                 monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  168                 persistence=False,
  169                 connection_limit=98))
  170         self.assertEqual(exp, rendered_obj)
  171 
  172     def test_render_template_udp_with_health_monitor_ip_port(self):
  173         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  174                "# Configuration for Listener sample_listener_id_1\n\n"
  175                "net_namespace amphora-haproxy\n\n"
  176                "virtual_server 10.0.0.2 80 {\n"
  177                "    lb_algo rr\n"
  178                "    lb_kind NAT\n"
  179                "    protocol UDP\n"
  180                "    delay_loop 30\n"
  181                "    delay_before_retry 30\n"
  182                "    retry 3\n\n\n"
  183                "    # Configuration for Pool sample_pool_id_1\n"
  184                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  185                "    # Configuration for Member sample_member_id_1\n"
  186                "    real_server 10.0.0.99 82 {\n"
  187                "        weight 13\n"
  188                "        uthreshold 98\n"
  189                "        MISC_CHECK {\n"
  190                "            misc_path \"/var/lib/octavia/lvs/check/"
  191                "udp_check.sh 192.168.1.1 9000\"\n"
  192                "            misc_timeout 31\n"
  193                "        }\n"
  194                "    }\n\n"
  195                "    # Configuration for Member sample_member_id_2\n"
  196                "    real_server 10.0.0.98 82 {\n"
  197                "        weight 13\n"
  198                "        uthreshold 98\n"
  199                "        MISC_CHECK {\n"
  200                "            misc_path \"/var/lib/octavia/lvs/check/"
  201                "udp_check.sh 192.168.1.1 9000\"\n"
  202                "            misc_timeout 31\n"
  203                "        }\n"
  204                "    }\n\n"
  205                "}\n\n")
  206 
  207         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  208             sample_configs_combined.sample_listener_tuple(
  209                 proto=constants.PROTOCOL_UDP,
  210                 monitor_ip_port=True,
  211                 monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  212                 persistence=False,
  213                 connection_limit=98))
  214         self.assertEqual(exp, rendered_obj)
  215 
  216     def test_render_template_udp_no_other_resources(self):
  217         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  218                "# Configuration for Listener sample_listener_id_1\n\n"
  219                "net_namespace amphora-haproxy\n\n\n")
  220 
  221         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  222             sample_configs_combined.sample_listener_tuple(
  223                 proto=constants.PROTOCOL_UDP, monitor=False,
  224                 persistence=False, alloc_default_pool=False))
  225         self.assertEqual(exp, rendered_obj)
  226 
  227     def test_render_template_udp_with_pool_no_member(self):
  228         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  229                "# Configuration for Listener sample_listener_id_1\n\n"
  230                "net_namespace amphora-haproxy\n\n"
  231                "virtual_server 10.0.0.2 80 {\n"
  232                "    lb_algo rr\n"
  233                "    lb_kind NAT\n"
  234                "    protocol UDP\n\n\n"
  235                "    # Configuration for Pool sample_pool_id_0\n"
  236                "}\n\n")
  237 
  238         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  239             sample_configs_combined.sample_listener_tuple(
  240                 proto=constants.PROTOCOL_UDP, monitor=False,
  241                 persistence=False, alloc_default_pool=True,
  242                 sample_default_pool=0))
  243         self.assertEqual(exp, rendered_obj)
  244 
  245     def test_render_template_udp_with_disabled_pool(self):
  246         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  247                "# Configuration for Listener sample_listener_id_1\n\n"
  248                "net_namespace amphora-haproxy\n\n"
  249                "virtual_server 10.0.0.2 80 {\n"
  250                "    lb_algo rr\n"
  251                "    lb_kind NAT\n"
  252                "    protocol UDP\n\n\n"
  253                "    # Pool sample_pool_id_1 is disabled\n"
  254                "    # Configuration for Member sample_member_id_1\n"
  255                "    real_server 10.0.0.99 82 {\n"
  256                "        weight 13\n\n"
  257                "    }\n\n"
  258                "    # Configuration for Member sample_member_id_2\n"
  259                "    real_server 10.0.0.98 82 {\n"
  260                "        weight 13\n\n"
  261                "    }\n\n"
  262                "}\n\n")
  263 
  264         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  265             sample_configs_combined.sample_listener_tuple(
  266                 proto=constants.PROTOCOL_UDP, monitor=False,
  267                 persistence=False, alloc_default_pool=True,
  268                 pool_enabled=False))
  269         self.assertEqual(exp, rendered_obj)
  270 
  271     def test_udp_transform_session_persistence(self):
  272         persistence_src_ip = (
  273             sample_configs_combined.sample_session_persistence_tuple(
  274                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  275                 persistence_cookie=None,
  276                 persistence_timeout=33,
  277                 persistence_granularity='255.0.0.0'
  278             ))
  279         exp = sample_configs_combined.UDP_SOURCE_IP_BODY
  280         ret = self.lvs_jinja_cfg._transform_session_persistence(
  281             persistence_src_ip)
  282         self.assertEqual(exp, ret)
  283 
  284     def test_udp_transform_health_monitor(self):
  285         in_hm = sample_configs_combined.sample_health_monitor_tuple(
  286             proto=constants.HEALTH_MONITOR_UDP_CONNECT
  287         )
  288         ret = self.lvs_jinja_cfg._transform_health_monitor(in_hm)
  289         self.assertEqual(sample_configs_combined.RET_UDP_HEALTH_MONITOR, ret)
  290 
  291     def test_udp_transform_member(self):
  292         in_member = sample_configs_combined.sample_member_tuple(
  293             'member_id_1', '192.0.2.10')
  294         ret = self.lvs_jinja_cfg._transform_member(in_member)
  295         self.assertEqual(sample_configs_combined.RET_UDP_MEMBER, ret)
  296 
  297         in_member = sample_configs_combined.sample_member_tuple(
  298             'member_id_1',
  299             '192.0.2.10',
  300             monitor_ip_port=True)
  301         ret = self.lvs_jinja_cfg._transform_member(in_member)
  302         self.assertEqual(
  303             sample_configs_combined.RET_UDP_MEMBER_MONITOR_IP_PORT, ret)
  304 
  305     def test_udp_transform_pool(self):
  306         in_pool = sample_configs_combined.sample_pool_tuple(
  307             proto=constants.PROTOCOL_UDP,
  308             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  309             persistence_timeout=33, persistence_granularity='255.0.0.0',
  310         )
  311         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  312         self.assertEqual(sample_configs_combined.RET_UDP_POOL, ret)
  313 
  314         in_pool = sample_configs_combined.sample_pool_tuple(
  315             proto=constants.PROTOCOL_UDP,
  316             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  317             persistence_timeout=33, persistence_granularity='255.0.0.0',
  318             lb_algorithm=None,
  319         )
  320         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  321         self.assertEqual(sample_configs_combined.RET_UDP_POOL, ret)
  322 
  323         in_pool = sample_configs_combined.sample_pool_tuple(
  324             proto=constants.PROTOCOL_UDP,
  325             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  326             persistence_timeout=33, persistence_granularity='255.0.0.0',
  327             monitor=False)
  328         sample_configs_combined.RET_UDP_POOL['health_monitor'] = ''
  329         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  330         self.assertEqual(sample_configs_combined.RET_UDP_POOL, ret)
  331 
  332     def test_udp_transform_listener(self):
  333         in_listener = sample_configs_combined.sample_listener_tuple(
  334             proto=constants.PROTOCOL_UDP,
  335             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  336             persistence_timeout=33,
  337             persistence_granularity='255.0.0.0',
  338             monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  339             connection_limit=98
  340         )
  341         ret = self.lvs_jinja_cfg._transform_listener(in_listener)
  342         self.assertEqual(sample_configs_combined.RET_UDP_LISTENER, ret)
  343 
  344         in_listener = sample_configs_combined.sample_listener_tuple(
  345             proto=constants.PROTOCOL_UDP,
  346             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  347             persistence_timeout=33,
  348             persistence_granularity='255.0.0.0',
  349             monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  350             connection_limit=-1)
  351 
  352         ret = self.lvs_jinja_cfg._transform_listener(in_listener)
  353         sample_configs_combined.RET_UDP_LISTENER.pop('connection_limit')
  354         self.assertEqual(sample_configs_combined.RET_UDP_LISTENER, ret)
  355 
  356     def test_render_template_udp_listener_with_http_health_monitor(self):
  357         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  358                "# Configuration for Listener sample_listener_id_1\n\n"
  359                "net_namespace amphora-haproxy\n\n"
  360                "virtual_server 10.0.0.2 80 {\n"
  361                "    lb_algo rr\n"
  362                "    lb_kind NAT\n"
  363                "    protocol UDP\n"
  364                "    delay_loop 30\n"
  365                "    delay_before_retry 30\n"
  366                "    retry 3\n\n\n"
  367                "    # Configuration for Pool sample_pool_id_1\n"
  368                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  369                "    # Configuration for Member sample_member_id_1\n"
  370                "    real_server 10.0.0.99 82 {\n"
  371                "        weight 13\n"
  372                "        uthreshold 98\n"
  373                "        HTTP_GET {\n"
  374                "            url {\n"
  375                "              path /index.html\n"
  376                "              status_code 200\n"
  377                "            }\n"
  378                "            url {\n"
  379                "              path /index.html\n"
  380                "              status_code 201\n"
  381                "            }\n"
  382                "            connect_ip 10.0.0.99\n"
  383                "            connect_port 82\n"
  384                "            connect_timeout 31\n"
  385                "        }\n"
  386                "    }\n\n"
  387                "    # Configuration for Member sample_member_id_2\n"
  388                "    real_server 10.0.0.98 82 {\n"
  389                "        weight 13\n"
  390                "        uthreshold 98\n"
  391                "        HTTP_GET {\n"
  392                "            url {\n"
  393                "              path /index.html\n"
  394                "              status_code 200\n"
  395                "            }\n"
  396                "            url {\n"
  397                "              path /index.html\n"
  398                "              status_code 201\n"
  399                "            }\n"
  400                "            connect_ip 10.0.0.98\n"
  401                "            connect_port 82\n"
  402                "            connect_timeout 31\n"
  403                "        }\n"
  404                "    }\n\n"
  405                "}\n\n")
  406 
  407         listener = sample_configs_combined.sample_listener_tuple(
  408             proto=constants.PROTOCOL_UDP,
  409             monitor_proto=constants.HEALTH_MONITOR_HTTP,
  410             connection_limit=98,
  411             persistence=False,
  412             monitor_expected_codes='200-201')
  413 
  414         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  415         self.assertEqual(exp, rendered_obj)
  416 
  417     def test_render_template_udp_listener_with_tcp_health_monitor(self):
  418         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  419                "# Configuration for Listener sample_listener_id_1\n\n"
  420                "net_namespace amphora-haproxy\n\n"
  421                "virtual_server 10.0.0.2 80 {\n"
  422                "    lb_algo rr\n"
  423                "    lb_kind NAT\n"
  424                "    protocol UDP\n"
  425                "    delay_loop 30\n"
  426                "    delay_before_retry 30\n"
  427                "    retry 3\n\n\n"
  428                "    # Configuration for Pool sample_pool_id_1\n"
  429                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  430                "    # Configuration for Member sample_member_id_1\n"
  431                "    real_server 10.0.0.99 82 {\n"
  432                "        weight 13\n"
  433                "        uthreshold 98\n"
  434                "        TCP_CHECK {\n"
  435                "            connect_ip 10.0.0.99\n"
  436                "            connect_port 82\n"
  437                "            connect_timeout 31\n"
  438                "        }\n"
  439                "    }\n\n"
  440                "    # Configuration for Member sample_member_id_2\n"
  441                "    real_server 10.0.0.98 82 {\n"
  442                "        weight 13\n"
  443                "        uthreshold 98\n"
  444                "        TCP_CHECK {\n"
  445                "            connect_ip 10.0.0.98\n"
  446                "            connect_port 82\n"
  447                "            connect_timeout 31\n"
  448                "        }\n"
  449                "    }\n\n"
  450                "}\n\n")
  451         listener = sample_configs_combined.sample_listener_tuple(
  452             proto=constants.PROTOCOL_UDP,
  453             monitor_proto=constants.HEALTH_MONITOR_TCP,
  454             connection_limit=98,
  455             persistence=False)
  456 
  457         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  458         self.assertEqual(exp, rendered_obj)
  459 
  460     def test_render_template_disabled_udp_listener(self):
  461         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  462                "# Listener sample_listener_id_1 is disabled\n\n"
  463                "net_namespace amphora-haproxy\n\n")
  464         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  465             sample_configs_combined.sample_listener_tuple(
  466                 enabled=False,
  467                 proto=constants.PROTOCOL_UDP,
  468                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  469                 persistence_timeout=33,
  470                 persistence_granularity='255.255.0.0',
  471                 monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT,
  472                 connection_limit=98))
  473         self.assertEqual(exp, rendered_obj)
  474 
  475     def test_render_template_sctp_source_ip(self):
  476         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  477                "# Configuration for Listener sample_listener_id_1\n\n"
  478                "net_namespace amphora-haproxy\n\n"
  479                "virtual_server 10.0.0.2 80 {\n"
  480                "    lb_algo rr\n"
  481                "    lb_kind NAT\n"
  482                "    protocol SCTP\n"
  483                "    persistence_timeout 33\n"
  484                "    persistence_granularity 255.255.0.0\n"
  485                "    delay_loop 30\n"
  486                "    delay_before_retry 30\n"
  487                "    retry 3\n\n\n"
  488                "    # Configuration for Pool sample_pool_id_1\n"
  489                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  490                "    # Configuration for Member sample_member_id_1\n"
  491                "    real_server 10.0.0.99 82 {\n"
  492                "        weight 13\n"
  493                "        uthreshold 98\n"
  494                "        MISC_CHECK {\n"
  495                "            misc_path \"amphora-health-checker sctp -t 31 "
  496                "10.0.0.99 82\"\n"
  497                "            misc_timeout 32\n"
  498                "        }\n"
  499                "    }\n\n"
  500                "    # Configuration for Member sample_member_id_2\n"
  501                "    real_server 10.0.0.98 82 {\n"
  502                "        weight 13\n"
  503                "        uthreshold 98\n"
  504                "        MISC_CHECK {\n"
  505                "            misc_path \"amphora-health-checker sctp -t 31 "
  506                "10.0.0.98 82\"\n"
  507                "            misc_timeout 32\n"
  508                "        }\n"
  509                "    }\n\n"
  510                "}\n\n")
  511         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  512             sample_configs_combined.sample_listener_tuple(
  513                 proto=lib_consts.PROTOCOL_SCTP,
  514                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  515                 persistence_timeout=33,
  516                 persistence_granularity='255.255.0.0',
  517                 monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  518                 connection_limit=98))
  519         self.assertEqual(exp, rendered_obj)
  520 
  521     def test_render_template_sctp_one_packet(self):
  522         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  523                "# Configuration for Listener sample_listener_id_1\n\n"
  524                "net_namespace amphora-haproxy\n\n"
  525                "virtual_server 10.0.0.2 80 {\n"
  526                "    lb_algo rr\n"
  527                "    lb_kind NAT\n"
  528                "    protocol SCTP\n"
  529                "    delay_loop 30\n"
  530                "    delay_before_retry 30\n"
  531                "    retry 3\n\n\n"
  532                "    # Configuration for Pool sample_pool_id_1\n"
  533                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  534                "    # Configuration for Member sample_member_id_1\n"
  535                "    real_server 10.0.0.99 82 {\n"
  536                "        weight 13\n"
  537                "        uthreshold 98\n"
  538                "        MISC_CHECK {\n"
  539                "            misc_path \"amphora-health-checker sctp -t 31 "
  540                "10.0.0.99 82\"\n"
  541                "            misc_timeout 32\n"
  542                "        }\n"
  543                "    }\n\n"
  544                "    # Configuration for Member sample_member_id_2\n"
  545                "    real_server 10.0.0.98 82 {\n"
  546                "        weight 13\n"
  547                "        uthreshold 98\n"
  548                "        MISC_CHECK {\n"
  549                "            misc_path \"amphora-health-checker sctp -t 31 "
  550                "10.0.0.98 82\"\n"
  551                "            misc_timeout 32\n"
  552                "        }\n"
  553                "    }\n\n"
  554                "}\n\n")
  555 
  556         listener = sample_configs_combined.sample_listener_tuple(
  557             proto=lib_consts.PROTOCOL_SCTP,
  558             monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  559             connection_limit=98,
  560             persistence=False)
  561         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  562         self.assertEqual(exp, rendered_obj)
  563 
  564     def test_render_template_sctp_with_health_monitor(self):
  565         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  566                "# Configuration for Listener sample_listener_id_1\n\n"
  567                "net_namespace amphora-haproxy\n\n"
  568                "virtual_server 10.0.0.2 80 {\n"
  569                "    lb_algo rr\n"
  570                "    lb_kind NAT\n"
  571                "    protocol SCTP\n"
  572                "    delay_loop 30\n"
  573                "    delay_before_retry 30\n"
  574                "    retry 3\n\n\n"
  575                "    # Configuration for Pool sample_pool_id_1\n"
  576                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  577                "    # Configuration for Member sample_member_id_1\n"
  578                "    real_server 10.0.0.99 82 {\n"
  579                "        weight 13\n"
  580                "        uthreshold 98\n"
  581                "        MISC_CHECK {\n"
  582                "            misc_path \"amphora-health-checker sctp -t 31 "
  583                "10.0.0.99 82\"\n"
  584                "            misc_timeout 32\n"
  585                "        }\n"
  586                "    }\n\n"
  587                "    # Configuration for Member sample_member_id_2\n"
  588                "    real_server 10.0.0.98 82 {\n"
  589                "        weight 13\n"
  590                "        uthreshold 98\n"
  591                "        MISC_CHECK {\n"
  592                "            misc_path \"amphora-health-checker sctp -t 31 "
  593                "10.0.0.98 82\"\n"
  594                "            misc_timeout 32\n"
  595                "        }\n"
  596                "    }\n\n"
  597                "}\n\n")
  598 
  599         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  600             sample_configs_combined.sample_listener_tuple(
  601                 proto=lib_consts.PROTOCOL_SCTP,
  602                 monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  603                 persistence=False,
  604                 connection_limit=98))
  605         self.assertEqual(exp, rendered_obj)
  606 
  607     def test_render_template_sctp_with_health_monitor_ip_port(self):
  608         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  609                "# Configuration for Listener sample_listener_id_1\n\n"
  610                "net_namespace amphora-haproxy\n\n"
  611                "virtual_server 10.0.0.2 80 {\n"
  612                "    lb_algo rr\n"
  613                "    lb_kind NAT\n"
  614                "    protocol SCTP\n"
  615                "    delay_loop 30\n"
  616                "    delay_before_retry 30\n"
  617                "    retry 3\n\n\n"
  618                "    # Configuration for Pool sample_pool_id_1\n"
  619                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  620                "    # Configuration for Member sample_member_id_1\n"
  621                "    real_server 10.0.0.99 82 {\n"
  622                "        weight 13\n"
  623                "        uthreshold 98\n"
  624                "        MISC_CHECK {\n"
  625                "            misc_path \"amphora-health-checker sctp -t 31 "
  626                "192.168.1.1 9000\"\n"
  627                "            misc_timeout 32\n"
  628                "        }\n"
  629                "    }\n\n"
  630                "    # Configuration for Member sample_member_id_2\n"
  631                "    real_server 10.0.0.98 82 {\n"
  632                "        weight 13\n"
  633                "        uthreshold 98\n"
  634                "        MISC_CHECK {\n"
  635                "            misc_path \"amphora-health-checker sctp -t 31 "
  636                "192.168.1.1 9000\"\n"
  637                "            misc_timeout 32\n"
  638                "        }\n"
  639                "    }\n\n"
  640                "}\n\n")
  641 
  642         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  643             sample_configs_combined.sample_listener_tuple(
  644                 proto=lib_consts.PROTOCOL_SCTP,
  645                 monitor_ip_port=True,
  646                 monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  647                 persistence=False,
  648                 connection_limit=98))
  649         self.assertEqual(exp, rendered_obj)
  650 
  651     def test_render_template_sctp_no_other_resources(self):
  652         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  653                "# Configuration for Listener sample_listener_id_1\n\n"
  654                "net_namespace amphora-haproxy\n\n\n")
  655 
  656         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  657             sample_configs_combined.sample_listener_tuple(
  658                 proto=lib_consts.PROTOCOL_SCTP, monitor=False,
  659                 persistence=False, alloc_default_pool=False))
  660         self.assertEqual(exp, rendered_obj)
  661 
  662     def test_sctp_transform_session_persistence(self):
  663         persistence_src_ip = (
  664             sample_configs_combined.sample_session_persistence_tuple(
  665                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  666                 persistence_cookie=None,
  667                 persistence_timeout=33,
  668                 persistence_granularity='255.0.0.0'
  669             ))
  670         exp = sample_configs_combined.SCTP_SOURCE_IP_BODY
  671         ret = self.lvs_jinja_cfg._transform_session_persistence(
  672             persistence_src_ip)
  673         self.assertEqual(exp, ret)
  674 
  675     def test_sctp_transform_health_monitor(self):
  676         in_hm = sample_configs_combined.sample_health_monitor_tuple(
  677             proto=lib_consts.HEALTH_MONITOR_SCTP
  678         )
  679         ret = self.lvs_jinja_cfg._transform_health_monitor(in_hm)
  680         self.assertEqual(sample_configs_combined.RET_SCTP_HEALTH_MONITOR, ret)
  681 
  682     def test_sctp_transform_member(self):
  683         in_member = sample_configs_combined.sample_member_tuple(
  684             'member_id_1', '192.0.2.10')
  685         ret = self.lvs_jinja_cfg._transform_member(in_member)
  686         self.assertEqual(sample_configs_combined.RET_SCTP_MEMBER, ret)
  687 
  688         in_member = sample_configs_combined.sample_member_tuple(
  689             'member_id_1',
  690             '192.0.2.10',
  691             monitor_ip_port=True)
  692         ret = self.lvs_jinja_cfg._transform_member(in_member)
  693         self.assertEqual(
  694             sample_configs_combined.RET_SCTP_MEMBER_MONITOR_IP_PORT, ret)
  695 
  696     def test_sctp_transform_pool(self):
  697         in_pool = sample_configs_combined.sample_pool_tuple(
  698             proto=lib_consts.PROTOCOL_SCTP,
  699             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  700             persistence_timeout=33, persistence_granularity='255.0.0.0',
  701         )
  702         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  703         self.assertEqual(sample_configs_combined.RET_SCTP_POOL, ret)
  704 
  705         in_pool = sample_configs_combined.sample_pool_tuple(
  706             proto=lib_consts.PROTOCOL_SCTP,
  707             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  708             persistence_timeout=33, persistence_granularity='255.0.0.0',
  709             lb_algorithm=None,
  710         )
  711         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  712         self.assertEqual(sample_configs_combined.RET_SCTP_POOL, ret)
  713 
  714         in_pool = sample_configs_combined.sample_pool_tuple(
  715             proto=lib_consts.PROTOCOL_SCTP,
  716             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  717             persistence_timeout=33, persistence_granularity='255.0.0.0',
  718             monitor=False)
  719         sample_configs_combined.RET_SCTP_POOL['health_monitor'] = ''
  720         ret = self.lvs_jinja_cfg._transform_pool(in_pool)
  721         self.assertEqual(sample_configs_combined.RET_SCTP_POOL, ret)
  722 
  723     def test_sctp_transform_listener(self):
  724         in_listener = sample_configs_combined.sample_listener_tuple(
  725             proto=lib_consts.PROTOCOL_SCTP,
  726             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  727             persistence_timeout=33,
  728             persistence_granularity='255.0.0.0',
  729             monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  730             connection_limit=98
  731         )
  732         ret = self.lvs_jinja_cfg._transform_listener(in_listener)
  733         self.assertEqual(sample_configs_combined.RET_SCTP_LISTENER, ret)
  734 
  735         in_listener = sample_configs_combined.sample_listener_tuple(
  736             proto=lib_consts.PROTOCOL_SCTP,
  737             persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  738             persistence_timeout=33,
  739             persistence_granularity='255.0.0.0',
  740             monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  741             connection_limit=-1)
  742 
  743         ret = self.lvs_jinja_cfg._transform_listener(in_listener)
  744         sample_configs_combined.RET_SCTP_LISTENER.pop('connection_limit')
  745         self.assertEqual(sample_configs_combined.RET_SCTP_LISTENER, ret)
  746 
  747     def test_render_template_sctp_listener_with_http_health_monitor(self):
  748         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  749                "# Configuration for Listener sample_listener_id_1\n\n"
  750                "net_namespace amphora-haproxy\n\n"
  751                "virtual_server 10.0.0.2 80 {\n"
  752                "    lb_algo rr\n"
  753                "    lb_kind NAT\n"
  754                "    protocol SCTP\n"
  755                "    delay_loop 30\n"
  756                "    delay_before_retry 30\n"
  757                "    retry 3\n\n\n"
  758                "    # Configuration for Pool sample_pool_id_1\n"
  759                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  760                "    # Configuration for Member sample_member_id_1\n"
  761                "    real_server 10.0.0.99 82 {\n"
  762                "        weight 13\n"
  763                "        uthreshold 98\n"
  764                "        HTTP_GET {\n"
  765                "            url {\n"
  766                "              path /index.html\n"
  767                "              status_code 200\n"
  768                "            }\n"
  769                "            url {\n"
  770                "              path /index.html\n"
  771                "              status_code 201\n"
  772                "            }\n"
  773                "            connect_ip 10.0.0.99\n"
  774                "            connect_port 82\n"
  775                "            connect_timeout 31\n"
  776                "        }\n"
  777                "    }\n\n"
  778                "    # Configuration for Member sample_member_id_2\n"
  779                "    real_server 10.0.0.98 82 {\n"
  780                "        weight 13\n"
  781                "        uthreshold 98\n"
  782                "        HTTP_GET {\n"
  783                "            url {\n"
  784                "              path /index.html\n"
  785                "              status_code 200\n"
  786                "            }\n"
  787                "            url {\n"
  788                "              path /index.html\n"
  789                "              status_code 201\n"
  790                "            }\n"
  791                "            connect_ip 10.0.0.98\n"
  792                "            connect_port 82\n"
  793                "            connect_timeout 31\n"
  794                "        }\n"
  795                "    }\n\n"
  796                "}\n\n")
  797 
  798         listener = sample_configs_combined.sample_listener_tuple(
  799             proto=lib_consts.PROTOCOL_SCTP,
  800             monitor_proto=constants.HEALTH_MONITOR_HTTP,
  801             connection_limit=98,
  802             persistence=False,
  803             monitor_expected_codes='200-201')
  804 
  805         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  806         self.assertEqual(exp, rendered_obj)
  807 
  808     def test_render_template_sctp_listener_with_tcp_health_monitor(self):
  809         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  810                "# Configuration for Listener sample_listener_id_1\n\n"
  811                "net_namespace amphora-haproxy\n\n"
  812                "virtual_server 10.0.0.2 80 {\n"
  813                "    lb_algo rr\n"
  814                "    lb_kind NAT\n"
  815                "    protocol SCTP\n"
  816                "    delay_loop 30\n"
  817                "    delay_before_retry 30\n"
  818                "    retry 3\n\n\n"
  819                "    # Configuration for Pool sample_pool_id_1\n"
  820                "    # Configuration for HealthMonitor sample_monitor_id_1\n"
  821                "    # Configuration for Member sample_member_id_1\n"
  822                "    real_server 10.0.0.99 82 {\n"
  823                "        weight 13\n"
  824                "        uthreshold 98\n"
  825                "        TCP_CHECK {\n"
  826                "            connect_ip 10.0.0.99\n"
  827                "            connect_port 82\n"
  828                "            connect_timeout 31\n"
  829                "        }\n"
  830                "    }\n\n"
  831                "    # Configuration for Member sample_member_id_2\n"
  832                "    real_server 10.0.0.98 82 {\n"
  833                "        weight 13\n"
  834                "        uthreshold 98\n"
  835                "        TCP_CHECK {\n"
  836                "            connect_ip 10.0.0.98\n"
  837                "            connect_port 82\n"
  838                "            connect_timeout 31\n"
  839                "        }\n"
  840                "    }\n\n"
  841                "}\n\n")
  842         listener = sample_configs_combined.sample_listener_tuple(
  843             proto=lib_consts.PROTOCOL_SCTP,
  844             monitor_proto=constants.HEALTH_MONITOR_TCP,
  845             connection_limit=98,
  846             persistence=False)
  847 
  848         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(listener)
  849         self.assertEqual(exp, rendered_obj)
  850 
  851     def test_render_template_disabled_sctp_listener(self):
  852         exp = ("# Configuration for Loadbalancer sample_loadbalancer_id_1\n"
  853                "# Listener sample_listener_id_1 is disabled\n\n"
  854                "net_namespace amphora-haproxy\n\n")
  855         rendered_obj = self.lvs_jinja_cfg.render_loadbalancer_obj(
  856             sample_configs_combined.sample_listener_tuple(
  857                 enabled=False,
  858                 proto=lib_consts.PROTOCOL_SCTP,
  859                 persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
  860                 persistence_timeout=33,
  861                 persistence_granularity='255.255.0.0',
  862                 monitor_proto=lib_consts.HEALTH_MONITOR_SCTP,
  863                 connection_limit=98))
  864         self.assertEqual(exp, rendered_obj)