def test_acquire_service_pub_ip_info_usr_specified_ip(self): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() neutron = self.useFixture(k_fix.MockNeutronClient()).client floating_ip = { 'floating_ip_address': '1.2.3.4', 'port_id': None, 'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b' } neutron.list_floatingips.return_value = {'floatingips': [floating_ip]} project_id = mock.sentinel.project_id spec_type = 'LoadBalancer' spec_lb_ip = '1.2.3.4' expected_resp = \ obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'], ip_addr=floating_ip['floating_ip_address'], alloc_method='user') self.assertEqual( expected_resp, cls.acquire_service_pub_ip_info(m_driver, spec_type, spec_lb_ip, project_id))
def test_acquire_service_pub_ip_info_alloc_from_pool(self, m_cfg): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() neutron = self.useFixture(k_fix.MockNeutronClient()).client m_cfg.neutron_defaults.external_svc_subnet =\ mock.sentinel.external_svc_subnet neutron.show_subnet.return_value =\ {'subnet': {'network_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'}} floating_ip = { 'floating_ip_address': '1.2.3.5', 'id': 'ec29d641-fec4-4f67-928a-124a76b3a888' } neutron.create_floatingip.return_value = {'floatingip': floating_ip} project_id = mock.sentinel.project_id spec_type = 'LoadBalancer' spec_lb_ip = None expected_resp = \ obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'], ip_addr=floating_ip['floating_ip_address'], alloc_method='pool') self.assertEqual( expected_resp, cls.acquire_service_pub_ip_info(m_driver, spec_type, spec_lb_ip, project_id))
def test_acquire_service_pub_ip_info_clusterip(self): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() project_id = mock.sentinel.project_id cur_service_pub_ip_info = None service = {'spec': {'type': 'ClusterIP'}} self.assertIsNone( cls.acquire_service_pub_ip_info(m_driver, service, project_id, cur_service_pub_ip_info))
def test_acquire_service_pub_ip_info_user_specified_non_exist_fip(self): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() neutron = self.useFixture(k_fix.MockNeutronClient()).client floating_ip = {'floating_ip_address': '1.2.3.5', 'port_id': None} neutron.list_floatingips.return_value = {'floatingips': [floating_ip]} project_id = mock.sentinel.project_id spec_type = 'LoadBalancer' spec_lb_ip = '1.2.3.4' self.assertIsNone( cls.acquire_service_pub_ip_info(m_driver, spec_type, spec_lb_ip, project_id))
def test_disassociate_pub_ip_neutron_exception(self): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() neutron = self.useFixture(k_fix.MockNeutronClient()).client neutron.update_floatingip.side_effect = n_exc.NeutronClientException floating_ip = { 'floating_ip_address': '1.2.3.5', 'id': 'ec29d641-fec4-4f67-928a-124a76b3a888' } service_pub_ip_info = \ obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'], ip_addr=floating_ip['floating_ip_address'], alloc_method='pool') self.assertRaises(n_exc.NeutronClientException, cls.disassociate_pub_ip, m_driver, service_pub_ip_info)
def test_disassociate_pub_ip_fip_id_not_exist(self): cls = d_lb_public_ip.FloatingIpServicePubIPDriver m_driver = mock.Mock(spec=cls) m_driver._drv_pub_ip = public_ip.FipPubIpDriver() neutron = self.useFixture(k_fix.MockNeutronClient()).client neutron.update_floatingip.return_value = None floating_ip = { 'floating_ip_address': '1.2.3.5', 'id': 'ec29d641-fec4-4f67-928a-124a76b3a888' } service_pub_ip_info = \ obj_lbaas.LBaaSPubIp(ip_id=0, ip_addr=floating_ip['floating_ip_address'], alloc_method='pool') self.assertIsNone( cls.disassociate_pub_ip(m_driver, service_pub_ip_info))
def __init__(self): super(FloatingIpServicePubIPDriver, self).__init__() self._drv_pub_ip = public_ip.FipPubIpDriver()