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 31\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_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 31\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, 'utils'):
             md.return_value = '/data/dirs/'
             be = ("backend sample_pool_id_1\n"
                   "    mode http\n"
                   "    balance roundrobin\n"
                   "    appsession APP_COOKIE len 56 timeout 3h\n"
                   "    timeout check 31\n"
                   "    option httpchk GET /index.html\n"
                   "    http-check expect rstatus %s\n"
                   "    option forwardfor\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_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"
           "    option forwardfor\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='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"
           "    option forwardfor\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='HTTP',
                                                  monitor=False), 'nogroup',
         '/sock_path', '/v2')
     self.assertEqual(
         sample_configs.sample_base_expected_config(backend=be),
         rendered_obj)
    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"
              "    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"
              "    redirect scheme https if !{ ssl_fc }\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    timeout check 31\n"
              "    option httpchk GET /index.html\n"
              "    http-check expect rstatus %s\n"
              "    option forwardfor\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, '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)
 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 #10
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"
              "    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"
              "    redirect scheme https if !{ ssl_fc }\n"
              "    balance roundrobin\n"
              "    cookie SRV insert indirect nocache\n"
              "    timeout check 31\n"
              "    option httpchk GET /index.html\n"
              "    http-check expect rstatus 405|404|500\n"
              "    option forwardfor\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")
        with mock.patch('os.makedirs'):
            with mock.patch('os.listdir'):
                with mock.patch.object(jinja_cfg, '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_http(self):
     be = ("backend sample_pool_id_1\n"
           "    mode http\n"
           "    balance roundrobin\n"
           "    cookie SRV insert indirect nocache\n"
           "    timeout check 31\n"
           "    option httpchk GET /index.html\n"
           "    http-check expect rstatus 405|404|500\n"
           "    option forwardfor\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")
     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)
 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 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 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)
 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"
         "    option forwardfor\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 #14
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 #15
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_tls_termination_no_sni(self):
        lb = sample_configs.sample_loadbalancer_tuple(proto="TERMINATED_HTTPS", tls=True)

        fe = (
            "frontend sample_listener_id_1\n"
            "    option tcplog\n"
            "    maxconn 98\n"
            "    option forwardfor\n"
            "    bind 10.0.0.2:443"
            " ssl crt /v2/sample_listener_id_1/fakeCNM.pem\n"
            "    mode http\n"
            "    default_backend sample_pool_id_1\n\n"
        )
        be = (
            "backend sample_pool_id_1\n"
            "    mode http\n"
            "    redirect scheme https if !{ ssl_fc }\n"
            "    balance roundrobin\n"
            "    cookie SRV insert indirect nocache\n"
            "    timeout check 31\n"
            "    option httpchk GET /index.html\n"
            "    http-check expect rstatus %s\n"
            "    option forwardfor\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("neutron.agent.linux.utils.replace_file"):
                with mock.patch("os.listdir"):
                    with mock.patch.object(jinja_cfg, "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": []}
                            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
                            )
 def test_render_template_no_monitor_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"
         "    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="HTTPS", monitor=False), "nogroup", "/sock_path", "/v2"
     )
     self.assertEqual(sample_configs.sample_base_expected_config(frontend=fe, backend=be), rendered_obj)
Example #18
0
 def test_render_template_appsession_persistence(self):
     with mock.patch('os.makedirs') as md:
         with mock.patch.object(jinja_cfg, 'n_utils'):
             md.return_value = '/data/dirs/'
             be = ("backend sample_pool_id_1\n"
                   "    mode http\n"
                   "    balance roundrobin\n"
                   "    appsession APP_COOKIE len 56 timeout 3h\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='APP_COOKIE'), 'nogroup',
                 '/sock_path', '/v2')
             self.assertEqual(
                 sample_configs.sample_base_expected_config(backend=be),
                 rendered_obj)
Example #19
0
 def test_transform_loadbalancer(self):
     in_lb = sample_configs.sample_loadbalancer_tuple()
     ret = jinja_cfg._transform_loadbalancer(in_lb, '/v2')
     self.assertEqual(sample_configs.RET_LB, ret)
 def test_transform_loadbalancer(self):
     in_lb = sample_configs.sample_loadbalancer_tuple()
     ret = jinja_cfg._transform_loadbalancer(in_lb, '/v2')
     self.assertEqual(sample_configs.RET_LB, ret)