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 = iter([o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy',
                                       provisioning_status='ACTIVE')])
        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)
        for attr in loadbalancer.obj_fields:
            self.assertEqual(getattr(loadbalancer, attr),
                             getattr(ret, attr))
        self.assertEqual(loadbalancer_id, ret.id)
        m_driver.release_loadbalancer.assert_not_called()
Exemple #2
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 = {
            '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='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)
        self.assertEqual(loadbalancer, ret)
        self.assertEqual(loadbalancer_id, ret['id'])
    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 = 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='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)
Exemple #4
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()
Exemple #5
0
 def test_make_it(self):
     test_load_balancer = load_balancer.LoadBalancer(**EXAMPLE)
     self.assertTrue(test_load_balancer.is_admin_state_up)
     self.assertEqual(EXAMPLE['created_at'], test_load_balancer.created_at),
     self.assertEqual(EXAMPLE['description'],
                      test_load_balancer.description)
     self.assertEqual(EXAMPLE['flavor'], test_load_balancer.flavor)
     self.assertEqual(EXAMPLE['id'], test_load_balancer.id)
     self.assertEqual(EXAMPLE['listeners'], test_load_balancer.listeners)
     self.assertEqual(EXAMPLE['name'], test_load_balancer.name)
     self.assertEqual(EXAMPLE['operating_status'],
                      test_load_balancer.operating_status)
     self.assertEqual(EXAMPLE['pools'], test_load_balancer.pools)
     self.assertEqual(EXAMPLE['project_id'], test_load_balancer.project_id)
     self.assertEqual(EXAMPLE['provider'], test_load_balancer.provider)
     self.assertEqual(EXAMPLE['provisioning_status'],
                      test_load_balancer.provisioning_status)
     self.assertEqual(EXAMPLE['updated_at'], test_load_balancer.updated_at),
     self.assertEqual(EXAMPLE['vip_address'],
                      test_load_balancer.vip_address)
     self.assertEqual(EXAMPLE['vip_network_id'],
                      test_load_balancer.vip_network_id)
     self.assertEqual(EXAMPLE['vip_port_id'],
                      test_load_balancer.vip_port_id)
     self.assertEqual(EXAMPLE['vip_subnet_id'],
                      test_load_balancer.vip_subnet_id)
    def test_create_loadbalancer_provider_defined(self):
        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 = {
            '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')
        m_driver._post_lb_resource.return_value = resp
        m_driver._get_vip_port.return_value = munch.Munch(
            {'id': mock.sentinel.port_id})

        ret = cls._create_loadbalancer(m_driver, loadbalancer)
        m_driver._post_lb_resource.assert_called_once_with(
            o_lb.LoadBalancer, req)
        for attr in loadbalancer.obj_fields:
            self.assertEqual(getattr(loadbalancer, attr), getattr(ret, attr))
        self.assertEqual(loadbalancer_id, ret.id)
Exemple #7
0
 def test_basic(self):
     test_load_balancer = load_balancer.LoadBalancer()
     self.assertEqual('loadbalancer', test_load_balancer.resource_key)
     self.assertEqual('loadbalancers', test_load_balancer.resources_key)
     self.assertEqual('/lbaas/loadbalancers', test_load_balancer.base_path)
     self.assertTrue(test_load_balancer.allow_create)
     self.assertTrue(test_load_balancer.allow_fetch)
     self.assertTrue(test_load_balancer.allow_delete)
     self.assertTrue(test_load_balancer.allow_list)
     self.assertTrue(test_load_balancer.allow_commit)
Exemple #8
0
 def test_basic(self):
     test_load_balancer = load_balancer.LoadBalancer()
     self.assertEqual('loadbalancer', test_load_balancer.resource_key)
     self.assertEqual('loadbalancers', test_load_balancer.resources_key)
     self.assertEqual('/loadbalancers', test_load_balancer.base_path)
     self.assertEqual('load_balancer',
                      test_load_balancer.service.service_type)
     self.assertTrue(test_load_balancer.allow_create)
     self.assertTrue(test_load_balancer.allow_get)
     self.assertTrue(test_load_balancer.allow_delete)
     self.assertTrue(test_load_balancer.allow_list)
    def test_make_it(self):
        test_load_balancer = load_balancer.LoadBalancer(**EXAMPLE)
        self.assertTrue(test_load_balancer.is_admin_state_up)
        self.assertEqual(EXAMPLE['availability_zone'],
                         test_load_balancer.availability_zone)
        self.assertEqual(EXAMPLE['created_at'], test_load_balancer.created_at)
        self.assertEqual(EXAMPLE['description'],
                         test_load_balancer.description)
        self.assertEqual(EXAMPLE['flavor_id'], test_load_balancer.flavor_id)
        self.assertEqual(EXAMPLE['id'], test_load_balancer.id)
        self.assertEqual(EXAMPLE['listeners'], test_load_balancer.listeners)
        self.assertEqual(EXAMPLE['name'], test_load_balancer.name)
        self.assertEqual(EXAMPLE['operating_status'],
                         test_load_balancer.operating_status)
        self.assertEqual(EXAMPLE['pools'], test_load_balancer.pools)
        self.assertEqual(EXAMPLE['project_id'], test_load_balancer.project_id)
        self.assertEqual(EXAMPLE['provider'], test_load_balancer.provider)
        self.assertEqual(EXAMPLE['provisioning_status'],
                         test_load_balancer.provisioning_status)
        self.assertEqual(EXAMPLE['updated_at'], test_load_balancer.updated_at)
        self.assertEqual(EXAMPLE['vip_address'],
                         test_load_balancer.vip_address)
        self.assertEqual(EXAMPLE['vip_network_id'],
                         test_load_balancer.vip_network_id)
        self.assertEqual(EXAMPLE['vip_port_id'],
                         test_load_balancer.vip_port_id)
        self.assertEqual(EXAMPLE['vip_subnet_id'],
                         test_load_balancer.vip_subnet_id)
        self.assertEqual(EXAMPLE['vip_qos_policy_id'],
                         test_load_balancer.vip_qos_policy_id)

        self.assertDictEqual(
            {'limit': 'limit',
             'marker': 'marker',
             'availability_zone': 'availability_zone',
             'description': 'description',
             'flavor_id': 'flavor_id',
             'name': 'name',
             'project_id': 'project_id',
             'provider': 'provider',
             'operating_status': 'operating_status',
             'provisioning_status': 'provisioning_status',
             'is_admin_state_up': 'admin_state_up',
             'vip_address': 'vip_address',
             'vip_network_id': 'vip_network_id',
             'vip_port_id': 'vip_port_id',
             'vip_subnet_id': 'vip_subnet_id',
             'vip_qos_policy_id': 'vip_qos_policy_id',
             'tags': 'tags',
             'any_tags': 'tags-any',
             'not_tags': 'not-tags',
             'not_any_tags': 'not-tags-any',
             },
            test_load_balancer._query_mapping._mapping)
Exemple #10
0
    def test_wait_for_provisioning(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = mock.Mock()
        timeout = mock.sentinel.timeout
        timer = [mock.sentinel.t0, mock.sentinel.t1]
        m_driver._provisioning_timer.return_value = timer
        resp = o_lb.LoadBalancer(provisioning_status='ACTIVE')
        lbaas.get_load_balancer.return_value = resp

        cls._wait_for_provisioning(m_driver, loadbalancer, timeout)

        lbaas.get_load_balancer.assert_called_once_with(loadbalancer.id)
Exemple #11
0
    def test_wait_for_provisioning_not_ready(self):
        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        loadbalancer = mock.Mock()
        timeout = mock.sentinel.timeout
        timer = [mock.sentinel.t0, mock.sentinel.t1]
        m_driver._provisioning_timer.return_value = timer
        resp = o_lb.LoadBalancer(provisioning_status='NOT_ACTIVE')
        lbaas.get_load_balancer.return_value = resp

        self.assertRaises(k_exc.ResourceNotReady, cls._wait_for_provisioning,
                          m_driver, loadbalancer, timeout)

        self.assertEqual(len(timer), lbaas.get_load_balancer.call_count)
Exemple #12
0
    def test_delete_cascade(self):
        sess = mock.Mock()
        resp = mock.Mock()
        sess.delete.return_value = resp

        sot = load_balancer.LoadBalancer(**EXAMPLE)
        sot.cascade = True
        sot._translate_response = mock.Mock()
        sot.delete(sess)

        url = 'lbaas/loadbalancers/%(lb)s' % {'lb': EXAMPLE['id']}
        headers = {'Accept': ''}
        params = {'cascade': True}
        sess.delete.assert_called_with(url, headers=headers, params=params)
        sot._translate_response.assert_called_once_with(
            resp,
            error_message=None,
            has_body=False,
        )
Exemple #13
0
    def test_wait_for_provisioning(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,
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        }
        timeout = mock.sentinel.timeout
        timer = [mock.sentinel.t0, mock.sentinel.t1]
        m_driver._provisioning_timer.return_value = timer
        resp = o_lb.LoadBalancer(provisioning_status='ACTIVE')
        lbaas.get_load_balancer.return_value = resp

        cls._wait_for_provisioning(m_driver, loadbalancer, timeout)

        lbaas.get_load_balancer.assert_called_once_with(loadbalancer['id'])
Exemple #14
0
    def test_wait_for_provisioning_not_ready(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,
            'id': '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        }
        timeout = mock.sentinel.timeout
        timer = [mock.sentinel.t0, mock.sentinel.t1]
        m_driver._provisioning_timer.return_value = timer
        resp = o_lb.LoadBalancer(provisioning_status='NOT_ACTIVE')
        lbaas.get_load_balancer.return_value = resp

        self.assertRaises(k_exc.ResourceNotReady, cls._wait_for_provisioning,
                          m_driver, loadbalancer, timeout)

        self.assertEqual(len(timer), lbaas.get_load_balancer.call_count)