Пример #1
0
    def test_create_member(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        member = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'pool_id': 'D4F35594-27EB-4F4C-930C-31DD40F53B77',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'port': 1234
        }
        member_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
        req = {
            'name': member['name'],
            'project_id': member['project_id'],
            'subnet_id': member['subnet_id'],
            'address': str(member['ip']),
            'protocol_port': member['port']
        }
        resp = o_mem.Member(id=member_id)
        lbaas.create_member.return_value = resp

        ret = cls._create_member(m_driver, member)
        lbaas.create_member.assert_called_once_with(member['pool_id'], **req)
        self.assertEqual(member, ret)
        self.assertEqual(member_id, ret['id'])
Пример #2
0
    def test_create_pool_conflict(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        lb_algorithm = 'ROUND_ROBIN'
        pool = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'listener_id': 'A57B7771-6050-4CA8-A63C-443493EC98AB',
            'protocol': 'TCP'
        }
        req = {
            'name': pool['name'],
            'project_id': pool['project_id'],
            'listener_id': pool['listener_id'],
            'loadbalancer_id': pool['loadbalancer_id'],
            'protocol': pool['protocol'],
            'lb_algorithm': lb_algorithm
        }
        lbaas.create_pool.side_effect = os_exc.BadRequestException

        self.assertRaises(os_exc.BadRequestException, cls._create_pool,
                          m_driver, pool)
        lbaas.create_pool.assert_called_once_with(**req)
Пример #3
0
    def test_find_pool_by_listener(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = {
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
        }
        pool = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'listener_id': 'A57B7771-6050-4CA8-A63C-443493EC98AB',
            'protocol': 'TCP'
        }
        pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'
        resp = [
            o_pool.Pool(id=pool_id, listeners=[{
                "id": pool['listener_id']
            }])
        ]
        lbaas.pools.return_value = resp

        ret = cls._find_pool(m_driver, pool, loadbalancer)
        lbaas.pools.assert_called_once_with(
            name=pool['name'],
            project_id=pool['project_id'],
            loadbalancer_id=pool['loadbalancer_id'],
            protocol=pool['protocol'])
        self.assertEqual(pool, ret)
        self.assertEqual(pool_id, ret['id'])
Пример #4
0
    def test_find_listener_not_found(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = {
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
        }
        listener = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'protocol': 'TCP',
            'port': 1234
        }
        resp = iter([])
        lbaas.listeners.return_value = resp

        ret = cls._find_listener(m_driver, listener, loadbalancer)
        lbaas.listeners.assert_called_once_with(
            name=listener['name'],
            project_id=listener['project_id'],
            load_balancer_id=listener['loadbalancer_id'],
            protocol=listener['protocol'],
            protocol_port=listener['port'])
        self.assertIsNone(ret)
Пример #5
0
    def test_create_pool(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        lb_algorithm = 'ROUND_ROBIN'
        pool = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'listener_id': 'A57B7771-6050-4CA8-A63C-443493EC98AB',
            'protocol': 'TCP'
        }
        pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'

        req = {
            'name': pool['name'],
            'project_id': pool['project_id'],
            'listener_id': pool['listener_id'],
            'loadbalancer_id': pool['loadbalancer_id'],
            'protocol': pool['protocol'],
            'lb_algorithm': lb_algorithm
        }
        resp = o_pool.Pool(id=pool_id)
        lbaas.create_pool.return_value = resp

        ret = cls._create_pool(m_driver, pool)
        lbaas.create_pool.assert_called_once_with(**req)
        self.assertEqual(pool, ret)
        self.assertEqual(pool_id, ret['id'])
Пример #6
0
    def test_create_listener(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        listener = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'protocol': 'TCP',
            'port': 1234
        }
        listener_id = 'A57B7771-6050-4CA8-A63C-443493EC98AB'

        req = {
            'name': listener['name'],
            'project_id': listener['project_id'],
            'loadbalancer_id': listener['loadbalancer_id'],
            'protocol': listener['protocol'],
            'protocol_port': listener['port']
        }
        resp = o_lis.Listener(id=listener_id)
        lbaas.create_listener.return_value = resp

        ret = cls._create_listener(m_driver, listener)
        lbaas.create_listener.assert_called_once_with(**req)
        self.assertEqual(listener, ret)
        self.assertEqual(listener_id, ret['id'])
Пример #7
0
    def test_find_listener(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = {
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
        }
        listener = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'protocol': 'TCP',
            'port': 1234
        }
        listener_id = 'A57B7771-6050-4CA8-A63C-443493EC98AB'
        lbaas.listeners.return_value = iter([o_lis.Listener(id=listener_id)])

        ret = cls._find_listener(m_driver, listener, loadbalancer)
        lbaas.listeners.assert_called_once_with(
            name=listener['name'],
            project_id=listener['project_id'],
            load_balancer_id=listener['loadbalancer_id'],
            protocol=listener['protocol'],
            protocol_port=listener['port'])
        self.assertEqual(listener, ret)
        self.assertEqual(listener_id, ret['id'])
Пример #8
0
    def test_find_loadbalancer_not_found(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = obj_lbaas.LBaaSLoadBalancer(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            ip='1.2.3.4',
            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
        loadbalancer = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'provider': None
        }
        resp = iter([])
        lbaas.load_balancers.return_value = resp

        ret = cls._find_loadbalancer(m_driver, loadbalancer)
        lbaas.load_balancers.assert_called_once_with(
            name=loadbalancer['name'],
            project_id=loadbalancer['project_id'],
            vip_address=str(loadbalancer['ip']),
            vip_subnet_id=loadbalancer['subnet_id'],
            provider=None)
        self.assertIsNone(ret)
        m_driver.release_loadbalancer.assert_not_called()
Пример #9
0
    def test_find_loadbalancer_error(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'provider': None
        }
        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        resp = iter([
            o_lb.LoadBalancer(id=loadbalancer_id,
                              provider='haproxy',
                              provisioning_status='ERROR')
        ])
        lbaas.load_balancers.return_value = resp
        m_driver._get_vip_port.return_value = munch.Munch(
            {'id': mock.sentinel.port_id})

        ret = cls._find_loadbalancer(m_driver, loadbalancer)
        lbaas.load_balancers.assert_called_once_with(
            name=loadbalancer['name'],
            project_id=loadbalancer['project_id'],
            vip_address=str(loadbalancer['ip']),
            vip_subnet_id=loadbalancer['subnet_id'],
            provider=None)
        self.assertIsNone(ret)
        m_driver.release_loadbalancer.assert_called_once()
Пример #10
0
    def test_create_loadbalancer_provider_mismatch(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        loadbalancer = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'security_groups': [],
            'provider': 'amphora'
        }
        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        req = {
            'name': loadbalancer['name'],
            'project_id': loadbalancer['project_id'],
            'vip_address': str(loadbalancer['ip']),
            'vip_subnet_id': loadbalancer['subnet_id'],
            'provider': loadbalancer['provider'],
        }
        resp = o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy')
        lbaas.create_load_balancer.return_value = resp
        m_driver._get_vip_port.return_value = munch.Munch(
            {'id': mock.sentinel.port_id})

        ret = cls._create_loadbalancer(m_driver, loadbalancer)
        lbaas.create_load_balancer.assert_called_once_with(**req)
        self.assertIsNone(ret)
Пример #11
0
    def test_release_member(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'security_groups': [],
            'provider': None
        }

        member = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'pool_id': 'D4F35594-27EB-4F4C-930C-31DD40F53B77',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'port': 1234,
            'id': '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
        }

        cls.release_member(m_driver, loadbalancer, member)

        m_driver._release.assert_called_once_with(loadbalancer, member,
                                                  lbaas.delete_member,
                                                  member['id'],
                                                  member['pool_id'])
Пример #12
0
    def test_release_listener(self):
        os_net = self.useFixture(k_fix.MockNetworkClient()).client
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        os_net.security_group_rules.return_value = (x for x in [])
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        m_driver._get_vip_port.return_value = munch.Munch(
            {'security_group_ids': [mock.sentinel.sg_id]})
        loadbalancer = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'security_groups': [],
            'provider': 'amphora'
        }
        listener = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'loadbalancer_id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            'protocol': 'TCP',
            'port': 1234,
            'id': 'A57B7771-6050-4CA8-A63C-443493EC98AB'
        }

        cls.release_listener(m_driver, loadbalancer, listener)

        m_driver._release.assert_called_once_with(loadbalancer, listener,
                                                  lbaas.delete_listener,
                                                  listener['id'])
Пример #13
0
    def test_find_member(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = obj_lbaas.LBaaSLoadBalancer()
        member = {
            'name': 'TEST_NAME',
            'project_id': 'TEST_PROJECT',
            'pool_id': 'D4F35594-27EB-4F4C-930C-31DD40F53B77',
            'subnet_id': 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            'ip': '1.2.3.4',
            'port': 1234
        }
        member_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
        resp = iter([o_mem.Member(id=member_id)])
        lbaas.members.return_value = resp

        ret = cls._find_member(m_driver, member, loadbalancer)
        lbaas.members.assert_called_once_with(member['pool_id'],
                                              name=member['name'],
                                              project_id=member['project_id'],
                                              subnet_id=member['subnet_id'],
                                              address=member['ip'],
                                              protocol_port=member['port'])
        self.assertEqual(member, ret)
        self.assertEqual(member_id, ret['id'])
Пример #14
0
    def test_create_loadbalancer_provider_defined(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        loadbalancer = obj_lbaas.LBaaSLoadBalancer(
            name='TEST_NAME', project_id='TEST_PROJECT', ip='1.2.3.4',
            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            security_groups=[],
            provider='amphora')
        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        req = {
            'name': loadbalancer.name,
            'project_id': loadbalancer.project_id,
            'vip_address': str(loadbalancer.ip),
            'vip_subnet_id': loadbalancer.subnet_id,
            'provider': loadbalancer.provider,
        }
        resp = o_lb.LoadBalancer(id=loadbalancer_id, provider='amphora')
        lbaas.create_load_balancer.return_value = resp
        m_driver._get_vip_port.return_value = munch.Munch(
            {'id': mock.sentinel.port_id})

        ret = cls._create_loadbalancer(m_driver, loadbalancer)
        lbaas.create_load_balancer.assert_called_once_with(**req)
        for attr in loadbalancer.obj_fields:
            self.assertEqual(getattr(loadbalancer, attr),
                             getattr(ret, attr))
        self.assertEqual(loadbalancer_id, ret.id)
Пример #15
0
    def test_get_lb_by_uuid(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)

        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        loadbalancer_vip = '1.2.3.4'
        loadbalancer_vip_port_id = '00EE9E11-91C2-41CF-8FD4-7970579EFFFF'
        loadbalancer_project_id = '00EE9E11-91C2-41CF-8FD4-7970579EAAAA'
        loadbalancer_name = 'MyName'
        loadbalancer_subnet_id = '00EE9E11-91C2-41CF-8FD4-7970579EBBBB'
        loadbalancer_provider = 'haproxy'

        expected_lb = obj_lbaas.LBaaSLoadBalancer(
            id=loadbalancer_id, port_id=loadbalancer_vip_port_id,
            name=loadbalancer_name, project_id=loadbalancer_project_id,
            subnet_id=loadbalancer_subnet_id, ip=loadbalancer_vip,
            security_groups=None, provider=loadbalancer_provider)

        resp = {'loadbalancer': {'id': loadbalancer_id,
                                 'vip_port_id': loadbalancer_vip_port_id,
                                 'name': loadbalancer_name,
                                 'project_id': loadbalancer_project_id,
                                 'vip_subnet_id': loadbalancer_subnet_id,
                                 'vip_address': loadbalancer_vip,
                                 'provider': loadbalancer_provider}}

        lbaas.show_loadbalancer.return_value = resp

        ret = cls.get_lb_by_uuid(m_driver, loadbalancer_id)
        lbaas.show_loadbalancer.assert_called_once()
        for attr in expected_lb.obj_fields:
            self.assertEqual(getattr(expected_lb, attr),
                             getattr(ret, attr))
        self.assertEqual(loadbalancer_id, ret.id)
Пример #16
0
    def test_find_member(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        member = obj_lbaas.LBaaSMember(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            ip='1.2.3.4',
            port=1234,
            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            pool_id='D4F35594-27EB-4F4C-930C-31DD40F53B77')
        member_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
        resp = {'members': [{'id': member_id}]}
        lbaas.list_lbaas_members.return_value = resp

        ret = cls._find_member(m_driver, member)
        lbaas.list_lbaas_members.assert_called_once_with(
            member.pool_id,
            name=member.name,
            project_id=member.project_id,
            subnet_id=member.subnet_id,
            address=member.ip,
            protocol_port=member.port)
        for attr in member.obj_fields:
            self.assertEqual(getattr(member, attr), getattr(ret, attr))
        self.assertEqual(member_id, ret.id)
Пример #17
0
    def test_create_pool_conflict(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lb_algorithm = 'ROUND_ROBIN'
        pool = obj_lbaas.LBaaSPool(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            protocol='TCP',
            listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
            loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
        req = {
            'pool': {
                'name': pool.name,
                'project_id': pool.project_id,
                'listener_id': pool.listener_id,
                'loadbalancer_id': pool.loadbalancer_id,
                'protocol': pool.protocol,
                'lb_algorithm': lb_algorithm
            }
        }
        lbaas.create_lbaas_pool.side_effect = n_exc.StateInvalidClient

        self.assertRaises(n_exc.StateInvalidClient, cls._create_pool, m_driver,
                          pool)
        lbaas.create_lbaas_pool.assert_called_once_with(req)
        m_driver._cleanup_bogus_pool.assert_called_once_with(
            lbaas, pool, lb_algorithm)
Пример #18
0
    def test_find_pool_by_listener(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        pool = obj_lbaas.LBaaSPool(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            protocol='TCP',
            listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
            loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
        pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'
        resp = {
            'pools': [{
                'id': pool_id,
                'listeners': [{
                    'id': pool.listener_id
                }]
            }]
        }
        lbaas.list_lbaas_pools.return_value = resp

        ret = cls._find_pool(m_driver, pool)
        lbaas.list_lbaas_pools.assert_called_once_with(
            name=pool.name,
            project_id=pool.project_id,
            loadbalancer_id=pool.loadbalancer_id,
            protocol=pool.protocol)
        for attr in pool.obj_fields:
            self.assertEqual(getattr(pool, attr), getattr(ret, attr))
        self.assertEqual(pool_id, ret.id)
Пример #19
0
    def test_find_loadbalancer(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = obj_lbaas.LBaaSLoadBalancer(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            ip='1.2.3.4',
            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            provider='haproxy',
            security_groups=[])
        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        resp = {
            'loadbalancers': [{
                'id': loadbalancer_id,
                'provider': 'haproxy'
            }]
        }
        lbaas.list_loadbalancers.return_value = resp
        m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}

        ret = cls._find_loadbalancer(m_driver, loadbalancer)
        lbaas.list_loadbalancers.assert_called_once_with(
            name=loadbalancer.name,
            project_id=loadbalancer.project_id,
            vip_address=str(loadbalancer.ip),
            vip_subnet_id=loadbalancer.subnet_id)
        for attr in loadbalancer.obj_fields:
            self.assertEqual(getattr(loadbalancer, attr), getattr(ret, attr))
        self.assertEqual(loadbalancer_id, ret.id)
Пример #20
0
    def test_create_listener(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        listener = obj_lbaas.LBaaSListener(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            protocol='TCP',
            port=1234,
            loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
        listener_id = 'A57B7771-6050-4CA8-A63C-443493EC98AB'
        req = {
            'listener': {
                'name': listener.name,
                'project_id': listener.project_id,
                'loadbalancer_id': listener.loadbalancer_id,
                'protocol': listener.protocol,
                'protocol_port': listener.port
            }
        }
        resp = {'listener': {'id': listener_id}}
        lbaas.create_listener.return_value = resp

        ret = cls._create_listener(m_driver, listener)
        lbaas.create_listener.assert_called_once_with(req)
        for attr in listener.obj_fields:
            self.assertEqual(getattr(listener, attr), getattr(ret, attr))
        self.assertEqual(listener_id, ret.id)
Пример #21
0
    def test_create_l7_rule(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)

        l7_rule = obj_lbaas.LBaaSL7Rule(
            compare_type='EQUAL_TO',
            l7policy_id='D4F35594-27EB-4F4C-930C-31DD40F53B77',
            type='HOST_NAME',
            value='www.test.com')

        l7_rule_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'

        req = {
            'rule': {
                'compare_type': l7_rule.compare_type,
                'type': l7_rule.type,
                'value': l7_rule.value
            }
        }

        resp = {'rule': {'id': l7_rule_id}}
        lbaas.create_lbaas_l7rule.return_value = resp

        ret = cls._create_l7_rule(m_driver, l7_rule)
        lbaas.create_lbaas_l7rule.assert_called_once_with(
            l7_rule.l7policy_id, req)
        for attr in l7_rule.obj_fields:
            self.assertEqual(getattr(l7_rule, attr), getattr(ret, attr))
        self.assertEqual(l7_rule_id, ret.id)
Пример #22
0
    def test_create_loadbalancer_provider_mismatch(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = obj_lbaas.LBaaSLoadBalancer(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            ip='1.2.3.4',
            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
            security_groups=[],
            provider='amphora')
        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        req = {
            'loadbalancer': {
                'name': loadbalancer.name,
                'project_id': loadbalancer.project_id,
                'vip_address': str(loadbalancer.ip),
                'vip_subnet_id': loadbalancer.subnet_id,
                'provider': loadbalancer.provider,
            }
        }
        resp = {'loadbalancer': {'id': loadbalancer_id, 'provider': 'haproxy'}}
        lbaas.create_loadbalancer.return_value = resp
        m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}

        ret = cls._create_loadbalancer(m_driver, loadbalancer)
        lbaas.create_loadbalancer.assert_called_once_with(req)
        self.assertIsNone(ret)
Пример #23
0
    def test_create_l7policy(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)

        l7_policy = obj_lbaas.LBaaSL7Policy(
            name='TEST_NAME',
            project_id='TEST_PROJECT',
            listener_id='D4F35594-27EB-4F4C-930C-31DD40F53B77',
            redirect_pool_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')

        l7policy_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
        req = {
            'l7policy': {
                'action': 'REDIRECT_TO_POOL',
                'listener_id': l7_policy.listener_id,
                'name': l7_policy.name,
                'project_id': l7_policy.project_id,
                'redirect_pool_id': l7_policy.redirect_pool_id
            }
        }
        resp = {'l7policy': {'id': l7policy_id}}
        lbaas.create_lbaas_l7policy.return_value = resp

        ret = cls._create_l7_policy(m_driver, l7_policy)
        lbaas.create_lbaas_l7policy.assert_called_once_with(req)
        for attr in l7_policy.obj_fields:
            self.assertEqual(getattr(l7_policy, attr), getattr(ret, attr))
        self.assertEqual(l7policy_id, ret.id)
Пример #24
0
    def test_create_pool_with_different_lb_algorithm(self):
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        lb_algorithm = 'SOURCE_IP_PORT'
        pool = obj_lbaas.LBaaSPool(
            name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
            listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
            loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
        pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'
        req = {
            'name': pool.name,
            'project_id': pool.project_id,
            'listener_id': pool.listener_id,
            'loadbalancer_id': pool.loadbalancer_id,
            'protocol': pool.protocol,
            'lb_algorithm': lb_algorithm}
        resp = o_pool.Pool(id=pool_id)
        lbaas.create_pool.return_value = resp
        CONF.set_override('lb_algorithm', lb_algorithm,
                          group='octavia_defaults')
        self.addCleanup(CONF.clear_override, 'lb_algorithm',
                        group='octavia_defaults')

        ret = cls._create_pool(m_driver, pool)
        lbaas.create_pool.assert_called_once_with(**req)
        for attr in pool.obj_fields:
            self.assertEqual(getattr(pool, attr),
                             getattr(ret, attr))
        self.assertEqual(pool_id, ret.id)
Пример #25
0
    def test_get_pool_by_name_empty_list(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        pools = {}
        lbaas.list_lbaas_pools.return_value = {'pools': [pools]}
        pool_name = 'NOT_KUKU'
        project_id = 'TEST_PROJECT'

        pool = cls.get_pool_by_name(m_driver, pool_name, project_id)
        self.assertIsNone(pool)
Пример #26
0
    def test_release_pool(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = mock.Mock()
        pool = mock.Mock()

        cls.release_pool(m_driver, loadbalancer, pool)

        m_driver._release.assert_called_once_with(loadbalancer, pool,
                                                  lbaas.delete_pool, pool.id)
Пример #27
0
    def test_get_pool_by_name_not_found(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)

        pools = {'name': 'KUKU', 'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'}
        lbaas.list_lbaas_pools.return_value = {'pools': [pools]}
        pool_name = 'NOT_KUKU'
        project_id = 'TEST_PROJECT'

        pool_id = cls.get_pool_by_name(m_driver, pool_name, project_id)
        self.assertIsNone(pool_id)
Пример #28
0
    def test_release_member(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = mock.Mock()
        member = mock.Mock()

        cls.release_member(m_driver, loadbalancer, member)

        m_driver._release.assert_called_once_with(loadbalancer, member,
                                                  lbaas.delete_lbaas_member,
                                                  member.id, member.pool_id)
Пример #29
0
    def test_release_l7policy(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)

        loadbalancer = mock.Mock()
        l7_policy = mock.Mock()
        cls.release_l7_policy(m_driver, loadbalancer, l7_policy)

        m_driver._release.assert_called_once_with(loadbalancer, l7_policy,
                                                  lbaas.delete_lbaas_l7policy,
                                                  l7_policy.id)
Пример #30
0
    def test_release_loadbalancer(self):
        self.useFixture(k_fix.MockNeutronClient()).client
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        lbaas.cascading_capable = False
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = mock.Mock()

        cls.release_loadbalancer(m_driver, loadbalancer)

        m_driver._release.assert_called_once_with(loadbalancer, loadbalancer,
                                                  lbaas.delete_loadbalancer,
                                                  loadbalancer.id)