Example #1
0
 def test_render_template_https(self):
     fe = ("frontend sample_listener_id_1\n"
           "    option tcplog\n"
           "    maxconn 98\n"
           "    bind 10.0.0.2:443\n"
           "    mode tcp\n"
           "    default_backend sample_pool_id_1\n\n")
     be = ("backend sample_pool_id_1\n"
           "    mode tcp\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    timeout check 31s\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    option ssl-hello-chk\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_2\n\n"
           % sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(proto='HTTPS'),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         frontend=fe, backend=be), rendered_obj)
 def test_render_template_appsession_persistence(self):
     with mock.patch('os.makedirs') as md:
         with mock.patch.object(jinja_cfg, 'file_utils'):
             md.return_value = '/data/dirs/'
             be = ("backend sample_pool_id_1\n"
                   "    mode http\n"
                   "    balance roundrobin\n"
                   "    stick-table type string len 64 size 10k\n"
                   "    stick store-response res.cook(APP_COOKIE)\n"
                   "    stick match req.cook(APP_COOKIE)\n"
                   "    timeout check 31s\n"
                   "    option httpchk GET /index.html\n"
                   "    http-check expect rstatus %s\n"
                   "    server sample_member_id_1 10.0.0.99:82 "
                   "weight 13 check inter 30s fall 3\n"
                   "    server sample_member_id_2 10.0.0.98:82 "
                   "weight 13 check inter 30s fall 3\n\n"
                   % sample_configs.PIPED_CODES)
             rendered_obj = jinja_cfg.render_loadbalancer_obj(
                 sample_configs.sample_loadbalancer_tuple(
                     persistence_type='APP_COOKIE'),
                 'nogroup', '/sock_path',
                 '/v2')
             self.assertEqual(
                 sample_configs.sample_base_expected_config(backend=be),
                 rendered_obj)
 def test_render_template_https(self):
     fe = ("frontend sample_listener_id_1\n"
           "    option tcplog\n"
           "    maxconn 98\n"
           "    bind 10.0.0.2:443\n"
           "    mode tcp\n"
           "    default_backend sample_pool_id_1\n\n")
     be = ("backend sample_pool_id_1\n"
           "    mode tcp\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    timeout check 31s\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    option ssl-hello-chk\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_2\n\n"
           % sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(proto='HTTPS'),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         frontend=fe, backend=be), rendered_obj)
Example #4
0
 def test_render_template_appsession_persistence(self):
     with mock.patch('os.makedirs') as md:
         with mock.patch.object(jinja_cfg, 'file_utils'):
             md.return_value = '/data/dirs/'
             be = ("backend sample_pool_id_1\n"
                   "    mode http\n"
                   "    balance roundrobin\n"
                   "    stick-table type string len 64 size 10k\n"
                   "    stick store-response res.cook(APP_COOKIE)\n"
                   "    stick match req.cook(APP_COOKIE)\n"
                   "    timeout check 31s\n"
                   "    option httpchk GET /index.html\n"
                   "    http-check expect rstatus %s\n"
                   "    server sample_member_id_1 10.0.0.99:82 "
                   "weight 13 check inter 30s fall 3\n"
                   "    server sample_member_id_2 10.0.0.98:82 "
                   "weight 13 check inter 30s fall 3\n\n" %
                   sample_configs.PIPED_CODES)
             rendered_obj = jinja_cfg.render_loadbalancer_obj(
                 sample_configs.sample_loadbalancer_tuple(
                     persistence_type='APP_COOKIE'), 'nogroup',
                 '/sock_path', '/v2')
             self.assertEqual(
                 sample_configs.sample_base_expected_config(backend=be),
                 rendered_obj)
Example #5
0
 def test_render_template_no_persistence_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto='HTTP', monitor=False, persistence=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         backend=be), rendered_obj)
 def test_render_template_no_persistence_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto='HTTP', monitor=False, persistence=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         backend=be), rendered_obj)
 def test_render_template_no_monitor_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13 "
           "cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13 "
           "cookie sample_member_id_2\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto=constants.PROTOCOL_HTTP, monitor=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         backend=be), rendered_obj)
 def test_render_template_no_monitor_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13 "
           "cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13 "
           "cookie sample_member_id_2\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto=constants.PROTOCOL_HTTP, monitor=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         backend=be), rendered_obj)
Example #9
0
    def test_render_template_tls_termination(self):
        lb = sample_configs.sample_loadbalancer_tuple(
            proto='TERMINATED_HTTPS', tls=True, sni=True)

        fe = ("frontend sample_listener_id_1\n"
              "    option tcplog\n"
              "    redirect scheme https if !{ ssl_fc }\n"
              "    maxconn 98\n"
              "    option forwardfor\n"
              "    bind 10.0.0.2:443"
              " ssl crt /v2/sample_listener_id_1/fakeCNM.pem"
              " crt /v2/sample_listener_id_1\n"
              "    mode http\n"
              "    default_backend sample_pool_id_1\n\n")
        be = ("backend sample_pool_id_1\n"
              "    mode http\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    timeout check 31s\n"
              "    option httpchk GET /index.html\n"
              "    http-check expect rstatus %s\n"
              "    server sample_member_id_1 10.0.0.99:82"
              " weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
              "    server sample_member_id_2 10.0.0.98:82"
              " weight 13 check inter 30s fall 3 cookie "
              "sample_member_id_2\n\n"
              % sample_configs.PIPED_CODES)
        with mock.patch('os.makedirs'):
            with mock.patch('os.listdir'):
                with mock.patch.object(jinja_cfg, 'n_utils'):
                    with mock.patch.object(
                            jinja_cfg, '_process_tls_certificates') as crt:
                        crt.return_value = {
                            'tls_cert': lb.listeners[0]
                            .default_tls_container,
                            'sni_certs': [lb.listeners[0]
                                          .sni_containers[0].tls_container]}
                        rendered_obj = jinja_cfg.render_loadbalancer_obj(
                            lb, 'nogroup',
                            '/sock_path',
                            '/v2')
                        self.assertEqual(
                            sample_configs.sample_base_expected_config(
                                frontend=fe, backend=be),
                            rendered_obj)
Example #10
0
    def test_render_template_tls_termination(self):
        lb = sample_configs.sample_loadbalancer_tuple(
            proto=constants.PROTOCOL_TERMINATED_HTTPS, tls=True, sni=True)

        fe = ("frontend sample_listener_id_1\n"
              "    option httplog\n"
              "    redirect scheme https if !{ ssl_fc }\n"
              "    maxconn 98\n"
              "    option forwardfor\n"
              "    bind 10.0.0.2:443"
              " ssl crt /v2/sample_listener_id_1/fakeCNM.pem"
              " crt /v2/sample_listener_id_1\n"
              "    mode http\n"
              "    default_backend sample_pool_id_1\n\n")
        be = ("backend sample_pool_id_1\n"
              "    mode http\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    timeout check 31s\n"
              "    option httpchk GET /index.html\n"
              "    http-check expect rstatus %s\n"
              "    server sample_member_id_1 10.0.0.99:82"
              " weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
              "    server sample_member_id_2 10.0.0.98:82"
              " weight 13 check inter 30s fall 3 cookie "
              "sample_member_id_2\n\n"
              % sample_configs.PIPED_CODES)
        with mock.patch('os.makedirs'):
            with mock.patch('os.listdir'):
                with mock.patch.object(jinja_cfg, 'file_utils'):
                    with mock.patch.object(
                            jinja_cfg, '_process_tls_certificates') as crt:
                        crt.return_value = {
                            'tls_cert': lb.listeners[0]
                            .default_tls_container,
                            'sni_certs': [lb.listeners[0]
                                          .sni_containers[0].tls_container]}
                        rendered_obj = jinja_cfg.render_loadbalancer_obj(
                            lb, 'nogroup',
                            '/sock_path',
                            '/v2')
                        self.assertEqual(
                            sample_configs.sample_base_expected_config(
                                frontend=fe, backend=be),
                            rendered_obj)
Example #11
0
 def test_render_template_no_persistence_https(self):
     fe = ("frontend sample_listener_id_1\n"
           "    option tcplog\n"
           "    maxconn 98\n"
           "    bind 10.0.0.2:443\n"
           "    mode tcp\n"
           "    default_backend sample_pool_id_1\n\n")
     be = ("backend sample_pool_id_1\n"
           "    mode tcp\n"
           "    balance roundrobin\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto='HTTPS', monitor=False, persistence=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         frontend=fe, backend=be), rendered_obj)
Example #12
0
 def test_render_template_no_persistence_https(self):
     fe = ("frontend sample_listener_id_1\n"
           "    option tcplog\n"
           "    maxconn 98\n"
           "    bind 10.0.0.2:443\n"
           "    mode tcp\n"
           "    default_backend sample_pool_id_1\n\n")
     be = ("backend sample_pool_id_1\n"
           "    mode tcp\n"
           "    balance roundrobin\n"
           "    server sample_member_id_1 10.0.0.99:82 weight 13\n"
           "    server sample_member_id_2 10.0.0.98:82 weight 13\n\n")
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             proto='HTTPS', monitor=False, persistence=False),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(sample_configs.sample_base_expected_config(
         frontend=fe, backend=be), rendered_obj)
 def test_render_template_about_option_log(self):
     for proto in constants.LISTENER_SUPPORTED_PROTOCOLS:
         proto_mode = jinja_cfg.PROTOCOL_MAP[proto]
         _rendered_obj = jinja_cfg.render_loadbalancer_obj(
             sample_configs.sample_loadbalancer_tuple(
                 proto=proto, monitor=False),
             'nogroup', '/sock_path', '/v2')
         expected_be = \
             ("backend sample_pool_id_1\n"
              "    mode %s\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    server sample_member_id_1 10.0.0.99:82 weight 13 "
              "cookie sample_member_id_1\n"
              "    server sample_member_id_2 10.0.0.98:82 weight 13 "
              "cookie sample_member_id_2\n\n") % proto_mode
         self.assertEqual(sample_configs.sample_base_expected_config(
             backend=expected_be, fe_proto=proto), _rendered_obj)
Example #14
0
 def test_render_template_about_option_log(self):
     for proto in constants.LISTENER_SUPPORTED_PROTOCOLS:
         proto_mode = jinja_cfg.PROTOCOL_MAP[proto]
         _rendered_obj = jinja_cfg.render_loadbalancer_obj(
             sample_configs.sample_loadbalancer_tuple(
                 proto=proto, monitor=False),
             'nogroup', '/sock_path', '/v2')
         expected_be = \
             ("backend sample_pool_id_1\n"
              "    mode %s\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    server sample_member_id_1 10.0.0.99:82 weight 13 "
              "cookie sample_member_id_1\n"
              "    server sample_member_id_2 10.0.0.98:82 weight 13 "
              "cookie sample_member_id_2\n\n") % proto_mode
         self.assertEqual(sample_configs.sample_base_expected_config(
             backend=expected_be, fe_proto=proto), _rendered_obj)
Example #15
0
 def test_render_template_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    timeout check 31s\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_2\n\n"
           % sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(
         sample_configs.sample_base_expected_config(backend=be),
         rendered_obj)
Example #16
0
 def test_render_template_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    timeout check 31s\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_1\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3 cookie sample_member_id_2\n\n"
           % sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(
         sample_configs.sample_base_expected_config(backend=be),
         rendered_obj)
Example #17
0
 def test_render_template_sourceip_persistence(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    stick-table type ip size 10k\n"
           "    stick on src\n"
           "    timeout check 31\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3\n\n" %
           sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             persistence_type='SOURCE_IP'), 'nogroup', '/sock_path', '/v2')
     self.assertEqual(
         sample_configs.sample_base_expected_config(backend=be),
         rendered_obj)
Example #18
0
 def test_render_template_sourceip_persistence(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    stick-table type ip size 10k\n"
           "    stick on src\n"
           "    timeout check 31s\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus %s\n"
           "    server sample_member_id_1 10.0.0.99:82 "
           "weight 13 check inter 30s fall 3\n"
           "    server sample_member_id_2 10.0.0.98:82 "
           "weight 13 check inter 30s fall 3\n\n"
           % sample_configs.PIPED_CODES)
     rendered_obj = jinja_cfg.render_loadbalancer_obj(
         sample_configs.sample_loadbalancer_tuple(
             persistence_type='SOURCE_IP'),
         'nogroup', '/sock_path', '/v2')
     self.assertEqual(
         sample_configs.sample_base_expected_config(backend=be),
         rendered_obj)