"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/tests/common/sample_data_models.py" (14 Apr 2021, 31947 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. See also the latest Fossies "Diffs" side-by-side code changes report for "sample_data_models.py": 7.1.1_vs_8.0.0.

    1 #    Copyright 2018 Rackspace, US Inc.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 import copy
   16 import datetime
   17 
   18 from octavia_lib.api.drivers import data_models as driver_dm
   19 from octavia_lib.common import constants as lib_consts
   20 from oslo_utils import uuidutils
   21 
   22 from octavia.common import constants
   23 from octavia.common import data_models
   24 
   25 
   26 class SampleDriverDataModels(object):
   27 
   28     def __init__(self):
   29         self.project_id = uuidutils.generate_uuid()
   30         self.lb_id = uuidutils.generate_uuid()
   31         self.ip_address = '192.0.2.30'
   32         self.port_id = uuidutils.generate_uuid()
   33         self.network_id = uuidutils.generate_uuid()
   34         self.subnet_id = uuidutils.generate_uuid()
   35         self.qos_policy_id = uuidutils.generate_uuid()
   36         self.lb_name = uuidutils.generate_uuid()
   37         self.lb_description = uuidutils.generate_uuid()
   38         self.flavor_id = uuidutils.generate_uuid()
   39         self.flavor_profile_id = uuidutils.generate_uuid()
   40 
   41         self.listener1_id = uuidutils.generate_uuid()
   42         self.listener2_id = uuidutils.generate_uuid()
   43         self.default_tls_container_ref = uuidutils.generate_uuid()
   44         self.sni_container_ref_1 = uuidutils.generate_uuid()
   45         self.sni_container_ref_2 = uuidutils.generate_uuid()
   46         self.client_ca_tls_certificate_ref = uuidutils.generate_uuid()
   47         self.client_crl_container_ref = uuidutils.generate_uuid()
   48         self.pool_sni_container_ref = uuidutils.generate_uuid()
   49         self.pool_ca_container_ref = uuidutils.generate_uuid()
   50         self.pool_crl_container_ref = uuidutils.generate_uuid()
   51 
   52         self.pool1_id = uuidutils.generate_uuid()
   53         self.pool2_id = uuidutils.generate_uuid()
   54 
   55         self.hm1_id = uuidutils.generate_uuid()
   56         self.hm2_id = uuidutils.generate_uuid()
   57 
   58         self.member1_id = uuidutils.generate_uuid()
   59         self.member2_id = uuidutils.generate_uuid()
   60         self.member3_id = uuidutils.generate_uuid()
   61         self.member4_id = uuidutils.generate_uuid()
   62 
   63         self.l7policy1_id = uuidutils.generate_uuid()
   64         self.l7policy2_id = uuidutils.generate_uuid()
   65 
   66         self.l7rule1_id = uuidutils.generate_uuid()
   67         self.l7rule2_id = uuidutils.generate_uuid()
   68 
   69         self.created_at = datetime.datetime.now()
   70         self.updated_at = (datetime.datetime.now() +
   71                            datetime.timedelta(minutes=1))
   72 
   73         self._common_test_dict = {
   74             lib_consts.PROVISIONING_STATUS: constants.ACTIVE,
   75             lib_consts.OPERATING_STATUS: constants.ONLINE,
   76             lib_consts.PROJECT_ID: self.project_id,
   77             constants.CREATED_AT: self.created_at,
   78             constants.UPDATED_AT: self.updated_at,
   79             constants.ENABLED: True}
   80 
   81         # Setup Health Monitors
   82         self.test_hm1_dict = {
   83             lib_consts.ID: self.hm1_id,
   84             lib_consts.TYPE: constants.HEALTH_MONITOR_PING,
   85             lib_consts.DELAY: 1, lib_consts.TIMEOUT: 3,
   86             lib_consts.FALL_THRESHOLD: 1, lib_consts.RISE_THRESHOLD: 2,
   87             lib_consts.HTTP_METHOD: lib_consts.HEALTH_MONITOR_HTTP_METHOD_GET,
   88             lib_consts.URL_PATH: '/', lib_consts.EXPECTED_CODES: '200',
   89             lib_consts.NAME: 'hm1', lib_consts.POOL_ID: self.pool1_id,
   90             lib_consts.HTTP_VERSION: 1.0, lib_consts.DOMAIN_NAME: None,
   91             lib_consts.PROJECT_ID: self.project_id}
   92 
   93         self.test_hm1_dict.update(self._common_test_dict)
   94 
   95         self.test_hm2_dict = copy.deepcopy(self.test_hm1_dict)
   96         self.test_hm2_dict[lib_consts.ID] = self.hm2_id
   97         self.test_hm2_dict[lib_consts.NAME] = 'hm2'
   98         self.test_hm2_dict.update(
   99             {lib_consts.HTTP_VERSION: 1.1,
  100              lib_consts.DOMAIN_NAME: 'testdomainname.com'})
  101 
  102         self.db_hm1 = data_models.HealthMonitor(**self.test_hm1_dict)
  103         self.db_hm2 = data_models.HealthMonitor(**self.test_hm2_dict)
  104 
  105         self.provider_hm1_dict = {
  106             lib_consts.ADMIN_STATE_UP: True,
  107             lib_consts.DELAY: 1, lib_consts.EXPECTED_CODES: '200',
  108             lib_consts.HEALTHMONITOR_ID: self.hm1_id,
  109             lib_consts.HTTP_METHOD: lib_consts.HEALTH_MONITOR_HTTP_METHOD_GET,
  110             lib_consts.MAX_RETRIES: 2,
  111             lib_consts.MAX_RETRIES_DOWN: 1,
  112             lib_consts.NAME: 'hm1',
  113             lib_consts.POOL_ID: self.pool1_id,
  114             lib_consts.PROJECT_ID: self.project_id,
  115             lib_consts.TIMEOUT: 3,
  116             lib_consts.TYPE: constants.HEALTH_MONITOR_PING,
  117             lib_consts.URL_PATH: '/',
  118             lib_consts.HTTP_VERSION: 1.0,
  119             lib_consts.DOMAIN_NAME: None}
  120 
  121         self.provider_hm2_dict = copy.deepcopy(self.provider_hm1_dict)
  122         self.provider_hm2_dict[lib_consts.HEALTHMONITOR_ID] = self.hm2_id
  123         self.provider_hm2_dict[lib_consts.NAME] = 'hm2'
  124         self.provider_hm2_dict.update(
  125             {lib_consts.HTTP_VERSION: 1.1,
  126              lib_consts.DOMAIN_NAME: 'testdomainname.com'})
  127 
  128         self.provider_hm1 = driver_dm.HealthMonitor(**self.provider_hm1_dict)
  129         self.provider_hm2 = driver_dm.HealthMonitor(**self.provider_hm2_dict)
  130 
  131         # Setup Members
  132         self.test_member1_dict = {
  133             lib_consts.ID: self.member1_id,
  134             lib_consts.POOL_ID: self.pool1_id,
  135             constants.IP_ADDRESS: '192.0.2.16',
  136             lib_consts.PROTOCOL_PORT: 80, lib_consts.WEIGHT: 0,
  137             lib_consts.BACKUP: False,
  138             lib_consts.SUBNET_ID: self.subnet_id,
  139             lib_consts.PROJECT_ID: self.project_id,
  140             lib_consts.NAME: 'member1',
  141             lib_consts.OPERATING_STATUS: lib_consts.ONLINE,
  142             lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
  143             constants.ENABLED: True,
  144             constants.CREATED_AT: self.created_at,
  145             constants.UPDATED_AT: self.updated_at,
  146             lib_consts.MONITOR_ADDRESS: '192.0.2.26',
  147             lib_consts.MONITOR_PORT: 81}
  148 
  149         self.test_member1_dict.update(self._common_test_dict)
  150 
  151         self.test_member2_dict = copy.deepcopy(self.test_member1_dict)
  152         self.test_member2_dict[lib_consts.ID] = self.member2_id
  153         self.test_member2_dict[constants.IP_ADDRESS] = '192.0.2.17'
  154         self.test_member2_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.27'
  155         self.test_member2_dict[lib_consts.NAME] = 'member2'
  156 
  157         self.test_member3_dict = copy.deepcopy(self.test_member1_dict)
  158         self.test_member3_dict[lib_consts.ID] = self.member3_id
  159         self.test_member3_dict[constants.IP_ADDRESS] = '192.0.2.18'
  160         self.test_member3_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.28'
  161         self.test_member3_dict[lib_consts.NAME] = 'member3'
  162         self.test_member3_dict[lib_consts.POOL_ID] = self.pool2_id
  163 
  164         self.test_member4_dict = copy.deepcopy(self.test_member1_dict)
  165         self.test_member4_dict[lib_consts.ID] = self.member4_id
  166         self.test_member4_dict[constants.IP_ADDRESS] = '192.0.2.19'
  167         self.test_member4_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.29'
  168         self.test_member4_dict[lib_consts.NAME] = 'member4'
  169         self.test_member4_dict[lib_consts.POOL_ID] = self.pool2_id
  170 
  171         self.test_pool1_members_dict = [self.test_member1_dict,
  172                                         self.test_member2_dict]
  173         self.test_pool2_members_dict = [self.test_member3_dict,
  174                                         self.test_member4_dict]
  175 
  176         self.db_member1 = data_models.Member(**self.test_member1_dict)
  177         self.db_member2 = data_models.Member(**self.test_member2_dict)
  178         self.db_member3 = data_models.Member(**self.test_member3_dict)
  179         self.db_member4 = data_models.Member(**self.test_member4_dict)
  180 
  181         self.db_pool1_members = [self.db_member1, self.db_member2]
  182         self.db_pool2_members = [self.db_member3, self.db_member4]
  183 
  184         self.provider_member1_dict = {lib_consts.ADDRESS: '192.0.2.16',
  185                                       lib_consts.ADMIN_STATE_UP: True,
  186                                       lib_consts.MEMBER_ID: self.member1_id,
  187                                       lib_consts.MONITOR_ADDRESS: '192.0.2.26',
  188                                       lib_consts.MONITOR_PORT: 81,
  189                                       lib_consts.NAME: 'member1',
  190                                       lib_consts.POOL_ID: self.pool1_id,
  191                                       lib_consts.PROJECT_ID: self.project_id,
  192                                       lib_consts.PROTOCOL_PORT: 80,
  193                                       lib_consts.SUBNET_ID: self.subnet_id,
  194                                       lib_consts.WEIGHT: 0,
  195                                       lib_consts.BACKUP: False}
  196 
  197         self.provider_member2_dict = copy.deepcopy(self.provider_member1_dict)
  198         self.provider_member2_dict[lib_consts.MEMBER_ID] = self.member2_id
  199         self.provider_member2_dict[lib_consts.ADDRESS] = '192.0.2.17'
  200         self.provider_member2_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.27'
  201         self.provider_member2_dict[lib_consts.NAME] = 'member2'
  202 
  203         self.provider_member3_dict = copy.deepcopy(self.provider_member1_dict)
  204         self.provider_member3_dict[lib_consts.MEMBER_ID] = self.member3_id
  205         self.provider_member3_dict[lib_consts.ADDRESS] = '192.0.2.18'
  206         self.provider_member3_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.28'
  207         self.provider_member3_dict[lib_consts.NAME] = 'member3'
  208         self.provider_member3_dict[lib_consts.POOL_ID] = self.pool2_id
  209 
  210         self.provider_member4_dict = copy.deepcopy(self.provider_member1_dict)
  211         self.provider_member4_dict[lib_consts.MEMBER_ID] = self.member4_id
  212         self.provider_member4_dict[lib_consts.ADDRESS] = '192.0.2.19'
  213         self.provider_member4_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.29'
  214         self.provider_member4_dict[lib_consts.NAME] = 'member4'
  215         self.provider_member4_dict[lib_consts.POOL_ID] = self.pool2_id
  216 
  217         self.provider_pool1_members_dict = [self.provider_member1_dict,
  218                                             self.provider_member2_dict]
  219 
  220         self.provider_pool2_members_dict = [self.provider_member3_dict,
  221                                             self.provider_member4_dict]
  222 
  223         self.provider_member1 = driver_dm.Member(**self.provider_member1_dict)
  224         self.provider_member2 = driver_dm.Member(**self.provider_member2_dict)
  225         self.provider_member3 = driver_dm.Member(**self.provider_member3_dict)
  226         self.provider_member4 = driver_dm.Member(**self.provider_member4_dict)
  227 
  228         self.provider_pool1_members = [self.provider_member1,
  229                                        self.provider_member2]
  230         self.provider_pool2_members = [self.provider_member3,
  231                                        self.provider_member4]
  232 
  233         # Setup test pools
  234         self.test_pool1_dict = {
  235             lib_consts.ID: self.pool1_id,
  236             lib_consts.NAME: 'pool1', lib_consts.DESCRIPTION: 'Pool 1',
  237             constants.LOAD_BALANCER_ID: self.lb_id,
  238             lib_consts.PROJECT_ID: self.project_id,
  239             lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
  240             lib_consts.LB_ALGORITHM: lib_consts.LB_ALGORITHM_ROUND_ROBIN,
  241             lib_consts.MEMBERS: self.test_pool1_members_dict,
  242             constants.HEALTH_MONITOR: self.test_hm1_dict,
  243             lib_consts.SESSION_PERSISTENCE: {
  244                 lib_consts.TYPE: lib_consts.LB_ALGORITHM_SOURCE_IP},
  245             lib_consts.LISTENERS: [],
  246             lib_consts.L7POLICIES: [],
  247             constants.TLS_CERTIFICATE_ID: self.pool_sni_container_ref,
  248             constants.CA_TLS_CERTIFICATE_ID: self.pool_ca_container_ref,
  249             constants.CRL_CONTAINER_ID: self.pool_crl_container_ref,
  250             lib_consts.TLS_ENABLED: True,
  251             lib_consts.TLS_CIPHERS: None,
  252             lib_consts.TLS_VERSIONS: None,
  253             lib_consts.ALPN_PROTOCOLS:
  254                 constants.AMPHORA_SUPPORTED_ALPN_PROTOCOLS
  255         }
  256 
  257         self.test_pool1_dict.update(self._common_test_dict)
  258 
  259         self.test_pool2_dict = copy.deepcopy(self.test_pool1_dict)
  260         self.test_pool2_dict[lib_consts.ID] = self.pool2_id
  261         self.test_pool2_dict[lib_consts.NAME] = 'pool2'
  262         self.test_pool2_dict[lib_consts.DESCRIPTION] = 'Pool 2'
  263         self.test_pool2_dict[
  264             lib_consts.MEMBERS] = self.test_pool2_members_dict
  265         del self.test_pool2_dict[constants.TLS_CERTIFICATE_ID]
  266         del self.test_pool2_dict[constants.CA_TLS_CERTIFICATE_ID]
  267         del self.test_pool2_dict[constants.CRL_CONTAINER_ID]
  268 
  269         self.test_pools = [self.test_pool1_dict, self.test_pool2_dict]
  270 
  271         self.db_pool1 = data_models.Pool(**self.test_pool1_dict)
  272         self.db_pool1.health_monitor = self.db_hm1
  273         self.db_pool1.members = self.db_pool1_members
  274         self.db_pool2 = data_models.Pool(**self.test_pool2_dict)
  275         self.db_pool2.health_monitor = self.db_hm2
  276         self.db_pool2.members = self.db_pool2_members
  277 
  278         self.test_db_pools = [self.db_pool1, self.db_pool2]
  279         pool_cert = data_models.TLSContainer(certificate='pool cert')
  280         pool_ca_file_content = 'X509 POOL CA CERT FILE'
  281         pool_crl_file_content = 'X509 POOL CRL FILE'
  282 
  283         self.provider_pool1_dict = {
  284             lib_consts.ADMIN_STATE_UP: True,
  285             lib_consts.DESCRIPTION: 'Pool 1',
  286             lib_consts.HEALTHMONITOR: self.provider_hm1_dict,
  287             lib_consts.LB_ALGORITHM: lib_consts.LB_ALGORITHM_ROUND_ROBIN,
  288             lib_consts.LOADBALANCER_ID: self.lb_id,
  289             lib_consts.MEMBERS: self.provider_pool1_members_dict,
  290             lib_consts.NAME: 'pool1',
  291             lib_consts.POOL_ID: self.pool1_id,
  292             lib_consts.PROJECT_ID: self.project_id,
  293             lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
  294             lib_consts.SESSION_PERSISTENCE: {
  295                 lib_consts.TYPE: lib_consts.LB_ALGORITHM_SOURCE_IP},
  296             lib_consts.TLS_CONTAINER_REF: self.pool_sni_container_ref,
  297             lib_consts.TLS_CONTAINER_DATA: pool_cert.to_dict(),
  298             lib_consts.CA_TLS_CONTAINER_REF: self.pool_ca_container_ref,
  299             lib_consts.CA_TLS_CONTAINER_DATA: pool_ca_file_content,
  300             lib_consts.CRL_CONTAINER_REF: self.pool_crl_container_ref,
  301             lib_consts.CRL_CONTAINER_DATA: pool_crl_file_content,
  302             lib_consts.TLS_ENABLED: True,
  303             lib_consts.TLS_CIPHERS: None,
  304             lib_consts.TLS_VERSIONS: None,
  305             lib_consts.ALPN_PROTOCOLS:
  306                 constants.AMPHORA_SUPPORTED_ALPN_PROTOCOLS
  307         }
  308 
  309         self.provider_pool2_dict = copy.deepcopy(self.provider_pool1_dict)
  310         self.provider_pool2_dict[lib_consts.POOL_ID] = self.pool2_id
  311         self.provider_pool2_dict[lib_consts.NAME] = 'pool2'
  312         self.provider_pool2_dict[lib_consts.DESCRIPTION] = 'Pool 2'
  313         self.provider_pool2_dict[
  314             lib_consts.MEMBERS] = self.provider_pool2_members_dict
  315         self.provider_pool2_dict[
  316             lib_consts.HEALTHMONITOR] = self.provider_hm2_dict
  317         self.provider_pool2_dict[lib_consts.TLS_CONTAINER_REF] = None
  318         del self.provider_pool2_dict[lib_consts.TLS_CONTAINER_DATA]
  319         self.provider_pool2_dict[lib_consts.CA_TLS_CONTAINER_REF] = None
  320         del self.provider_pool2_dict[lib_consts.CA_TLS_CONTAINER_DATA]
  321         self.provider_pool2_dict[lib_consts.CRL_CONTAINER_REF] = None
  322         del self.provider_pool2_dict[lib_consts.CRL_CONTAINER_DATA]
  323 
  324         self.provider_pool1 = driver_dm.Pool(**self.provider_pool1_dict)
  325         self.provider_pool1.members = self.provider_pool1_members
  326         self.provider_pool1.healthmonitor = self.provider_hm1
  327         self.provider_pool2 = driver_dm.Pool(**self.provider_pool2_dict)
  328         self.provider_pool2.members = self.provider_pool2_members
  329         self.provider_pool2.healthmonitor = self.provider_hm2
  330 
  331         self.provider_pools = [self.provider_pool1, self.provider_pool2]
  332 
  333         # Setup L7Rules
  334         self.test_l7rule1_dict = {
  335             lib_consts.ID: self.l7rule1_id,
  336             lib_consts.L7POLICY_ID: self.l7policy1_id,
  337             lib_consts.TYPE: lib_consts.L7RULE_TYPE_PATH,
  338             lib_consts.COMPARE_TYPE: lib_consts.L7RULE_COMPARE_TYPE_EQUAL_TO,
  339             lib_consts.KEY: 'fake_key',
  340             lib_consts.VALUE: 'fake_value',
  341             lib_consts.PROJECT_ID: self.project_id,
  342             constants.L7POLICY: None,
  343             lib_consts.INVERT: False}
  344 
  345         self.test_l7rule1_dict.update(self._common_test_dict)
  346 
  347         self.test_l7rule2_dict = copy.deepcopy(self.test_l7rule1_dict)
  348         self.test_l7rule2_dict[lib_consts.ID] = self.l7rule2_id
  349 
  350         self.test_l7rules = [self.test_l7rule1_dict, self.test_l7rule2_dict]
  351 
  352         self.db_l7Rule1 = data_models.L7Rule(**self.test_l7rule1_dict)
  353         self.db_l7Rule2 = data_models.L7Rule(**self.test_l7rule2_dict)
  354 
  355         self.db_l7Rules = [self.db_l7Rule1, self.db_l7Rule2]
  356 
  357         self.provider_l7rule1_dict = {
  358             lib_consts.ADMIN_STATE_UP: True,
  359             lib_consts.COMPARE_TYPE: lib_consts.L7RULE_COMPARE_TYPE_EQUAL_TO,
  360             lib_consts.INVERT: False,
  361             lib_consts.KEY: 'fake_key',
  362             lib_consts.L7POLICY_ID: self.l7policy1_id,
  363             lib_consts.L7RULE_ID: self.l7rule1_id,
  364             lib_consts.TYPE: lib_consts.L7RULE_TYPE_PATH,
  365             lib_consts.PROJECT_ID: self.project_id,
  366             lib_consts.VALUE: 'fake_value'}
  367 
  368         self.provider_l7rule2_dict = copy.deepcopy(self.provider_l7rule1_dict)
  369         self.provider_l7rule2_dict[lib_consts.L7RULE_ID] = self.l7rule2_id
  370         self.provider_l7rules_dicts = [self.provider_l7rule1_dict,
  371                                        self.provider_l7rule2_dict]
  372 
  373         self.provider_l7rule1 = driver_dm.L7Rule(**self.provider_l7rule1_dict)
  374         self.provider_l7rule2 = driver_dm.L7Rule(**self.provider_l7rule2_dict)
  375 
  376         self.provider_rules = [self.provider_l7rule1, self.provider_l7rule2]
  377 
  378         # Setup L7Policies
  379         self.test_l7policy1_dict = {
  380             lib_consts.ID: self.l7policy1_id,
  381             lib_consts.NAME: 'l7policy_1',
  382             lib_consts.DESCRIPTION: 'L7policy 1',
  383             lib_consts.LISTENER_ID: self.listener1_id,
  384             lib_consts.ACTION: lib_consts.L7POLICY_ACTION_REDIRECT_TO_URL,
  385             lib_consts.REDIRECT_POOL_ID: None,
  386             lib_consts.REDIRECT_URL: 'http://example.com/index.html',
  387             lib_consts.REDIRECT_PREFIX: None,
  388             lib_consts.PROJECT_ID: self.project_id,
  389             lib_consts.POSITION: 1,
  390             constants.LISTENER: None,
  391             constants.REDIRECT_POOL: None,
  392             lib_consts.L7RULES: self.test_l7rules,
  393             lib_consts.REDIRECT_HTTP_CODE: 302}
  394 
  395         self.test_l7policy1_dict.update(self._common_test_dict)
  396 
  397         self.test_l7policy2_dict = copy.deepcopy(self.test_l7policy1_dict)
  398         self.test_l7policy2_dict[lib_consts.ID] = self.l7policy2_id
  399         self.test_l7policy2_dict[lib_consts.NAME] = 'l7policy_2'
  400         self.test_l7policy2_dict[lib_consts.DESCRIPTION] = 'L7policy 2'
  401 
  402         self.test_l7policies = [self.test_l7policy1_dict,
  403                                 self.test_l7policy2_dict]
  404 
  405         self.db_l7policy1 = data_models.L7Policy(**self.test_l7policy1_dict)
  406         self.db_l7policy2 = data_models.L7Policy(**self.test_l7policy2_dict)
  407         self.db_l7policy1.l7rules = self.db_l7Rules
  408         self.db_l7policy2.l7rules = self.db_l7Rules
  409 
  410         self.db_l7policies = [self.db_l7policy1, self.db_l7policy2]
  411 
  412         self.provider_l7policy1_dict = {
  413             lib_consts.ACTION: lib_consts.L7POLICY_ACTION_REDIRECT_TO_URL,
  414             lib_consts.ADMIN_STATE_UP: True,
  415             lib_consts.DESCRIPTION: 'L7policy 1',
  416             lib_consts.L7POLICY_ID: self.l7policy1_id,
  417             lib_consts.LISTENER_ID: self.listener1_id,
  418             lib_consts.NAME: 'l7policy_1',
  419             lib_consts.POSITION: 1,
  420             lib_consts.PROJECT_ID: self.project_id,
  421             lib_consts.REDIRECT_POOL_ID: None,
  422             lib_consts.REDIRECT_URL: 'http://example.com/index.html',
  423             lib_consts.REDIRECT_PREFIX: None,
  424             lib_consts.RULES: self.provider_l7rules_dicts,
  425             lib_consts.REDIRECT_HTTP_CODE: 302
  426         }
  427 
  428         self.provider_l7policy2_dict = copy.deepcopy(
  429             self.provider_l7policy1_dict)
  430         self.provider_l7policy2_dict[
  431             lib_consts.L7POLICY_ID] = self.l7policy2_id
  432         self.provider_l7policy2_dict[lib_consts.NAME] = 'l7policy_2'
  433         self.provider_l7policy2_dict[lib_consts.DESCRIPTION] = 'L7policy 2'
  434 
  435         self.provider_l7policies_dict = [self.provider_l7policy1_dict,
  436                                          self.provider_l7policy2_dict]
  437 
  438         self.provider_l7policy1 = driver_dm.L7Policy(
  439             **self.provider_l7policy1_dict)
  440         self.provider_l7policy1.rules = self.provider_rules
  441         self.provider_l7policy2 = driver_dm.L7Policy(
  442             **self.provider_l7policy2_dict)
  443         self.provider_l7policy2.rules = self.provider_rules
  444 
  445         self.provider_l7policies = [self.provider_l7policy1,
  446                                     self.provider_l7policy2]
  447 
  448         # Setup Listeners
  449         self.test_listener1_dict = {
  450             lib_consts.ID: self.listener1_id,
  451             lib_consts.NAME: 'listener_1',
  452             lib_consts.DESCRIPTION: 'Listener 1',
  453             lib_consts.DEFAULT_POOL_ID: self.pool1_id,
  454             constants.LOAD_BALANCER_ID: self.lb_id,
  455             lib_consts.PROJECT_ID: self.project_id,
  456             lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
  457             lib_consts.PROTOCOL_PORT: 90,
  458             lib_consts.CONNECTION_LIMIT: 10000,
  459             constants.TLS_CERTIFICATE_ID: self.default_tls_container_ref,
  460             lib_consts.DEFAULT_POOL: self.test_pool1_dict,
  461             constants.SNI_CONTAINERS: [self.sni_container_ref_1,
  462                                        self.sni_container_ref_2],
  463             constants.PEER_PORT: 55,
  464             lib_consts.L7POLICIES: self.test_l7policies,
  465             lib_consts.INSERT_HEADERS: {},
  466             lib_consts.TIMEOUT_CLIENT_DATA: 1000,
  467             lib_consts.TIMEOUT_MEMBER_CONNECT: 2000,
  468             lib_consts.TIMEOUT_MEMBER_DATA: 3000,
  469             lib_consts.TIMEOUT_TCP_INSPECT: 4000,
  470             constants.CLIENT_CA_TLS_CERTIFICATE_ID:
  471                 self.client_ca_tls_certificate_ref,
  472             lib_consts.CLIENT_AUTHENTICATION: constants.CLIENT_AUTH_NONE,
  473             constants.CLIENT_CRL_CONTAINER_ID: self.client_crl_container_ref,
  474             lib_consts.ALLOWED_CIDRS: ['192.0.2.0/24', '198.51.100.0/24'],
  475             lib_consts.TLS_CIPHERS: constants.CIPHERS_OWASP_SUITE_B,
  476             lib_consts.TLS_VERSIONS: constants.TLS_VERSIONS_OWASP_SUITE_B,
  477             lib_consts.ALPN_PROTOCOLS:
  478                 constants.AMPHORA_SUPPORTED_ALPN_PROTOCOLS
  479         }
  480 
  481         self.test_listener1_dict.update(self._common_test_dict)
  482 
  483         self.test_listener2_dict = copy.deepcopy(self.test_listener1_dict)
  484         self.test_listener2_dict[lib_consts.ID] = self.listener2_id
  485         self.test_listener2_dict[lib_consts.NAME] = 'listener_2'
  486         self.test_listener2_dict[lib_consts.DESCRIPTION] = 'Listener 1'
  487         self.test_listener2_dict[lib_consts.DEFAULT_POOL_ID] = self.pool2_id
  488         self.test_listener2_dict[
  489             lib_consts.DEFAULT_POOL] = self.test_pool2_dict
  490         del self.test_listener2_dict[lib_consts.L7POLICIES]
  491         del self.test_listener2_dict[constants.SNI_CONTAINERS]
  492         del self.test_listener2_dict[constants.CLIENT_CA_TLS_CERTIFICATE_ID]
  493         del self.test_listener2_dict[constants.CLIENT_CRL_CONTAINER_ID]
  494 
  495         self.test_listeners = [self.test_listener1_dict,
  496                                self.test_listener2_dict]
  497 
  498         self.db_listener1 = data_models.Listener(**self.test_listener1_dict)
  499         self.db_listener2 = data_models.Listener(**self.test_listener2_dict)
  500         self.db_listener1.default_pool = self.db_pool1
  501         self.db_listener2.default_pool = self.db_pool2
  502         self.db_listener1.l7policies = self.db_l7policies
  503         self.db_listener1.sni_containers = [
  504             data_models.SNI(tls_container_id='2'),
  505             data_models.SNI(tls_container_id='3')]
  506 
  507         self.test_db_listeners = [self.db_listener1, self.db_listener2]
  508 
  509         cert1 = data_models.TLSContainer(certificate='cert 1')
  510         cert2 = data_models.TLSContainer(certificate='cert 2')
  511         cert3 = data_models.TLSContainer(certificate='cert 3')
  512         ca_cert = 'ca cert'
  513         crl_file_content = 'X509 CRL FILE'
  514 
  515         self.provider_listener1_dict = {
  516             lib_consts.ADMIN_STATE_UP: True,
  517             lib_consts.ALLOWED_CIDRS: ['192.0.2.0/24', '198.51.100.0/24'],
  518             lib_consts.ALPN_PROTOCOLS: [lib_consts.ALPN_PROTOCOL_HTTP_1_1],
  519             lib_consts.CONNECTION_LIMIT: 10000,
  520             lib_consts.DEFAULT_POOL: self.provider_pool1_dict,
  521             lib_consts.DEFAULT_POOL_ID: self.pool1_id,
  522             lib_consts.DEFAULT_TLS_CONTAINER_DATA: cert1.to_dict(),
  523             lib_consts.DEFAULT_TLS_CONTAINER_REF:
  524                 self.default_tls_container_ref,
  525             lib_consts.DESCRIPTION: 'Listener 1',
  526             lib_consts.INSERT_HEADERS: {},
  527             lib_consts.L7POLICIES: self.provider_l7policies_dict,
  528             lib_consts.LISTENER_ID: self.listener1_id,
  529             lib_consts.LOADBALANCER_ID: self.lb_id,
  530             lib_consts.NAME: 'listener_1',
  531             lib_consts.PROJECT_ID: self.project_id,
  532             lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
  533             lib_consts.PROTOCOL_PORT: 90,
  534             lib_consts.SNI_CONTAINER_DATA: [cert2.to_dict(), cert3.to_dict()],
  535             lib_consts.SNI_CONTAINER_REFS: [self.sni_container_ref_1,
  536                                             self.sni_container_ref_2],
  537             lib_consts.TIMEOUT_CLIENT_DATA: 1000,
  538             lib_consts.TIMEOUT_MEMBER_CONNECT: 2000,
  539             lib_consts.TIMEOUT_MEMBER_DATA: 3000,
  540             lib_consts.TIMEOUT_TCP_INSPECT: 4000,
  541             lib_consts.CLIENT_CA_TLS_CONTAINER_REF:
  542                 self.client_ca_tls_certificate_ref,
  543             lib_consts.CLIENT_CA_TLS_CONTAINER_DATA: ca_cert,
  544             lib_consts.CLIENT_AUTHENTICATION: constants.CLIENT_AUTH_NONE,
  545             lib_consts.CLIENT_CRL_CONTAINER_REF: self.client_crl_container_ref,
  546             lib_consts.CLIENT_CRL_CONTAINER_DATA: crl_file_content,
  547             lib_consts.TLS_CIPHERS: constants.CIPHERS_OWASP_SUITE_B,
  548             lib_consts.TLS_VERSIONS: constants.TLS_VERSIONS_OWASP_SUITE_B,
  549             lib_consts.ALPN_PROTOCOLS:
  550                 constants.AMPHORA_SUPPORTED_ALPN_PROTOCOLS
  551         }
  552 
  553         self.provider_listener2_dict = copy.deepcopy(
  554             self.provider_listener1_dict)
  555         self.provider_listener2_dict[
  556             lib_consts.LISTENER_ID] = self.listener2_id
  557         self.provider_listener2_dict[lib_consts.NAME] = 'listener_2'
  558         self.provider_listener2_dict[lib_consts.DESCRIPTION] = 'Listener 1'
  559         self.provider_listener2_dict[
  560             lib_consts.DEFAULT_POOL_ID] = self.pool2_id
  561         self.provider_listener2_dict[
  562             lib_consts.DEFAULT_POOL] = self.provider_pool2_dict
  563         del self.provider_listener2_dict[lib_consts.L7POLICIES]
  564         self.provider_listener2_dict[
  565             lib_consts.CLIENT_CA_TLS_CONTAINER_REF] = None
  566         del self.provider_listener2_dict[
  567             lib_consts.CLIENT_CA_TLS_CONTAINER_DATA]
  568         self.provider_listener2_dict[lib_consts.CLIENT_AUTHENTICATION] = (
  569             constants.CLIENT_AUTH_NONE)
  570         self.provider_listener2_dict[
  571             lib_consts.CLIENT_CRL_CONTAINER_REF] = None
  572         del self.provider_listener2_dict[lib_consts.CLIENT_CRL_CONTAINER_DATA]
  573 
  574         self.provider_listener1 = driver_dm.Listener(
  575             **self.provider_listener1_dict)
  576         self.provider_listener2 = driver_dm.Listener(
  577             **self.provider_listener2_dict)
  578         self.provider_listener1.default_pool = self.provider_pool1
  579         self.provider_listener2.default_pool = self.provider_pool2
  580         self.provider_listener1.l7policies = self.provider_l7policies
  581 
  582         self.provider_listeners = [self.provider_listener1,
  583                                    self.provider_listener2]
  584 
  585         self.test_vip_dict = {constants.IP_ADDRESS: self.ip_address,
  586                               constants.NETWORK_ID: self.network_id,
  587                               constants.PORT_ID: self.port_id,
  588                               lib_consts.SUBNET_ID: self.subnet_id,
  589                               constants.QOS_POLICY_ID: self.qos_policy_id,
  590                               constants.OCTAVIA_OWNED: None}
  591 
  592         self.provider_vip_dict = {
  593             lib_consts.VIP_ADDRESS: self.ip_address,
  594             lib_consts.VIP_NETWORK_ID: self.network_id,
  595             lib_consts.VIP_PORT_ID: self.port_id,
  596             lib_consts.VIP_SUBNET_ID: self.subnet_id,
  597             lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
  598             constants.OCTAVIA_OWNED: None}
  599 
  600         self.db_vip = data_models.Vip(
  601             ip_address=self.ip_address,
  602             network_id=self.network_id,
  603             port_id=self.port_id,
  604             subnet_id=self.subnet_id,
  605             qos_policy_id=self.qos_policy_id)
  606 
  607         self.test_loadbalancer1_dict = {
  608             lib_consts.NAME: self.lb_name,
  609             lib_consts.DESCRIPTION: self.lb_description,
  610             constants.ENABLED: True,
  611             lib_consts.PROVISIONING_STATUS: lib_consts.PENDING_UPDATE,
  612             lib_consts.OPERATING_STATUS: lib_consts.OFFLINE,
  613             constants.TOPOLOGY: constants.TOPOLOGY_ACTIVE_STANDBY,
  614             constants.VRRP_GROUP: None,
  615             constants.PROVIDER: constants.AMPHORA,
  616             constants.SERVER_GROUP_ID: uuidutils.generate_uuid(),
  617             lib_consts.PROJECT_ID: self.project_id,
  618             lib_consts.ID: self.lb_id, constants.FLAVOR_ID: self.flavor_id,
  619             constants.TAGS: ['test_tag']}
  620 
  621         self.provider_loadbalancer_dict = {
  622             lib_consts.ADDITIONAL_VIPS: None,
  623             lib_consts.ADMIN_STATE_UP: True,
  624             lib_consts.DESCRIPTION: self.lb_description,
  625             lib_consts.FLAVOR: {"something": "else"},
  626             lib_consts.LISTENERS: None,
  627             lib_consts.LOADBALANCER_ID: self.lb_id,
  628             lib_consts.NAME: self.lb_name,
  629             lib_consts.POOLS: None,
  630             lib_consts.PROJECT_ID: self.project_id,
  631             lib_consts.VIP_ADDRESS: self.ip_address,
  632             lib_consts.VIP_NETWORK_ID: self.network_id,
  633             lib_consts.VIP_PORT_ID: self.port_id,
  634             lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
  635             lib_consts.VIP_SUBNET_ID: self.subnet_id}
  636 
  637         self.provider_loadbalancer_tree_dict = {
  638             lib_consts.ADDITIONAL_VIPS: None,
  639             lib_consts.ADMIN_STATE_UP: True,
  640             lib_consts.AVAILABILITY_ZONE: None,
  641             lib_consts.DESCRIPTION: self.lb_description,
  642             lib_consts.FLAVOR: {"something": "else"},
  643             lib_consts.LISTENERS: None,
  644             lib_consts.LOADBALANCER_ID: self.lb_id,
  645             lib_consts.NAME: self.lb_name,
  646             lib_consts.POOLS: None,
  647             lib_consts.PROJECT_ID: self.project_id,
  648             lib_consts.VIP_ADDRESS: self.ip_address,
  649             lib_consts.VIP_NETWORK_ID: self.network_id,
  650             lib_consts.VIP_PORT_ID: self.port_id,
  651             lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
  652             lib_consts.VIP_SUBNET_ID: self.subnet_id}