def test_count_pool_children_for_quota(self):
        project_id = uuidutils.generate_uuid()
        member1 = data_models.Member(id=1, project_id=project_id)
        member2 = data_models.Member(id=2, project_id=project_id)
        healtmon = data_models.HealthMonitor(id=1, project_id=project_id)
        pool_no_children = data_models.Pool(id=1, project_id=project_id)
        pool_1_mem = data_models.Pool(id=1, project_id=project_id,
                                      members=[member1])
        pool_hm = data_models.Pool(id=1, project_id=project_id,
                                   health_monitor=healtmon)
        pool_hm_2_mem = data_models.Pool(id=1, project_id=project_id,
                                         health_monitor=healtmon,
                                         members=[member1, member2])
        task = database_tasks.CountPoolChildrenForQuota()

        # Test pool with no children
        result = task.execute(pool_no_children)

        self.assertEqual({'HM': 0, 'member': 0}, result)

        # Test pool with one member
        result = task.execute(pool_1_mem)

        self.assertEqual({'HM': 0, 'member': 1}, result)

        # Test pool with health monitor and no members
        result = task.execute(pool_hm)

        self.assertEqual({'HM': 1, 'member': 0}, result)

        # Test pool with health monitor and two members
        result = task.execute(pool_hm_2_mem)

        self.assertEqual({'HM': 1, 'member': 2}, result)
Esempio n. 2
0
 def test_update_pool(self):
     p = producer.PoolProducer()
     pool_model = data_models.Pool(id=10)
     pool_updates = pool.PoolPUT(enabled=False)
     p.update(pool_model, pool_updates)
     kw = {'pool_id': pool_model.id,
           'pool_updates': pool_updates.to_dict(render_unsets=False)}
     self.mck_client.cast.assert_called_once_with(
         {}, 'update_pool', **kw)
Esempio n. 3
0
 def test_create_pool_with_protocol_proxy(self):
     mock_pool = task.PoolCreate()
     mock_pool.axapi_client = self.client_mock
     mock_pool.CONF = self.conf
     pool = o_data_models.Pool(
         id=a10constants.MOCK_POOL_ID,
         protocol=o_constants.PROTOCOL_PROXY,
         lb_algorithm=o_constants.LB_ALGORITHM_SOURCE_IP)
     self.assertRaises(exceptions.ProviderUnsupportedOptionError,
                       mock_pool.execute, pool, VTHUNDER)
    def get_pool_octavia_model(self, pool_dict):
        pool = n_data_models.Pool.from_dict(
            copy.deepcopy(pool_dict)
        )
        ret = o_data_models.Pool()
        args = self._get_common_args(pool)
        # REVISIT(jiahao): In Mitaka, instead of pool.listener,
        # there are pool.listeners. We need to handle that
        if pool_dict.get('listener'):
            listener = self.get_listener_octavia_model(
                pool_dict.get('listener'))
            if pool.id not in [_pool.id for _pool in listener.pools]:
                listener.pools.append(ret)
            if (not listener.default_pool) \
                    or (listener.default_pool_id == pool.id):
                listener.default_pool = ret
            listeners = [listener]
            args.update({
                'listeners': listeners,
            })
            if listener.load_balancer:
                if pool.id not in [_pool.id for _pool
                                   in listener.load_balancer.pools]:
                    listener.load_balancer.pools.append(ret)
                args.update({
                    'load_balancer': listener.load_balancer,
                    'load_balancer_id': listener.load_balancer_id,
                })
        if pool_dict.get('members'):
            members = []
            for member_dict in pool_dict.get('members'):
                member = self.get_member_octavia_model(member_dict)
                if not member.pool:
                    member.pool = ret
                members.append(member)
            args.update({
                'members': members
            })
        if pool_dict.get('healthmonitor'):
            healthmonitor = self.get_healthmonitor_octavia_model(
                pool_dict.get('healthmonitor'))
            if not healthmonitor.pool:
                healthmonitor.pool = ret
            args.update({
                'health_monitor': healthmonitor
            })

        # REVISIT(jiahao): L7Policy are not added
        args.update({
            'protocol': pool.protocol,
            'lb_algorithm': pool.lb_algorithm,
            'session_persistence': pool.session_persistence,
        })
        ret = self._update(ret, args)
        return ret
Esempio n. 5
0
    def test_Pool_update(self):

        new_id = uuidutils.generate_uuid()
        new_project_id = uuidutils.generate_uuid()
        new_name = 'new-test-pool'
        new_description = 'new-test-pool-description'
        new_lb_id = uuidutils.generate_uuid()
        new_protocol = 'sneaker'
        new_lb_algorithm = 'JustOne'
        new_enabled = False
        new_provisioning_status = 'new-great'
        new_operating_status = 'new-even-better'
        new_created_at = self.CREATED_AT + datetime.timedelta(minutes=5)
        new_updated_at = self.UPDATED_AT + datetime.timedelta(minutes=10)

        reference_Pool_obj = data_models.Pool(
            id=new_id,
            project_id=new_project_id,
            name=new_name,
            description=new_description,
            load_balancer_id=new_lb_id,
            protocol=new_protocol,
            lb_algorithm=new_lb_algorithm,
            enabled=new_enabled,
            provisioning_status=new_provisioning_status,
            operating_status=new_operating_status,
            members=[],
            health_monitor=None,
            session_persistence=None,
            listeners=[],
            l7policies=[],
            created_at=new_created_at,
            updated_at=new_updated_at)

        update_dict = {
            'id': new_id,
            'project_id': new_project_id,
            'name': new_name,
            'description': new_description,
            'load_balancer_id': new_lb_id,
            'protocol': new_protocol,
            'lb_algorithm': new_lb_algorithm,
            'enabled': new_enabled,
            'provisioning_status': new_provisioning_status,
            'operating_status': new_operating_status,
            'created_at': new_created_at,
            'updated_at': new_updated_at
        }

        test_Pool_obj = copy.deepcopy(self.POOL_obj)

        test_Pool_obj.update(update_dict)

        self.assertEqual(reference_Pool_obj, test_Pool_obj)
 def test_create_lb_algorithm_source_ip_hash_only(self):
     mock_pool = task.PoolCreate()
     mock_pool.axapi_client = self.client_mock
     mock_pool.CONF = self.conf
     pool = o_data_models.Pool(
         id=a10constants.MOCK_POOL_ID,
         protocol=o_constants.PROTOCOL_HTTP,
         lb_algorithm=o_constants.LB_ALGORITHM_SOURCE_IP)
     mock_pool.execute(pool, VTHUNDER)
     self.client_mock.slb.service_group.create.assert_called_with(
         a10constants.MOCK_POOL_ID,
         protocol=mock.ANY,
         lb_method=mock_pool.axapi_client.slb.service_group.
         SOURCE_IP_HASH_ONLY,
         service_group_templates=mock.ANY,
         axapi_args=AXAPI_ARGS)
Esempio n. 7
0
    def test_count_pool_children_for_quota(self, repo_mock, session_mock):
        project_id = uuidutils.generate_uuid()
        pool = data_models.Pool(id=1, project_id=project_id)

        task = database_tasks.CountPoolChildrenForQuota()

        # Test pool with no children
        repo_mock.reset_mock()
        repo_mock.return_value = (0, 0)
        result = task.execute(pool.id)

        self.assertEqual({'HM': 0, 'member': 0}, result)

        # Test pool with health monitor and two members
        repo_mock.reset_mock()
        repo_mock.return_value = (1, 2)
        result = task.execute(pool.id)

        self.assertEqual({'HM': 1, 'member': 2}, result)
Esempio n. 8
0
 def test_update_health_no_status_change(self):
     health = {
         "id": self.FAKE_UUID_1,
         "listeners": {
             "listener-id-1": {
                 "status": constants.OPEN,
                 "pools": {
                     "pool-id-1": {
                         "status": constants.UP,
                         "members": {
                             "member-id-1": constants.UP
                         }
                     }
                 }
             }
         }
     }
     db_lb = data_models.LoadBalancer(id=self.FAKE_UUID_1,
                                      operating_status=constants.ONLINE)
     db_listener = data_models.Listener(id='listener-id-',
                                        operating_status=constants.ONLINE,
                                        load_balancer_id=self.FAKE_UUID_1)
     db_pool = data_models.Pool(id='pool-id-1',
                                operating_status=constants.ONLINE)
     db_member = data_models.Member(id='member-id-1',
                                    operating_status=constants.ONLINE)
     self.listener_repo.get.return_value = db_listener
     self.pool_repo.get.return_value = db_pool
     self.member_repo.get.return_value = db_member
     self.loadbalancer_repo.get.return_value = db_lb
     self.hm.update_health(health)
     self.event_client.cast.assert_not_called()
     self.loadbalancer_repo.update.assert_not_called()
     self.listener_repo.update.assert_not_called()
     self.pool_repo.update.assert_not_called()
     self.member_repo.update.assert_not_called()
Esempio n. 9
0
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture

from octavia.common import data_models as o_data_models
from octavia.tests.common import constants as t_constants

from a10_octavia.common import config_options
from a10_octavia.common import data_models
import a10_octavia.controller.worker.tasks.server_tasks as task
from a10_octavia.controller.worker.tasks import utils
from a10_octavia.tests.common import a10constants
from a10_octavia.tests.unit import base

VTHUNDER = data_models.VThunder()
POOL = o_data_models.Pool(id=a10constants.MOCK_POOL_ID,
                          protocol=a10constants.MOCK_SERVICE_GROUP_PROTOCOL)
MEMBER = o_data_models.Member(
    id=a10constants.MOCK_MEMBER_ID, protocol_port=t_constants.MOCK_PORT_ID,
    project_id=t_constants.MOCK_PROJECT_ID, ip_address=t_constants.MOCK_IP_ADDRESS,
    subnet_id=a10constants.MOCK_SUBNET_ID)

KEY_ARGS = {'server': utils.meta(MEMBER, 'server', {'conn_resume': None, 'conn_limit': 64000000})}
SERVER_NAME = '{}_{}'.format(MEMBER.project_id[:5],
                             MEMBER.ip_address.replace('.', '_'))


class TestHandlerServerTasks(base.BaseTaskTestCase):

    def setUp(self):
        super(TestHandlerServerTasks, self).setUp()
        imp.reload(task)
Esempio n. 10
0
    def __init__(self):
        self.project_id = uuidutils.generate_uuid()
        self.lb_id = uuidutils.generate_uuid()
        self.ip_address = '192.0.2.30'
        self.port_id = uuidutils.generate_uuid()
        self.network_id = uuidutils.generate_uuid()
        self.subnet_id = uuidutils.generate_uuid()
        self.qos_policy_id = uuidutils.generate_uuid()

        self.listener1_id = uuidutils.generate_uuid()
        self.listener2_id = uuidutils.generate_uuid()
        self.default_tls_container_ref = uuidutils.generate_uuid()
        self.sni_container_ref_1 = uuidutils.generate_uuid()
        self.sni_container_ref_2 = uuidutils.generate_uuid()
        self.client_ca_tls_certificate_ref = uuidutils.generate_uuid()
        self.client_crl_container_ref = uuidutils.generate_uuid()
        self.pool_sni_container_ref = uuidutils.generate_uuid()
        self.pool_ca_container_ref = uuidutils.generate_uuid()
        self.pool_crl_container_ref = uuidutils.generate_uuid()

        self.pool1_id = uuidutils.generate_uuid()
        self.pool2_id = uuidutils.generate_uuid()

        self.hm1_id = uuidutils.generate_uuid()
        self.hm2_id = uuidutils.generate_uuid()

        self.member1_id = uuidutils.generate_uuid()
        self.member2_id = uuidutils.generate_uuid()
        self.member3_id = uuidutils.generate_uuid()
        self.member4_id = uuidutils.generate_uuid()

        self.l7policy1_id = uuidutils.generate_uuid()
        self.l7policy2_id = uuidutils.generate_uuid()

        self.l7rule1_id = uuidutils.generate_uuid()
        self.l7rule2_id = uuidutils.generate_uuid()

        self._common_test_dict = {
            'provisioning_status': constants.ACTIVE,
            'operating_status': constants.ONLINE,
            'project_id': self.project_id,
            'created_at': 'then',
            'updated_at': 'now',
            'enabled': True
        }

        # Setup Health Monitors
        self.test_hm1_dict = {
            'id': self.hm1_id,
            'type': constants.HEALTH_MONITOR_PING,
            'delay': 1,
            'timeout': 3,
            'fall_threshold': 1,
            'rise_threshold': 2,
            'http_method': 'GET',
            'url_path': '/',
            'expected_codes': '200',
            'name': 'hm1',
            'pool_id': self.pool1_id,
            'http_version': 1.0,
            'domain_name': None,
            'project_id': self.project_id
        }

        self.test_hm1_dict.update(self._common_test_dict)

        self.test_hm2_dict = copy.deepcopy(self.test_hm1_dict)
        self.test_hm2_dict['id'] = self.hm2_id
        self.test_hm2_dict['name'] = 'hm2'
        self.test_hm2_dict.update({
            'http_version': 1.1,
            'domain_name': 'testdomainname.com'
        })

        self.db_hm1 = data_models.HealthMonitor(**self.test_hm1_dict)
        self.db_hm2 = data_models.HealthMonitor(**self.test_hm2_dict)

        self.provider_hm1_dict = {
            'admin_state_up': True,
            'delay': 1,
            'expected_codes': '200',
            'healthmonitor_id': self.hm1_id,
            'http_method': 'GET',
            'max_retries': 2,
            'max_retries_down': 1,
            'name': 'hm1',
            'pool_id': self.pool1_id,
            'project_id': self.project_id,
            'timeout': 3,
            'type': constants.HEALTH_MONITOR_PING,
            'url_path': '/',
            'http_version': 1.0,
            'domain_name': None
        }

        self.provider_hm2_dict = copy.deepcopy(self.provider_hm1_dict)
        self.provider_hm2_dict['healthmonitor_id'] = self.hm2_id
        self.provider_hm2_dict['name'] = 'hm2'
        self.provider_hm2_dict.update({
            'http_version': 1.1,
            'domain_name': 'testdomainname.com'
        })

        self.provider_hm1 = driver_dm.HealthMonitor(**self.provider_hm1_dict)
        self.provider_hm2 = driver_dm.HealthMonitor(**self.provider_hm2_dict)

        # Setup Members
        self.test_member1_dict = {
            'id': self.member1_id,
            'pool_id': self.pool1_id,
            'ip_address': '192.0.2.16',
            'protocol_port': 80,
            'weight': 0,
            'backup': False,
            'subnet_id': self.subnet_id,
            'pool': None,
            'project_id': self.project_id,
            'name': 'member1',
            'monitor_address': '192.0.2.26',
            'monitor_port': 81
        }

        self.test_member1_dict.update(self._common_test_dict)

        self.test_member2_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member2_dict['id'] = self.member2_id
        self.test_member2_dict['ip_address'] = '192.0.2.17'
        self.test_member2_dict['monitor_address'] = '192.0.2.27'
        self.test_member2_dict['name'] = 'member2'

        self.test_member3_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member3_dict['id'] = self.member3_id
        self.test_member3_dict['ip_address'] = '192.0.2.18'
        self.test_member3_dict['monitor_address'] = '192.0.2.28'
        self.test_member3_dict['name'] = 'member3'
        self.test_member3_dict['pool_id'] = self.pool2_id

        self.test_member4_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member4_dict['id'] = self.member4_id
        self.test_member4_dict['ip_address'] = '192.0.2.19'
        self.test_member4_dict['monitor_address'] = '192.0.2.29'
        self.test_member4_dict['name'] = 'member4'
        self.test_member4_dict['pool_id'] = self.pool2_id

        self.test_pool1_members_dict = [
            self.test_member1_dict, self.test_member2_dict
        ]
        self.test_pool2_members_dict = [
            self.test_member3_dict, self.test_member4_dict
        ]

        self.db_member1 = data_models.Member(**self.test_member1_dict)
        self.db_member2 = data_models.Member(**self.test_member2_dict)
        self.db_member3 = data_models.Member(**self.test_member3_dict)
        self.db_member4 = data_models.Member(**self.test_member4_dict)

        self.db_pool1_members = [self.db_member1, self.db_member2]
        self.db_pool2_members = [self.db_member3, self.db_member4]

        self.provider_member1_dict = {
            'address': '192.0.2.16',
            'admin_state_up': True,
            'member_id': self.member1_id,
            'monitor_address': '192.0.2.26',
            'monitor_port': 81,
            'name': 'member1',
            'pool_id': self.pool1_id,
            'project_id': self.project_id,
            'protocol_port': 80,
            'subnet_id': self.subnet_id,
            'weight': 0,
            'backup': False
        }

        self.provider_member2_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member2_dict['member_id'] = self.member2_id
        self.provider_member2_dict['address'] = '192.0.2.17'
        self.provider_member2_dict['monitor_address'] = '192.0.2.27'
        self.provider_member2_dict['name'] = 'member2'

        self.provider_member3_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member3_dict['member_id'] = self.member3_id
        self.provider_member3_dict['address'] = '192.0.2.18'
        self.provider_member3_dict['monitor_address'] = '192.0.2.28'
        self.provider_member3_dict['name'] = 'member3'
        self.provider_member3_dict['pool_id'] = self.pool2_id

        self.provider_member4_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member4_dict['member_id'] = self.member4_id
        self.provider_member4_dict['address'] = '192.0.2.19'
        self.provider_member4_dict['monitor_address'] = '192.0.2.29'
        self.provider_member4_dict['name'] = 'member4'
        self.provider_member4_dict['pool_id'] = self.pool2_id

        self.provider_pool1_members_dict = [
            self.provider_member1_dict, self.provider_member2_dict
        ]

        self.provider_pool2_members_dict = [
            self.provider_member3_dict, self.provider_member4_dict
        ]

        self.provider_member1 = driver_dm.Member(**self.provider_member1_dict)
        self.provider_member2 = driver_dm.Member(**self.provider_member2_dict)
        self.provider_member3 = driver_dm.Member(**self.provider_member3_dict)
        self.provider_member4 = driver_dm.Member(**self.provider_member4_dict)

        self.provider_pool1_members = [
            self.provider_member1, self.provider_member2
        ]
        self.provider_pool2_members = [
            self.provider_member3, self.provider_member4
        ]

        # Setup test pools
        self.test_pool1_dict = {
            'id': self.pool1_id,
            'name': 'pool1',
            'description': 'Pool 1',
            'load_balancer_id': self.lb_id,
            'project_id': self.project_id,
            'protocol': 'avian',
            'lb_algorithm': 'round_robin',
            'members': self.test_pool1_members_dict,
            'health_monitor': self.test_hm1_dict,
            'session_persistence': {
                'type': 'SOURCE'
            },
            'listeners': [],
            'l7policies': [],
            'tls_certificate_id': self.pool_sni_container_ref,
            'ca_tls_certificate_id': self.pool_ca_container_ref,
            'crl_container_id': self.pool_crl_container_ref,
            'tls_enabled': True
        }

        self.test_pool1_dict.update(self._common_test_dict)

        self.test_pool2_dict = copy.deepcopy(self.test_pool1_dict)
        self.test_pool2_dict['id'] = self.pool2_id
        self.test_pool2_dict['name'] = 'pool2'
        self.test_pool2_dict['description'] = 'Pool 2'
        self.test_pool2_dict['members'] = self.test_pool2_members_dict
        del self.test_pool2_dict['tls_certificate_id']
        del self.test_pool2_dict['ca_tls_certificate_id']
        del self.test_pool2_dict['crl_container_id']

        self.test_pools = [self.test_pool1_dict, self.test_pool2_dict]

        self.db_pool1 = data_models.Pool(**self.test_pool1_dict)
        self.db_pool1.health_monitor = self.db_hm1
        self.db_pool1.members = self.db_pool1_members
        self.db_pool2 = data_models.Pool(**self.test_pool2_dict)
        self.db_pool2.health_monitor = self.db_hm2
        self.db_pool2.members = self.db_pool2_members

        self.test_db_pools = [self.db_pool1, self.db_pool2]
        pool_cert = data_models.TLSContainer(certificate='pool cert')
        pool_ca_file_content = 'X509 POOL CA CERT FILE'
        pool_crl_file_content = 'X509 POOL CRL FILE'

        self.provider_pool1_dict = {
            'admin_state_up': True,
            'description': 'Pool 1',
            'healthmonitor': self.provider_hm1_dict,
            'lb_algorithm': 'round_robin',
            'loadbalancer_id': self.lb_id,
            'members': self.provider_pool1_members_dict,
            'name': 'pool1',
            'pool_id': self.pool1_id,
            'project_id': self.project_id,
            'protocol': 'avian',
            'session_persistence': {
                'type': 'SOURCE'
            },
            'tls_container_ref': self.pool_sni_container_ref,
            'tls_container_data': pool_cert.to_dict(),
            'ca_tls_container_ref': self.pool_ca_container_ref,
            'ca_tls_container_data': pool_ca_file_content,
            'crl_container_ref': self.pool_crl_container_ref,
            'crl_container_data': pool_crl_file_content,
            'tls_enabled': True
        }

        self.provider_pool2_dict = copy.deepcopy(self.provider_pool1_dict)
        self.provider_pool2_dict['pool_id'] = self.pool2_id
        self.provider_pool2_dict['name'] = 'pool2'
        self.provider_pool2_dict['description'] = 'Pool 2'
        self.provider_pool2_dict['members'] = self.provider_pool2_members_dict
        self.provider_pool2_dict['healthmonitor'] = self.provider_hm2_dict
        self.provider_pool2_dict['tls_container_ref'] = None
        del self.provider_pool2_dict['tls_container_data']
        self.provider_pool2_dict['ca_tls_container_ref'] = None
        del self.provider_pool2_dict['ca_tls_container_data']
        self.provider_pool2_dict['crl_container_ref'] = None
        del self.provider_pool2_dict['crl_container_data']

        self.provider_pool1 = driver_dm.Pool(**self.provider_pool1_dict)
        self.provider_pool1.members = self.provider_pool1_members
        self.provider_pool1.healthmonitor = self.provider_hm1
        self.provider_pool2 = driver_dm.Pool(**self.provider_pool2_dict)
        self.provider_pool2.members = self.provider_pool2_members
        self.provider_pool2.healthmonitor = self.provider_hm2

        self.provider_pools = [self.provider_pool1, self.provider_pool2]

        # Setup L7Rules
        self.test_l7rule1_dict = {
            'id': self.l7rule1_id,
            'l7policy_id': self.l7policy1_id,
            'type': 'o',
            'compare_type': 'fake_type',
            'key': 'fake_key',
            'value': 'fake_value',
            'project_id': self.project_id,
            'l7policy': None,
            'invert': False
        }

        self.test_l7rule1_dict.update(self._common_test_dict)

        self.test_l7rule2_dict = copy.deepcopy(self.test_l7rule1_dict)
        self.test_l7rule2_dict['id'] = self.l7rule2_id

        self.test_l7rules = [self.test_l7rule1_dict, self.test_l7rule2_dict]

        self.db_l7Rule1 = data_models.L7Rule(**self.test_l7rule1_dict)
        self.db_l7Rule2 = data_models.L7Rule(**self.test_l7rule2_dict)

        self.db_l7Rules = [self.db_l7Rule1, self.db_l7Rule2]

        self.provider_l7rule1_dict = {
            'admin_state_up': True,
            'compare_type': 'fake_type',
            'invert': False,
            'key': 'fake_key',
            'l7policy_id': self.l7policy1_id,
            'l7rule_id': self.l7rule1_id,
            'type': 'o',
            'project_id': self.project_id,
            'value': 'fake_value'
        }

        self.provider_l7rule2_dict = copy.deepcopy(self.provider_l7rule1_dict)
        self.provider_l7rule2_dict['l7rule_id'] = self.l7rule2_id
        self.provider_l7rules_dicts = [
            self.provider_l7rule1_dict, self.provider_l7rule2_dict
        ]

        self.provider_l7rule1 = driver_dm.L7Rule(**self.provider_l7rule1_dict)
        self.provider_l7rule2 = driver_dm.L7Rule(**self.provider_l7rule2_dict)

        self.provider_rules = [self.provider_l7rule1, self.provider_l7rule2]

        # Setup L7Policies
        self.test_l7policy1_dict = {
            'id': self.l7policy1_id,
            'name': 'l7policy_1',
            'description': 'L7policy 1',
            'listener_id': self.listener1_id,
            'action': 'go',
            'redirect_pool_id': self.pool1_id,
            'redirect_url': '/index.html',
            'redirect_prefix': 'https://example.com/',
            'project_id': self.project_id,
            'position': 1,
            'listener': None,
            'redirect_pool': None,
            'l7rules': self.test_l7rules,
            'redirect_http_code': 302
        }

        self.test_l7policy1_dict.update(self._common_test_dict)

        self.test_l7policy2_dict = copy.deepcopy(self.test_l7policy1_dict)
        self.test_l7policy2_dict['id'] = self.l7policy2_id
        self.test_l7policy2_dict['name'] = 'l7policy_2'
        self.test_l7policy2_dict['description'] = 'L7policy 2'

        self.test_l7policies = [
            self.test_l7policy1_dict, self.test_l7policy2_dict
        ]

        self.db_l7policy1 = data_models.L7Policy(**self.test_l7policy1_dict)
        self.db_l7policy2 = data_models.L7Policy(**self.test_l7policy2_dict)
        self.db_l7policy1.l7rules = self.db_l7Rules
        self.db_l7policy2.l7rules = self.db_l7Rules

        self.db_l7policies = [self.db_l7policy1, self.db_l7policy2]

        self.provider_l7policy1_dict = {
            'action': 'go',
            'admin_state_up': True,
            'description': 'L7policy 1',
            'l7policy_id': self.l7policy1_id,
            'listener_id': self.listener1_id,
            'name': 'l7policy_1',
            'position': 1,
            'project_id': self.project_id,
            'redirect_pool_id': self.pool1_id,
            'redirect_url': '/index.html',
            'redirect_prefix': 'https://example.com/',
            'rules': self.provider_l7rules_dicts,
            'redirect_http_code': 302
        }

        self.provider_l7policy2_dict = copy.deepcopy(
            self.provider_l7policy1_dict)
        self.provider_l7policy2_dict['l7policy_id'] = self.l7policy2_id
        self.provider_l7policy2_dict['name'] = 'l7policy_2'
        self.provider_l7policy2_dict['description'] = 'L7policy 2'

        self.provider_l7policies_dict = [
            self.provider_l7policy1_dict, self.provider_l7policy2_dict
        ]

        self.provider_l7policy1 = driver_dm.L7Policy(
            **self.provider_l7policy1_dict)
        self.provider_l7policy1.rules = self.provider_rules
        self.provider_l7policy2 = driver_dm.L7Policy(
            **self.provider_l7policy2_dict)
        self.provider_l7policy2.rules = self.provider_rules

        self.provider_l7policies = [
            self.provider_l7policy1, self.provider_l7policy2
        ]

        # Setup Listeners
        self.test_listener1_dict = {
            'id': self.listener1_id,
            'name': 'listener_1',
            'description': 'Listener 1',
            'default_pool_id': self.pool1_id,
            'load_balancer_id': self.lb_id,
            'project_id': self.project_id,
            'protocol': 'avian',
            'protocol_port': 90,
            'connection_limit': 10000,
            'tls_certificate_id': self.default_tls_container_ref,
            'stats': None,
            'default_pool': self.test_pool1_dict,
            'load_balancer': None,
            'sni_containers':
            [self.sni_container_ref_1, self.sni_container_ref_2],
            'peer_port': 55,
            'l7policies': self.test_l7policies,
            'insert_headers': {},
            'pools': None,
            'timeout_client_data': 1000,
            'timeout_member_connect': 2000,
            'timeout_member_data': 3000,
            'timeout_tcp_inspect': 4000,
            'client_ca_tls_certificate_id': self.client_ca_tls_certificate_ref,
            'client_authentication': constants.CLIENT_AUTH_NONE,
            'client_crl_container_id': self.client_crl_container_ref
        }

        self.test_listener1_dict.update(self._common_test_dict)

        self.test_listener2_dict = copy.deepcopy(self.test_listener1_dict)
        self.test_listener2_dict['id'] = self.listener2_id
        self.test_listener2_dict['name'] = 'listener_2'
        self.test_listener2_dict['description'] = 'Listener 1'
        self.test_listener2_dict['default_pool_id'] = self.pool2_id
        self.test_listener2_dict['default_pool'] = self.test_pool2_dict
        del self.test_listener2_dict['l7policies']
        del self.test_listener2_dict['sni_containers']
        del self.test_listener2_dict['client_ca_tls_certificate_id']
        del self.test_listener2_dict['client_crl_container_id']

        self.test_listeners = [
            self.test_listener1_dict, self.test_listener2_dict
        ]

        self.db_listener1 = data_models.Listener(**self.test_listener1_dict)
        self.db_listener2 = data_models.Listener(**self.test_listener2_dict)
        self.db_listener1.default_pool = self.db_pool1
        self.db_listener2.default_pool = self.db_pool2
        self.db_listener1.l7policies = self.db_l7policies
        self.db_listener1.sni_containers = [
            data_models.SNI(tls_container_id='2'),
            data_models.SNI(tls_container_id='3')
        ]

        self.test_db_listeners = [self.db_listener1, self.db_listener2]

        cert1 = data_models.TLSContainer(certificate='cert 1')
        cert2 = data_models.TLSContainer(certificate='cert 2')
        cert3 = data_models.TLSContainer(certificate='cert 3')
        ca_cert = 'ca cert'
        crl_file_content = 'X509 CRL FILE'

        self.provider_listener1_dict = {
            'admin_state_up':
            True,
            'connection_limit':
            10000,
            'default_pool':
            self.provider_pool1_dict,
            'default_pool_id':
            self.pool1_id,
            'default_tls_container_data':
            cert1.to_dict(),
            'default_tls_container_ref':
            self.default_tls_container_ref,
            'description':
            'Listener 1',
            'insert_headers': {},
            'l7policies':
            self.provider_l7policies_dict,
            'listener_id':
            self.listener1_id,
            'loadbalancer_id':
            self.lb_id,
            'name':
            'listener_1',
            'project_id':
            self.project_id,
            'protocol':
            'avian',
            'protocol_port':
            90,
            'sni_container_data': [cert2.to_dict(),
                                   cert3.to_dict()],
            'sni_container_refs':
            [self.sni_container_ref_1, self.sni_container_ref_2],
            'timeout_client_data':
            1000,
            'timeout_member_connect':
            2000,
            'timeout_member_data':
            3000,
            'timeout_tcp_inspect':
            4000,
            'client_ca_tls_container_ref':
            self.client_ca_tls_certificate_ref,
            'client_ca_tls_container_data':
            ca_cert,
            'client_authentication':
            constants.CLIENT_AUTH_NONE,
            'client_crl_container_ref':
            self.client_crl_container_ref,
            'client_crl_container_data':
            crl_file_content
        }

        self.provider_listener2_dict = copy.deepcopy(
            self.provider_listener1_dict)
        self.provider_listener2_dict['listener_id'] = self.listener2_id
        self.provider_listener2_dict['name'] = 'listener_2'
        self.provider_listener2_dict['description'] = 'Listener 1'
        self.provider_listener2_dict['default_pool_id'] = self.pool2_id
        self.provider_listener2_dict['default_pool'] = self.provider_pool2_dict
        del self.provider_listener2_dict['l7policies']
        self.provider_listener2_dict['client_ca_tls_container_ref'] = None
        del self.provider_listener2_dict['client_ca_tls_container_data']
        self.provider_listener2_dict['client_authentication'] = (
            constants.CLIENT_AUTH_NONE)
        self.provider_listener2_dict['client_crl_container_ref'] = None
        del self.provider_listener2_dict['client_crl_container_data']

        self.provider_listener1 = driver_dm.Listener(
            **self.provider_listener1_dict)
        self.provider_listener2 = driver_dm.Listener(
            **self.provider_listener2_dict)
        self.provider_listener1.default_pool = self.provider_pool1
        self.provider_listener2.default_pool = self.provider_pool2
        self.provider_listener1.l7policies = self.provider_l7policies

        self.provider_listeners = [
            self.provider_listener1, self.provider_listener2
        ]

        self.test_vip_dict = {
            'ip_address': self.ip_address,
            'network_id': self.network_id,
            'port_id': self.port_id,
            'subnet_id': self.subnet_id,
            'qos_policy_id': self.qos_policy_id
        }

        self.provider_vip_dict = {
            'vip_address': self.ip_address,
            'vip_network_id': self.network_id,
            'vip_port_id': self.port_id,
            'vip_subnet_id': self.subnet_id,
            'vip_qos_policy_id': self.qos_policy_id
        }

        self.db_vip = data_models.Vip(ip_address=self.ip_address,
                                      network_id=self.network_id,
                                      port_id=self.port_id,
                                      subnet_id=self.subnet_id,
                                      qos_policy_id=self.qos_policy_id)
Esempio n. 11
0
    def setUp(self):

        self.LB_ID = uuidutils.generate_uuid()
        self.PROJECT_ID = uuidutils.generate_uuid()
        self.SERVER_GROUP_ID = uuidutils.generate_uuid()
        self.CREATED_AT = datetime.datetime.now()
        self.UPDATED_AT = datetime.datetime.utcnow()
        self.VIP_IP = '192.0.2.10'
        self.VIP_SUBNET_ID = uuidutils.generate_uuid()
        self.VIP_NETWORK_ID = uuidutils.generate_uuid()
        self.VIP_PORT_ID = uuidutils.generate_uuid()
        self.VIP_QOS_ID = uuidutils.generate_uuid()
        self.POOL_ID = uuidutils.generate_uuid()

        self.LB_obj = data_models.LoadBalancer(
            id=self.LB_ID,
            project_id=self.PROJECT_ID,
            name='test-lb',
            description='test-lb-description',
            provisioning_status='great',
            operating_status='even-better',
            enabled=True,
            vip=None,
            vrrp_group=1,
            topology='infinite',
            listeners=[],
            amphorae=[],
            pools=[],
            server_group_id=self.SERVER_GROUP_ID,
            created_at=self.CREATED_AT,
            updated_at=self.UPDATED_AT)

        self.VIP_obj = data_models.Vip(
            load_balancer_id=self.LB_ID,
            ip_address=self.VIP_IP,
            subnet_id=self.VIP_SUBNET_ID,
            network_id=self.VIP_NETWORK_ID,
            port_id=self.VIP_PORT_ID,
            qos_policy_id=self.VIP_QOS_ID)

        self.POOL_obj = data_models.Pool(
            id=self.POOL_ID,
            project_id=self.PROJECT_ID,
            name='test-pool',
            description='test-pool-description',
            load_balancer_id=self.LB_ID,
            load_balancer=None,
            protocol='avian',
            lb_algorithm='UseAllofThem',
            enabled=True,
            provisioning_status='great',
            operating_status='even-better',
            members=[],
            health_monitor=None,
            session_persistence=None,
            listeners=[],
            l7policies=[],
            created_at=self.CREATED_AT,
            updated_at=self.UPDATED_AT)

        self.SP_obj = data_models.SessionPersistence(
            pool_id=self.POOL_ID,
            type='adhesive',
            cookie_name='chocolate',
            pool=None)

        super(TestDataModels, self).setUp()
Esempio n. 12
0
    def __init__(self):
        self.project_id = uuidutils.generate_uuid()
        self.lb_id = uuidutils.generate_uuid()
        self.ip_address = '192.0.2.30'
        self.port_id = uuidutils.generate_uuid()
        self.network_id = uuidutils.generate_uuid()
        self.subnet_id = uuidutils.generate_uuid()
        self.qos_policy_id = uuidutils.generate_uuid()
        self.lb_name = uuidutils.generate_uuid()
        self.lb_description = uuidutils.generate_uuid()
        self.flavor_id = uuidutils.generate_uuid()
        self.flavor_profile_id = uuidutils.generate_uuid()

        self.listener1_id = uuidutils.generate_uuid()
        self.listener2_id = uuidutils.generate_uuid()
        self.default_tls_container_ref = uuidutils.generate_uuid()
        self.sni_container_ref_1 = uuidutils.generate_uuid()
        self.sni_container_ref_2 = uuidutils.generate_uuid()
        self.client_ca_tls_certificate_ref = uuidutils.generate_uuid()
        self.client_crl_container_ref = uuidutils.generate_uuid()
        self.pool_sni_container_ref = uuidutils.generate_uuid()
        self.pool_ca_container_ref = uuidutils.generate_uuid()
        self.pool_crl_container_ref = uuidutils.generate_uuid()

        self.pool1_id = uuidutils.generate_uuid()
        self.pool2_id = uuidutils.generate_uuid()

        self.hm1_id = uuidutils.generate_uuid()
        self.hm2_id = uuidutils.generate_uuid()

        self.member1_id = uuidutils.generate_uuid()
        self.member2_id = uuidutils.generate_uuid()
        self.member3_id = uuidutils.generate_uuid()
        self.member4_id = uuidutils.generate_uuid()

        self.l7policy1_id = uuidutils.generate_uuid()
        self.l7policy2_id = uuidutils.generate_uuid()

        self.l7rule1_id = uuidutils.generate_uuid()
        self.l7rule2_id = uuidutils.generate_uuid()

        self.created_at = datetime.datetime.now()
        self.updated_at = (datetime.datetime.now() +
                           datetime.timedelta(minutes=1))

        self._common_test_dict = {
            lib_consts.PROVISIONING_STATUS: constants.ACTIVE,
            lib_consts.OPERATING_STATUS: constants.ONLINE,
            lib_consts.PROJECT_ID: self.project_id,
            constants.CREATED_AT: self.created_at,
            constants.UPDATED_AT: self.updated_at,
            constants.ENABLED: True
        }

        # Setup Health Monitors
        self.test_hm1_dict = {
            lib_consts.ID: self.hm1_id,
            lib_consts.TYPE: constants.HEALTH_MONITOR_PING,
            lib_consts.DELAY: 1,
            lib_consts.TIMEOUT: 3,
            lib_consts.FALL_THRESHOLD: 1,
            lib_consts.RISE_THRESHOLD: 2,
            lib_consts.HTTP_METHOD: lib_consts.HEALTH_MONITOR_HTTP_METHOD_GET,
            lib_consts.URL_PATH: '/',
            lib_consts.EXPECTED_CODES: '200',
            lib_consts.NAME: 'hm1',
            lib_consts.POOL_ID: self.pool1_id,
            lib_consts.HTTP_VERSION: 1.0,
            lib_consts.DOMAIN_NAME: None,
            lib_consts.PROJECT_ID: self.project_id
        }

        self.test_hm1_dict.update(self._common_test_dict)

        self.test_hm2_dict = copy.deepcopy(self.test_hm1_dict)
        self.test_hm2_dict[lib_consts.ID] = self.hm2_id
        self.test_hm2_dict[lib_consts.NAME] = 'hm2'
        self.test_hm2_dict.update({
            lib_consts.HTTP_VERSION: 1.1,
            lib_consts.DOMAIN_NAME: 'testdomainname.com'
        })

        self.db_hm1 = data_models.HealthMonitor(**self.test_hm1_dict)
        self.db_hm2 = data_models.HealthMonitor(**self.test_hm2_dict)

        self.provider_hm1_dict = {
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.DELAY: 1,
            lib_consts.EXPECTED_CODES: '200',
            lib_consts.HEALTHMONITOR_ID: self.hm1_id,
            lib_consts.HTTP_METHOD: lib_consts.HEALTH_MONITOR_HTTP_METHOD_GET,
            lib_consts.MAX_RETRIES: 2,
            lib_consts.MAX_RETRIES_DOWN: 1,
            lib_consts.NAME: 'hm1',
            lib_consts.POOL_ID: self.pool1_id,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.TIMEOUT: 3,
            lib_consts.TYPE: constants.HEALTH_MONITOR_PING,
            lib_consts.URL_PATH: '/',
            lib_consts.HTTP_VERSION: 1.0,
            lib_consts.DOMAIN_NAME: None
        }

        self.provider_hm2_dict = copy.deepcopy(self.provider_hm1_dict)
        self.provider_hm2_dict[lib_consts.HEALTHMONITOR_ID] = self.hm2_id
        self.provider_hm2_dict[lib_consts.NAME] = 'hm2'
        self.provider_hm2_dict.update({
            lib_consts.HTTP_VERSION:
            1.1,
            lib_consts.DOMAIN_NAME:
            'testdomainname.com'
        })

        self.provider_hm1 = driver_dm.HealthMonitor(**self.provider_hm1_dict)
        self.provider_hm2 = driver_dm.HealthMonitor(**self.provider_hm2_dict)

        # Setup Members
        self.test_member1_dict = {
            lib_consts.ID: self.member1_id,
            lib_consts.POOL_ID: self.pool1_id,
            constants.IP_ADDRESS: '192.0.2.16',
            lib_consts.PROTOCOL_PORT: 80,
            lib_consts.WEIGHT: 0,
            lib_consts.BACKUP: False,
            lib_consts.SUBNET_ID: self.subnet_id,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.NAME: 'member1',
            lib_consts.OPERATING_STATUS: lib_consts.ONLINE,
            lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
            constants.ENABLED: True,
            constants.CREATED_AT: self.created_at,
            constants.UPDATED_AT: self.updated_at,
            lib_consts.MONITOR_ADDRESS: '192.0.2.26',
            lib_consts.MONITOR_PORT: 81
        }

        self.test_member1_dict.update(self._common_test_dict)

        self.test_member2_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member2_dict[lib_consts.ID] = self.member2_id
        self.test_member2_dict[constants.IP_ADDRESS] = '192.0.2.17'
        self.test_member2_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.27'
        self.test_member2_dict[lib_consts.NAME] = 'member2'

        self.test_member3_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member3_dict[lib_consts.ID] = self.member3_id
        self.test_member3_dict[constants.IP_ADDRESS] = '192.0.2.18'
        self.test_member3_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.28'
        self.test_member3_dict[lib_consts.NAME] = 'member3'
        self.test_member3_dict[lib_consts.POOL_ID] = self.pool2_id

        self.test_member4_dict = copy.deepcopy(self.test_member1_dict)
        self.test_member4_dict[lib_consts.ID] = self.member4_id
        self.test_member4_dict[constants.IP_ADDRESS] = '192.0.2.19'
        self.test_member4_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.29'
        self.test_member4_dict[lib_consts.NAME] = 'member4'
        self.test_member4_dict[lib_consts.POOL_ID] = self.pool2_id

        self.test_pool1_members_dict = [
            self.test_member1_dict, self.test_member2_dict
        ]
        self.test_pool2_members_dict = [
            self.test_member3_dict, self.test_member4_dict
        ]

        self.db_member1 = data_models.Member(**self.test_member1_dict)
        self.db_member2 = data_models.Member(**self.test_member2_dict)
        self.db_member3 = data_models.Member(**self.test_member3_dict)
        self.db_member4 = data_models.Member(**self.test_member4_dict)

        self.db_pool1_members = [self.db_member1, self.db_member2]
        self.db_pool2_members = [self.db_member3, self.db_member4]

        self.provider_member1_dict = {
            lib_consts.ADDRESS: '192.0.2.16',
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.MEMBER_ID: self.member1_id,
            lib_consts.MONITOR_ADDRESS: '192.0.2.26',
            lib_consts.MONITOR_PORT: 81,
            lib_consts.NAME: 'member1',
            lib_consts.POOL_ID: self.pool1_id,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.PROTOCOL_PORT: 80,
            lib_consts.SUBNET_ID: self.subnet_id,
            lib_consts.WEIGHT: 0,
            lib_consts.BACKUP: False
        }

        self.provider_member2_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member2_dict[lib_consts.MEMBER_ID] = self.member2_id
        self.provider_member2_dict[lib_consts.ADDRESS] = '192.0.2.17'
        self.provider_member2_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.27'
        self.provider_member2_dict[lib_consts.NAME] = 'member2'

        self.provider_member3_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member3_dict[lib_consts.MEMBER_ID] = self.member3_id
        self.provider_member3_dict[lib_consts.ADDRESS] = '192.0.2.18'
        self.provider_member3_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.28'
        self.provider_member3_dict[lib_consts.NAME] = 'member3'
        self.provider_member3_dict[lib_consts.POOL_ID] = self.pool2_id

        self.provider_member4_dict = copy.deepcopy(self.provider_member1_dict)
        self.provider_member4_dict[lib_consts.MEMBER_ID] = self.member4_id
        self.provider_member4_dict[lib_consts.ADDRESS] = '192.0.2.19'
        self.provider_member4_dict[lib_consts.MONITOR_ADDRESS] = '192.0.2.29'
        self.provider_member4_dict[lib_consts.NAME] = 'member4'
        self.provider_member4_dict[lib_consts.POOL_ID] = self.pool2_id

        self.provider_pool1_members_dict = [
            self.provider_member1_dict, self.provider_member2_dict
        ]

        self.provider_pool2_members_dict = [
            self.provider_member3_dict, self.provider_member4_dict
        ]

        self.provider_member1 = driver_dm.Member(**self.provider_member1_dict)
        self.provider_member2 = driver_dm.Member(**self.provider_member2_dict)
        self.provider_member3 = driver_dm.Member(**self.provider_member3_dict)
        self.provider_member4 = driver_dm.Member(**self.provider_member4_dict)

        self.provider_pool1_members = [
            self.provider_member1, self.provider_member2
        ]
        self.provider_pool2_members = [
            self.provider_member3, self.provider_member4
        ]

        # Setup test pools
        self.test_pool1_dict = {
            lib_consts.ID: self.pool1_id,
            lib_consts.NAME: 'pool1',
            lib_consts.DESCRIPTION: 'Pool 1',
            constants.LOAD_BALANCER_ID: self.lb_id,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
            lib_consts.LB_ALGORITHM: lib_consts.LB_ALGORITHM_ROUND_ROBIN,
            lib_consts.MEMBERS: self.test_pool1_members_dict,
            constants.HEALTH_MONITOR: self.test_hm1_dict,
            lib_consts.SESSION_PERSISTENCE: {
                lib_consts.TYPE: lib_consts.LB_ALGORITHM_SOURCE_IP
            },
            lib_consts.LISTENERS: [],
            lib_consts.L7POLICIES: [],
            constants.TLS_CERTIFICATE_ID: self.pool_sni_container_ref,
            constants.CA_TLS_CERTIFICATE_ID: self.pool_ca_container_ref,
            constants.CRL_CONTAINER_ID: self.pool_crl_container_ref,
            lib_consts.TLS_ENABLED: True,
            lib_consts.TLS_CIPHERS: None,
            lib_consts.TLS_VERSIONS: None
        }

        self.test_pool1_dict.update(self._common_test_dict)

        self.test_pool2_dict = copy.deepcopy(self.test_pool1_dict)
        self.test_pool2_dict[lib_consts.ID] = self.pool2_id
        self.test_pool2_dict[lib_consts.NAME] = 'pool2'
        self.test_pool2_dict[lib_consts.DESCRIPTION] = 'Pool 2'
        self.test_pool2_dict[lib_consts.MEMBERS] = self.test_pool2_members_dict
        del self.test_pool2_dict[constants.TLS_CERTIFICATE_ID]
        del self.test_pool2_dict[constants.CA_TLS_CERTIFICATE_ID]
        del self.test_pool2_dict[constants.CRL_CONTAINER_ID]

        self.test_pools = [self.test_pool1_dict, self.test_pool2_dict]

        self.db_pool1 = data_models.Pool(**self.test_pool1_dict)
        self.db_pool1.health_monitor = self.db_hm1
        self.db_pool1.members = self.db_pool1_members
        self.db_pool2 = data_models.Pool(**self.test_pool2_dict)
        self.db_pool2.health_monitor = self.db_hm2
        self.db_pool2.members = self.db_pool2_members

        self.test_db_pools = [self.db_pool1, self.db_pool2]
        pool_cert = data_models.TLSContainer(certificate='pool cert')
        pool_ca_file_content = 'X509 POOL CA CERT FILE'
        pool_crl_file_content = 'X509 POOL CRL FILE'

        self.provider_pool1_dict = {
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.DESCRIPTION: 'Pool 1',
            lib_consts.HEALTHMONITOR: self.provider_hm1_dict,
            lib_consts.LB_ALGORITHM: lib_consts.LB_ALGORITHM_ROUND_ROBIN,
            lib_consts.LOADBALANCER_ID: self.lb_id,
            lib_consts.MEMBERS: self.provider_pool1_members_dict,
            lib_consts.NAME: 'pool1',
            lib_consts.POOL_ID: self.pool1_id,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.PROTOCOL: lib_consts.PROTOCOL_TCP,
            lib_consts.SESSION_PERSISTENCE: {
                lib_consts.TYPE: lib_consts.LB_ALGORITHM_SOURCE_IP
            },
            lib_consts.TLS_CONTAINER_REF: self.pool_sni_container_ref,
            lib_consts.TLS_CONTAINER_DATA: pool_cert.to_dict(),
            lib_consts.CA_TLS_CONTAINER_REF: self.pool_ca_container_ref,
            lib_consts.CA_TLS_CONTAINER_DATA: pool_ca_file_content,
            lib_consts.CRL_CONTAINER_REF: self.pool_crl_container_ref,
            lib_consts.CRL_CONTAINER_DATA: pool_crl_file_content,
            lib_consts.TLS_ENABLED: True,
            lib_consts.TLS_CIPHERS: None,
            lib_consts.TLS_VERSIONS: None,
        }

        self.provider_pool2_dict = copy.deepcopy(self.provider_pool1_dict)
        self.provider_pool2_dict[lib_consts.POOL_ID] = self.pool2_id
        self.provider_pool2_dict[lib_consts.NAME] = 'pool2'
        self.provider_pool2_dict[lib_consts.DESCRIPTION] = 'Pool 2'
        self.provider_pool2_dict[
            lib_consts.MEMBERS] = self.provider_pool2_members_dict
        self.provider_pool2_dict[
            lib_consts.HEALTHMONITOR] = self.provider_hm2_dict
        self.provider_pool2_dict[lib_consts.TLS_CONTAINER_REF] = None
        del self.provider_pool2_dict[lib_consts.TLS_CONTAINER_DATA]
        self.provider_pool2_dict[lib_consts.CA_TLS_CONTAINER_REF] = None
        del self.provider_pool2_dict[lib_consts.CA_TLS_CONTAINER_DATA]
        self.provider_pool2_dict[lib_consts.CRL_CONTAINER_REF] = None
        del self.provider_pool2_dict[lib_consts.CRL_CONTAINER_DATA]

        self.provider_pool1 = driver_dm.Pool(**self.provider_pool1_dict)
        self.provider_pool1.members = self.provider_pool1_members
        self.provider_pool1.healthmonitor = self.provider_hm1
        self.provider_pool2 = driver_dm.Pool(**self.provider_pool2_dict)
        self.provider_pool2.members = self.provider_pool2_members
        self.provider_pool2.healthmonitor = self.provider_hm2

        self.provider_pools = [self.provider_pool1, self.provider_pool2]

        # Setup L7Rules
        self.test_l7rule1_dict = {
            lib_consts.ID: self.l7rule1_id,
            lib_consts.L7POLICY_ID: self.l7policy1_id,
            lib_consts.TYPE: lib_consts.L7RULE_TYPE_PATH,
            lib_consts.COMPARE_TYPE: lib_consts.L7RULE_COMPARE_TYPE_EQUAL_TO,
            lib_consts.KEY: 'fake_key',
            lib_consts.VALUE: 'fake_value',
            lib_consts.PROJECT_ID: self.project_id,
            constants.L7POLICY: None,
            lib_consts.INVERT: False
        }

        self.test_l7rule1_dict.update(self._common_test_dict)

        self.test_l7rule2_dict = copy.deepcopy(self.test_l7rule1_dict)
        self.test_l7rule2_dict[lib_consts.ID] = self.l7rule2_id

        self.test_l7rules = [self.test_l7rule1_dict, self.test_l7rule2_dict]

        self.db_l7Rule1 = data_models.L7Rule(**self.test_l7rule1_dict)
        self.db_l7Rule2 = data_models.L7Rule(**self.test_l7rule2_dict)

        self.db_l7Rules = [self.db_l7Rule1, self.db_l7Rule2]

        self.provider_l7rule1_dict = {
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.COMPARE_TYPE: lib_consts.L7RULE_COMPARE_TYPE_EQUAL_TO,
            lib_consts.INVERT: False,
            lib_consts.KEY: 'fake_key',
            lib_consts.L7POLICY_ID: self.l7policy1_id,
            lib_consts.L7RULE_ID: self.l7rule1_id,
            lib_consts.TYPE: lib_consts.L7RULE_TYPE_PATH,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.VALUE: 'fake_value'
        }

        self.provider_l7rule2_dict = copy.deepcopy(self.provider_l7rule1_dict)
        self.provider_l7rule2_dict[lib_consts.L7RULE_ID] = self.l7rule2_id
        self.provider_l7rules_dicts = [
            self.provider_l7rule1_dict, self.provider_l7rule2_dict
        ]

        self.provider_l7rule1 = driver_dm.L7Rule(**self.provider_l7rule1_dict)
        self.provider_l7rule2 = driver_dm.L7Rule(**self.provider_l7rule2_dict)

        self.provider_rules = [self.provider_l7rule1, self.provider_l7rule2]

        # Setup L7Policies
        self.test_l7policy1_dict = {
            lib_consts.ID: self.l7policy1_id,
            lib_consts.NAME: 'l7policy_1',
            lib_consts.DESCRIPTION: 'L7policy 1',
            lib_consts.LISTENER_ID: self.listener1_id,
            lib_consts.ACTION: lib_consts.L7POLICY_ACTION_REDIRECT_TO_URL,
            lib_consts.REDIRECT_POOL_ID: None,
            lib_consts.REDIRECT_URL: 'http://example.com/index.html',
            lib_consts.REDIRECT_PREFIX: None,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.POSITION: 1,
            constants.LISTENER: None,
            constants.REDIRECT_POOL: None,
            lib_consts.L7RULES: self.test_l7rules,
            lib_consts.REDIRECT_HTTP_CODE: 302
        }

        self.test_l7policy1_dict.update(self._common_test_dict)

        self.test_l7policy2_dict = copy.deepcopy(self.test_l7policy1_dict)
        self.test_l7policy2_dict[lib_consts.ID] = self.l7policy2_id
        self.test_l7policy2_dict[lib_consts.NAME] = 'l7policy_2'
        self.test_l7policy2_dict[lib_consts.DESCRIPTION] = 'L7policy 2'

        self.test_l7policies = [
            self.test_l7policy1_dict, self.test_l7policy2_dict
        ]

        self.db_l7policy1 = data_models.L7Policy(**self.test_l7policy1_dict)
        self.db_l7policy2 = data_models.L7Policy(**self.test_l7policy2_dict)
        self.db_l7policy1.l7rules = self.db_l7Rules
        self.db_l7policy2.l7rules = self.db_l7Rules

        self.db_l7policies = [self.db_l7policy1, self.db_l7policy2]

        self.provider_l7policy1_dict = {
            lib_consts.ACTION: lib_consts.L7POLICY_ACTION_REDIRECT_TO_URL,
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.DESCRIPTION: 'L7policy 1',
            lib_consts.L7POLICY_ID: self.l7policy1_id,
            lib_consts.LISTENER_ID: self.listener1_id,
            lib_consts.NAME: 'l7policy_1',
            lib_consts.POSITION: 1,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.REDIRECT_POOL_ID: None,
            lib_consts.REDIRECT_URL: 'http://example.com/index.html',
            lib_consts.REDIRECT_PREFIX: None,
            lib_consts.RULES: self.provider_l7rules_dicts,
            lib_consts.REDIRECT_HTTP_CODE: 302
        }

        self.provider_l7policy2_dict = copy.deepcopy(
            self.provider_l7policy1_dict)
        self.provider_l7policy2_dict[
            lib_consts.L7POLICY_ID] = self.l7policy2_id
        self.provider_l7policy2_dict[lib_consts.NAME] = 'l7policy_2'
        self.provider_l7policy2_dict[lib_consts.DESCRIPTION] = 'L7policy 2'

        self.provider_l7policies_dict = [
            self.provider_l7policy1_dict, self.provider_l7policy2_dict
        ]

        self.provider_l7policy1 = driver_dm.L7Policy(
            **self.provider_l7policy1_dict)
        self.provider_l7policy1.rules = self.provider_rules
        self.provider_l7policy2 = driver_dm.L7Policy(
            **self.provider_l7policy2_dict)
        self.provider_l7policy2.rules = self.provider_rules

        self.provider_l7policies = [
            self.provider_l7policy1, self.provider_l7policy2
        ]

        # Setup Listeners
        self.test_listener1_dict = {
            lib_consts.ID:
            self.listener1_id,
            lib_consts.NAME:
            'listener_1',
            lib_consts.DESCRIPTION:
            'Listener 1',
            lib_consts.DEFAULT_POOL_ID:
            self.pool1_id,
            constants.LOAD_BALANCER_ID:
            self.lb_id,
            lib_consts.PROJECT_ID:
            self.project_id,
            lib_consts.PROTOCOL:
            lib_consts.PROTOCOL_TCP,
            lib_consts.PROTOCOL_PORT:
            90,
            lib_consts.CONNECTION_LIMIT:
            10000,
            constants.TLS_CERTIFICATE_ID:
            self.default_tls_container_ref,
            lib_consts.DEFAULT_POOL:
            self.test_pool1_dict,
            constants.SNI_CONTAINERS: [{
                constants.TLS_CONTAINER_ID:
                self.sni_container_ref_1
            }, {
                constants.TLS_CONTAINER_ID:
                self.sni_container_ref_2
            }],
            constants.PEER_PORT:
            55,
            lib_consts.L7POLICIES:
            self.test_l7policies,
            lib_consts.INSERT_HEADERS: {},
            lib_consts.TIMEOUT_CLIENT_DATA:
            1000,
            lib_consts.TIMEOUT_MEMBER_CONNECT:
            2000,
            lib_consts.TIMEOUT_MEMBER_DATA:
            3000,
            lib_consts.TIMEOUT_TCP_INSPECT:
            4000,
            constants.CLIENT_CA_TLS_CERTIFICATE_ID:
            self.client_ca_tls_certificate_ref,
            lib_consts.CLIENT_AUTHENTICATION:
            constants.CLIENT_AUTH_NONE,
            constants.CLIENT_CRL_CONTAINER_ID:
            self.client_crl_container_ref,
            lib_consts.ALLOWED_CIDRS: ['192.0.2.0/24', '198.51.100.0/24'],
            lib_consts.TLS_CIPHERS:
            constants.CIPHERS_OWASP_SUITE_B,
            lib_consts.TLS_VERSIONS:
            constants.TLS_VERSIONS_OWASP_SUITE_B
        }

        self.test_listener1_dict.update(self._common_test_dict)

        self.test_listener2_dict = copy.deepcopy(self.test_listener1_dict)
        self.test_listener2_dict[lib_consts.ID] = self.listener2_id
        self.test_listener2_dict[lib_consts.NAME] = 'listener_2'
        self.test_listener2_dict[lib_consts.DESCRIPTION] = 'Listener 1'
        self.test_listener2_dict[lib_consts.DEFAULT_POOL_ID] = self.pool2_id
        self.test_listener2_dict[
            lib_consts.DEFAULT_POOL] = self.test_pool2_dict
        del self.test_listener2_dict[lib_consts.L7POLICIES]
        del self.test_listener2_dict[constants.SNI_CONTAINERS]
        del self.test_listener2_dict[constants.CLIENT_CA_TLS_CERTIFICATE_ID]
        del self.test_listener2_dict[constants.CLIENT_CRL_CONTAINER_ID]

        self.test_listeners = [
            self.test_listener1_dict, self.test_listener2_dict
        ]

        self.db_listener1 = data_models.Listener(**self.test_listener1_dict)
        self.db_listener2 = data_models.Listener(**self.test_listener2_dict)
        self.db_listener1.default_pool = self.db_pool1
        self.db_listener2.default_pool = self.db_pool2
        self.db_listener1.l7policies = self.db_l7policies
        self.db_listener1.sni_containers = [
            data_models.SNI(tls_container_id='2'),
            data_models.SNI(tls_container_id='3')
        ]

        self.test_db_listeners = [self.db_listener1, self.db_listener2]

        cert1 = data_models.TLSContainer(certificate='cert 1')
        cert2 = data_models.TLSContainer(certificate='cert 2')
        cert3 = data_models.TLSContainer(certificate='cert 3')
        ca_cert = 'ca cert'
        crl_file_content = 'X509 CRL FILE'

        self.provider_listener1_dict = {
            lib_consts.ADMIN_STATE_UP:
            True,
            lib_consts.ALLOWED_CIDRS: ['192.0.2.0/24', '198.51.100.0/24'],
            lib_consts.CONNECTION_LIMIT:
            10000,
            lib_consts.DEFAULT_POOL:
            self.provider_pool1_dict,
            lib_consts.DEFAULT_POOL_ID:
            self.pool1_id,
            lib_consts.DEFAULT_TLS_CONTAINER_DATA:
            cert1.to_dict(),
            lib_consts.DEFAULT_TLS_CONTAINER_REF:
            self.default_tls_container_ref,
            lib_consts.DESCRIPTION:
            'Listener 1',
            lib_consts.INSERT_HEADERS: {},
            lib_consts.L7POLICIES:
            self.provider_l7policies_dict,
            lib_consts.LISTENER_ID:
            self.listener1_id,
            lib_consts.LOADBALANCER_ID:
            self.lb_id,
            lib_consts.NAME:
            'listener_1',
            lib_consts.PROJECT_ID:
            self.project_id,
            lib_consts.PROTOCOL:
            lib_consts.PROTOCOL_TCP,
            lib_consts.PROTOCOL_PORT:
            90,
            lib_consts.SNI_CONTAINER_DATA: [cert2.to_dict(),
                                            cert3.to_dict()],
            lib_consts.SNI_CONTAINER_REFS:
            [self.sni_container_ref_1, self.sni_container_ref_2],
            lib_consts.TIMEOUT_CLIENT_DATA:
            1000,
            lib_consts.TIMEOUT_MEMBER_CONNECT:
            2000,
            lib_consts.TIMEOUT_MEMBER_DATA:
            3000,
            lib_consts.TIMEOUT_TCP_INSPECT:
            4000,
            lib_consts.CLIENT_CA_TLS_CONTAINER_REF:
            self.client_ca_tls_certificate_ref,
            lib_consts.CLIENT_CA_TLS_CONTAINER_DATA:
            ca_cert,
            lib_consts.CLIENT_AUTHENTICATION:
            constants.CLIENT_AUTH_NONE,
            lib_consts.CLIENT_CRL_CONTAINER_REF:
            self.client_crl_container_ref,
            lib_consts.CLIENT_CRL_CONTAINER_DATA:
            crl_file_content,
            lib_consts.TLS_CIPHERS:
            constants.CIPHERS_OWASP_SUITE_B,
            lib_consts.TLS_VERSIONS:
            constants.TLS_VERSIONS_OWASP_SUITE_B
        }

        self.provider_listener2_dict = copy.deepcopy(
            self.provider_listener1_dict)
        self.provider_listener2_dict[
            lib_consts.LISTENER_ID] = self.listener2_id
        self.provider_listener2_dict[lib_consts.NAME] = 'listener_2'
        self.provider_listener2_dict[lib_consts.DESCRIPTION] = 'Listener 1'
        self.provider_listener2_dict[
            lib_consts.DEFAULT_POOL_ID] = self.pool2_id
        self.provider_listener2_dict[
            lib_consts.DEFAULT_POOL] = self.provider_pool2_dict
        del self.provider_listener2_dict[lib_consts.L7POLICIES]
        self.provider_listener2_dict[
            lib_consts.CLIENT_CA_TLS_CONTAINER_REF] = None
        del self.provider_listener2_dict[
            lib_consts.CLIENT_CA_TLS_CONTAINER_DATA]
        self.provider_listener2_dict[lib_consts.CLIENT_AUTHENTICATION] = (
            constants.CLIENT_AUTH_NONE)
        self.provider_listener2_dict[
            lib_consts.CLIENT_CRL_CONTAINER_REF] = None
        del self.provider_listener2_dict[lib_consts.CLIENT_CRL_CONTAINER_DATA]

        self.provider_listener1 = driver_dm.Listener(
            **self.provider_listener1_dict)
        self.provider_listener2 = driver_dm.Listener(
            **self.provider_listener2_dict)
        self.provider_listener1.default_pool = self.provider_pool1
        self.provider_listener2.default_pool = self.provider_pool2
        self.provider_listener1.l7policies = self.provider_l7policies

        self.provider_listeners = [
            self.provider_listener1, self.provider_listener2
        ]

        self.test_vip_dict = {
            constants.IP_ADDRESS: self.ip_address,
            constants.NETWORK_ID: self.network_id,
            constants.PORT_ID: self.port_id,
            lib_consts.SUBNET_ID: self.subnet_id,
            constants.QOS_POLICY_ID: self.qos_policy_id,
            constants.OCTAVIA_OWNED: None
        }

        self.provider_vip_dict = {
            lib_consts.VIP_ADDRESS: self.ip_address,
            lib_consts.VIP_NETWORK_ID: self.network_id,
            lib_consts.VIP_PORT_ID: self.port_id,
            lib_consts.VIP_SUBNET_ID: self.subnet_id,
            lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
            constants.OCTAVIA_OWNED: None
        }

        self.db_vip = data_models.Vip(ip_address=self.ip_address,
                                      network_id=self.network_id,
                                      port_id=self.port_id,
                                      subnet_id=self.subnet_id,
                                      qos_policy_id=self.qos_policy_id)

        self.test_loadbalancer1_dict = {
            lib_consts.NAME: self.lb_name,
            lib_consts.DESCRIPTION: self.lb_description,
            constants.ENABLED: True,
            lib_consts.PROVISIONING_STATUS: lib_consts.PENDING_UPDATE,
            lib_consts.OPERATING_STATUS: lib_consts.OFFLINE,
            constants.TOPOLOGY: constants.TOPOLOGY_ACTIVE_STANDBY,
            constants.VRRP_GROUP: None,
            constants.PROVIDER: constants.AMPHORA,
            constants.SERVER_GROUP_ID: uuidutils.generate_uuid(),
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.ID: self.lb_id,
            constants.FLAVOR_ID: self.flavor_id,
            constants.TAGS: ['test_tag']
        }

        self.provider_loadbalancer_dict = {
            lib_consts.ADDITIONAL_VIPS: None,
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.DESCRIPTION: self.lb_description,
            lib_consts.FLAVOR: {
                "something": "else"
            },
            lib_consts.LISTENERS: None,
            lib_consts.LOADBALANCER_ID: self.lb_id,
            lib_consts.NAME: self.lb_name,
            lib_consts.POOLS: None,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.VIP_ADDRESS: self.ip_address,
            lib_consts.VIP_NETWORK_ID: self.network_id,
            lib_consts.VIP_PORT_ID: self.port_id,
            lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
            lib_consts.VIP_SUBNET_ID: self.subnet_id
        }

        self.provider_loadbalancer_tree_dict = {
            lib_consts.ADDITIONAL_VIPS: None,
            lib_consts.ADMIN_STATE_UP: True,
            lib_consts.AVAILABILITY_ZONE: None,
            lib_consts.DESCRIPTION: self.lb_description,
            lib_consts.FLAVOR: {
                "something": "else"
            },
            lib_consts.LISTENERS: None,
            lib_consts.LOADBALANCER_ID: self.lb_id,
            lib_consts.NAME: self.lb_name,
            lib_consts.POOLS: None,
            lib_consts.PROJECT_ID: self.project_id,
            lib_consts.VIP_ADDRESS: self.ip_address,
            lib_consts.VIP_NETWORK_ID: self.network_id,
            lib_consts.VIP_PORT_ID: self.port_id,
            lib_consts.VIP_QOS_POLICY_ID: self.qos_policy_id,
            lib_consts.VIP_SUBNET_ID: self.subnet_id
        }
Esempio n. 13
0
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture

from octavia.common import constants as o_constants
from octavia.common import data_models as o_data_models
from octavia.common import exceptions

from a10_octavia.common import config_options
from a10_octavia.common import data_models
import a10_octavia.controller.worker.tasks.service_group_tasks as task
from a10_octavia.controller.worker.tasks import utils
from a10_octavia.tests.common import a10constants
from a10_octavia.tests.unit.base import BaseTaskTestCase

VTHUNDER = data_models.VThunder()
POOL = o_data_models.Pool(id=a10constants.MOCK_POOL_ID, name="sg1")
AXAPI_ARGS = {'service_group': utils.meta(POOL, 'service_group', {})}


class TestHandlerServiceGroupTasks(BaseTaskTestCase):
    def setUp(self):
        super(TestHandlerServiceGroupTasks, self).setUp()
        imp.reload(task)
        self.client_mock = mock.Mock()
        self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
        self.conf.register_opts(config_options.A10_SERVICE_GROUP_OPTS,
                                group=a10constants.SERVICE_GROUP_CONF_SECTION)
        self.conf.register_opts(config_options.A10_GLOBAL_OPTS,
                                group=a10constants.A10_GLOBAL_CONF_SECTION)

    def tearDown(self):
Esempio n. 14
0
    import mock
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture

from octavia.common import data_models as o_data_models
from octavia.network import data_models as o_net_data_models

from a10_octavia.common import config_options
from a10_octavia.common import data_models
from a10_octavia.controller.worker.tasks import a10_network_tasks
from a10_octavia.tests.common import a10constants
from a10_octavia.tests.unit import base

LB = o_data_models.LoadBalancer(id=a10constants.MOCK_LOAD_BALANCER_ID)
MEMBER = o_data_models.Member(subnet_id=a10constants.MOCK_SUBNET_ID)
POOL = o_data_models.Pool()
VTHUNDER = data_models.VThunder()
SUBNET = o_net_data_models.Subnet()
PORT = o_net_data_models.Port()
VRID = data_models.VRID()
VRID_VALUE = 0
SUBNET_1 = o_net_data_models.Subnet(id=a10constants.MOCK_SUBNET_ID)
VRID_1 = data_models.VRID(id=1, subnet_id=a10constants.MOCK_SUBNET_ID)
NAT_POOL = data_models.NATPool(port_id=a10constants.MOCK_PORT_ID)
NAT_FLAVOR = {
    "pool_name": "p1",
    "start_address": "1.1.1.1",
    "end_address": "1.1.1.2"
}
HW_THUNDER = data_models.HardwareThunder(
    project_id=a10constants.MOCK_PROJECT_ID,
Esempio n. 15
0
    def setUp(self):

        self.LB_ID = uuidutils.generate_uuid()
        self.PROJECT_ID = uuidutils.generate_uuid()
        self.SERVER_GROUP_ID = uuidutils.generate_uuid()
        self.CREATED_AT = datetime.datetime.now()
        self.UPDATED_AT = datetime.datetime.utcnow()
        self.VIP_IP = '192.0.2.10'
        self.VIP_SUBNET_ID = uuidutils.generate_uuid()
        self.VIP_NETWORK_ID = uuidutils.generate_uuid()
        self.VIP_PORT_ID = uuidutils.generate_uuid()
        self.VIP_QOS_ID = uuidutils.generate_uuid()
        self.POOL_ID = uuidutils.generate_uuid()
        self.AMP_ID = uuidutils.generate_uuid()
        self.COMPUTE_ID = uuidutils.generate_uuid()
        self.IMAGE_ID = uuidutils.generate_uuid()
        self.COMPUTE_FLAVOR = uuidutils.generate_uuid()

        self.LB_obj = data_models.LoadBalancer(
            id=self.LB_ID,
            project_id=self.PROJECT_ID,
            name='test-lb',
            description='test-lb-description',
            provisioning_status='great',
            operating_status='even-better',
            enabled=True,
            vip=None,
            vrrp_group=1,
            topology='infinite',
            listeners=[],
            amphorae=[],
            pools=[],
            server_group_id=self.SERVER_GROUP_ID,
            created_at=self.CREATED_AT,
            updated_at=self.UPDATED_AT)

        self.VIP_obj = data_models.Vip(load_balancer_id=self.LB_ID,
                                       ip_address=self.VIP_IP,
                                       subnet_id=self.VIP_SUBNET_ID,
                                       network_id=self.VIP_NETWORK_ID,
                                       port_id=self.VIP_PORT_ID,
                                       qos_policy_id=self.VIP_QOS_ID)

        self.POOL_obj = data_models.Pool(id=self.POOL_ID,
                                         project_id=self.PROJECT_ID,
                                         name='test-pool',
                                         description='test-pool-description',
                                         load_balancer_id=self.LB_ID,
                                         load_balancer=None,
                                         protocol='avian',
                                         lb_algorithm='UseAllofThem',
                                         enabled=True,
                                         provisioning_status='great',
                                         operating_status='even-better',
                                         members=[],
                                         health_monitor=None,
                                         session_persistence=None,
                                         listeners=[],
                                         l7policies=[],
                                         created_at=self.CREATED_AT,
                                         updated_at=self.UPDATED_AT)

        self.SP_obj = data_models.SessionPersistence(pool_id=self.POOL_ID,
                                                     type='adhesive',
                                                     cookie_name='chocolate',
                                                     pool=None)

        self.AMP_obj = data_models.Amphora(
            id=self.AMP_ID,
            load_balancer_id=self.LB_ID,
            compute_id=self.COMPUTE_ID,
            status=constants.ACTIVE,
            lb_network_ip=None,
            vrrp_ip=None,
            ha_ip=None,
            vrrp_port_id=None,
            ha_port_id=self.VIP_PORT_ID,
            load_balancer=self.LB_obj,
            role=constants.ROLE_MASTER,
            cert_expiration=None,
            cert_busy=False,
            vrrp_interface=None,
            vrrp_id=None,
            vrrp_priority=constants.ROLE_MASTER_PRIORITY,
            cached_zone=None,
            created_at=self.CREATED_AT,
            updated_at=self.UPDATED_AT,
            image_id=self.IMAGE_ID,
            compute_flavor=self.COMPUTE_FLAVOR)

        super(TestDataModels, self).setUp()
Esempio n. 16
0
    username="******",
    password="******",
    ip_address="10.10.10.10",
    partition_name="shared")
LB = o_data_models.LoadBalancer(id=a10constants.MOCK_LOAD_BALANCER_ID,
                                flavor_id=a10constants.MOCK_FLAVOR_ID)
FIXED_IP = n_data_models.FixedIP(ip_address='10.10.10.10')
PORT = n_data_models.Port(id=uuidutils.generate_uuid(), fixed_ips=[FIXED_IP])
VRID = data_models.VRID(id=1,
                        vrid=0,
                        owner=a10constants.MOCK_PROJECT_ID,
                        vrid_port_id=uuidutils.generate_uuid(),
                        vrid_floating_ip='10.0.12.32')
LISTENER = o_data_models.Listener(id=a10constants.MOCK_LISTENER_ID,
                                  load_balancer=LB)
POOL = o_data_models.Pool(id=a10constants.MOCK_POOL_ID, load_balancer=LB)
HM = o_data_models.HealthMonitor(id=a10constants, pool=POOL)
MEMBER_1 = o_data_models.Member(id=uuidutils.generate_uuid(),
                                project_id=a10constants.MOCK_PROJECT_ID,
                                subnet_id=a10constants.MOCK_SUBNET_ID,
                                pool=POOL)
MEMBER_2 = o_data_models.Member(id=uuidutils.generate_uuid(),
                                project_id=a10constants.MOCK_PROJECT_ID,
                                subnet_id=a10constants.MOCK_SUBNET_ID_2,
                                pool=POOL)
FLAVOR_PROFILE = o_data_models.FlavorProfile(
    id=a10constants.MOCK_FLAVOR_PROF_ID, flavor_data={})
FLAVOR = o_data_models.Flavor(
    id=a10constants.MOCK_FLAVOR_ID,
    flavor_profile_id=a10constants.MOCK_FLAVOR_PROF_ID)
SUBNET = n_data_models.Subnet(id=uuidutils.generate_uuid())
Esempio n. 17
0
def pool_dict_to_provider_dict(pool_dict):
    new_pool_dict = _base_to_provider_dict(pool_dict, include_project_id=True)
    new_pool_dict['pool_id'] = new_pool_dict.pop('id')

    # Pull the certs out of the certificate manager to pass to the provider
    if 'tls_certificate_id' in new_pool_dict:
        new_pool_dict['tls_container_ref'] = new_pool_dict.pop(
            'tls_certificate_id')
    if 'ca_tls_certificate_id' in new_pool_dict:
        new_pool_dict['ca_tls_container_ref'] = new_pool_dict.pop(
            'ca_tls_certificate_id')
    if 'crl_container_id' in new_pool_dict:
        new_pool_dict['crl_container_ref'] = new_pool_dict.pop(
            'crl_container_id')

    pool_obj = data_models.Pool(**pool_dict)
    if (pool_obj.tls_certificate_id or pool_obj.ca_tls_certificate_id or
            pool_obj.crl_container_id):
        cert_manager = stevedore_driver.DriverManager(
            namespace='octavia.cert_manager',
            name=CONF.certificates.cert_manager,
            invoke_on_load=True,
        ).driver
        cert_dict = cert_parser.load_certificates_data(cert_manager,
                                                       pool_obj)
        if 'tls_cert' in cert_dict and cert_dict['tls_cert']:
            new_pool_dict['tls_container_data'] = (
                cert_dict['tls_cert'].to_dict())

        if pool_obj.ca_tls_certificate_id:
            cert = _get_secret_data(cert_manager, pool_obj.project_id,
                                    pool_obj.ca_tls_certificate_id)
            new_pool_dict['ca_tls_container_data'] = cert

        if pool_obj.crl_container_id:
            crl_file = _get_secret_data(cert_manager, pool_obj.project_id,
                                        pool_obj.crl_container_id)
            new_pool_dict['crl_container_data'] = crl_file

    # Remove the DB back references
    if ('session_persistence' in new_pool_dict and
            new_pool_dict['session_persistence']):
        if 'pool_id' in new_pool_dict['session_persistence']:
            del new_pool_dict['session_persistence']['pool_id']
        if 'pool' in new_pool_dict['session_persistence']:
            del new_pool_dict['session_persistence']['pool']
    if 'l7policies' in new_pool_dict:
        del new_pool_dict['l7policies']
    if 'listeners' in new_pool_dict:
        del new_pool_dict['listeners']
    if 'load_balancer' in new_pool_dict:
        del new_pool_dict['load_balancer']
    if 'load_balancer_id' in new_pool_dict:
        new_pool_dict['loadbalancer_id'] = new_pool_dict.pop(
            'load_balancer_id')
    if 'health_monitor' in new_pool_dict:
        hm = new_pool_dict.pop('health_monitor')
        if hm:
            new_pool_dict['healthmonitor'] = hm_dict_to_provider_dict(hm)
        else:
            new_pool_dict['healthmonitor'] = None
    if 'members' in new_pool_dict and new_pool_dict['members']:
        members = new_pool_dict.pop('members')
        provider_members = []
        for member in members:
            provider_member = member_dict_to_provider_dict(member)
            provider_members.append(provider_member)
        new_pool_dict['members'] = provider_members
    return new_pool_dict
Esempio n. 18
0
import copy
import imp
try:
    from unittest import mock
except ImportError:
    import mock

from octavia.common import data_models as o_data_models

from a10_octavia.common.data_models import VThunder
from a10_octavia.controller.worker.tasks import persist_tasks
from a10_octavia.tests.common import a10constants as a10_test_constants
from a10_octavia.tests.unit.base import BaseTaskTestCase

VTHUNDER = VThunder()
POOL = o_data_models.Pool(id=a10_test_constants.MOCK_POOL_ID)
SOURCE_IP_SESS_PERS = o_data_models.SessionPersistence(
    pool_id=a10_test_constants.MOCK_POOL_ID,
    type='SOURCE_IP')
APP_COOKIE_SESS_PERS = o_data_models.SessionPersistence(
    pool_id=a10_test_constants.MOCK_POOL_ID,
    type='APP_COOKIE', cookie_name=a10_test_constants.MOCK_COOKIE_NAME)
HTTP_COOKIE_SESS_PERS = o_data_models.SessionPersistence(
    pool_id=a10_test_constants.MOCK_POOL_ID,
    type='HTTP_COOKIE', cookie_name=a10_test_constants.MOCK_COOKIE_NAME)
APP_COOKIE_SESS_PERS_WITH_NO_TYPE = o_data_models.SessionPersistence(
    pool_id=a10_test_constants.MOCK_POOL_ID,
    cookie_name=a10_test_constants.MOCK_COOKIE_NAME)


class TestPersistTasks(BaseTaskTestCase):