def test_release_vif_delete_failed(self):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        pod = mock.sentinel.pod
        vif = mock.Mock()
        vif.id = port_id

        container_mac = mock.sentinel.mac_address
        container_ip = mock.sentinel.ip_addresses
        container_port = self._get_fake_port(port_id, container_ip,
                                             container_mac)
        neutron.show_port.return_value = container_port
        neutron.delete_port.side_effect = n_exc.PortNotFoundClient

        vm_port = self._get_fake_port()
        m_driver._get_parent_port.return_value = vm_port
        m_driver._try_update_port.return_value = 0
        m_driver.lock = mock.MagicMock(spec=threading.Lock())

        cls.release_vif(m_driver, pod, vif)

        neutron.show_port.assert_called_once_with(port_id)
        m_driver._get_parent_port.assert_called_once_with(pod)
        m_driver._try_update_port.assert_called_once()
        neutron.delete_port.assert_called_once_with(vif.id)
Exemple #2
0
    def test_request_vif(self, m_to_vif):
        cls = generic_vif.GenericPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pod = mock.sentinel.pod
        project_id = mock.sentinel.project_id
        subnets = mock.sentinel.subnets
        security_groups = mock.sentinel.security_groups
        port = mock.sentinel.port
        port_request = mock.sentinel.port_request
        vif = mock.sentinel.vif
        vif_plugin = mock.sentinel.vif_plugin

        m_to_vif.return_value = vif
        m_driver._get_port_request.return_value = port_request
        m_driver._get_vif_plugin.return_value = vif_plugin
        neutron.create_port.return_value = {'port': port}

        self.assertEqual(vif, cls.request_vif(m_driver, pod, project_id,
                                              subnets, security_groups))

        m_driver._get_port_request.assert_called_once_with(
            pod, project_id, subnets, security_groups)
        neutron.create_port.assert_called_once_with(port_request)
        m_driver._get_vif_plugin.assert_called_once_with(port)
        m_to_vif.assert_called_once_with(vif_plugin, port, subnets)
Exemple #3
0
    def test_create_loadbalancer(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).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_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
        req = {
            'loadbalancer': {
                'name': loadbalancer.name,
                'project_id': loadbalancer.project_id,
                'tenant_id': loadbalancer.project_id,
                'vip_address': str(loadbalancer.ip),
                'vip_subnet_id': loadbalancer.subnet_id
            }
        }
        resp = {'loadbalancer': {'id': loadbalancer_id}}
        neutron.create_loadbalancer.return_value = resp

        ret = cls._create_loadbalancer(m_driver, loadbalancer)
        neutron.create_loadbalancer.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)
    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__precreated_ports_free(self):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
        vif_driver = mock.MagicMock(spec=cls_vif_driver)
        m_driver._drv_vif = vif_driver

        port_id = mock.sentinel.port_id
        host_addr = mock.sentinel.host_addr

        subport_obj = get_port_obj(port_id=port_id,
                                   device_owner='trunk:subport')
        m_driver._get_ports_by_attrs.side_effect = [[subport_obj], []]
        trunk_id = mock.sentinel.trunk_id
        trunk_obj = self._get_trunk_obj(port_id=trunk_id, subport_id=port_id)
        pool_key = (host_addr, subport_obj['id'],
                    tuple(subport_obj['security_groups']))
        m_driver._available_ports_pools = {pool_key: port_id}

        neutron.list_trunks.return_value = {'trunks': [trunk_obj]}
        m_driver._get_parent_port_ip.return_value = host_addr

        cls._precreated_ports(m_driver, 'free')
        neutron.list_trunks.assert_called_once()
        m_driver._get_parent_port_ip.assert_called_with(trunk_id)
        m_driver._drv_vif._remove_subport.assert_called_once()
        neutron.delete_port.assert_called_once()
        m_driver._drv_vif._release_vlan_id.assert_called_once()
Exemple #6
0
    def test_find_member(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).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}]}
        neutron.list_lbaas_members.return_value = resp

        ret = cls._find_member(m_driver, member)
        neutron.list_lbaas_members.assert_called_once_with(
            member.pool_id,
            name=member.name,
            project_id=member.project_id,
            tenant_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)
Exemple #7
0
    def test_get_subnet(self, m_osv_subnet, m_osv_network):
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        subnet = mock.MagicMock()
        network = mock.MagicMock()
        subnet_id = mock.sentinel.subnet_id
        network_id = mock.sentinel.network_id

        neutron_subnet = {'network_id': network_id}
        neutron_network = mock.sentinel.neutron_network

        neutron.show_subnet.return_value = {'subnet': neutron_subnet}
        neutron.show_network.return_value = {'network': neutron_network}

        m_osv_subnet.return_value = subnet
        m_osv_network.return_value = network

        ret = default_subnet._get_subnet(subnet_id)

        self.assertEqual(network, ret)
        neutron.show_subnet.assert_called_once_with(subnet_id)
        neutron.show_network.assert_called_once_with(network_id)
        m_osv_subnet.assert_called_once_with(neutron_subnet)
        m_osv_network.assert_called_once_with(neutron_network)
        network.subnets.objects.append.assert_called_once_with(subnet)
Exemple #8
0
    def test_create_namespace_network(self):
        cls = subnet_drv.NamespacePodSubnetDriver
        m_driver = mock.MagicMock(spec=cls)

        namespace = 'test'
        project_id = mock.sentinel.project_id
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        net = {'id': mock.sentinel.net}
        neutron.create_network.return_value = {'network': net}
        subnet = {'id': mock.sentinel.subnet, 'cidr': mock.sentinel.cidr}
        neutron.create_subnet.return_value = {'subnet': subnet}
        router_id = 'router1'
        oslo_cfg.CONF.set_override('pod_router',
                                   router_id,
                                   group='namespace_subnet')
        net_crd = {
            'netId': net['id'],
            'routerId': router_id,
            'subnetId': subnet['id'],
            'subnetCIDR': subnet['cidr']
        }

        net_crd_resp = cls.create_namespace_network(m_driver, namespace,
                                                    project_id)

        self.assertEqual(net_crd_resp, net_crd)
        neutron.create_network.assert_called_once()
        neutron.create_subnet.assert_called_once()
        neutron.add_interface_router.assert_called_once()
Exemple #9
0
    def test_request_vifs_no_vlans(self):
        cls = nested_vlan_vif.NestedVlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pod = mock.sentinel.pod
        project_id = mock.sentinel.project_id
        subnets = mock.sentinel.subnets
        security_groups = mock.sentinel.security_groups
        num_ports = 2

        parent_port = mock.sentinel.parent_port
        trunk_id = mock.sentinel.trunk_id
        port_request = mock.sentinel.port_request
        subports_info = []

        m_driver._get_parent_port.return_value = parent_port
        m_driver._get_trunk_id.return_value = trunk_id
        m_driver._create_subports_info.return_value = (port_request,
                                                       subports_info)

        self.assertEqual([],
                         cls.request_vifs(m_driver, pod, project_id, subnets,
                                          security_groups, num_ports))

        m_driver._get_parent_port.assert_called_once_with(neutron, pod)
        m_driver._get_trunk_id.assert_called_once_with(parent_port)
        m_driver._create_subports_info.assert_called_once_with(pod,
                                                               project_id,
                                                               subnets,
                                                               security_groups,
                                                               trunk_id,
                                                               num_ports,
                                                               unbound=True)
    def test_try_update_port_failure(self, aaapf_mock):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        m_driver.lock = mock.MagicMock(spec=threading.Lock())
        self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        vm_port = self._get_fake_port(port_id)['port']

        mac_addr = 'fa:16:3e:1b:30:00'
        address_pairs = [
            {
                'ip_address': '10.0.0.30',
                'mac_address': mac_addr
            },
            {
                'ip_address': 'fe80::f816:3eff:fe1c:36a9',
                'mac_address': mac_addr
            },
        ]
        vm_port['allowed_address_pairs'].extend(address_pairs)

        ip_addr = ['10.0.0.29']

        aaapf_mock.side_effect = n_exc.NeutronClientException
        self.assertRaises(n_exc.NeutronClientException, cls._try_update_port,
                          m_driver, 1, cls._add_to_allowed_address_pairs,
                          vm_port, frozenset(ip_addr), mac_addr)
    def test_request_vif_parent_not_found(self, m_to_vif):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pod = mock.sentinel.pod
        project_id = mock.sentinel.project_id
        subnets = mock.sentinel.subnets
        security_groups = mock.sentinel.security_groups
        container_mac = mock.sentinel.mac_address
        container_ip = mock.sentinel.ip_address
        container_port = self._get_fake_port(mac_address=container_mac,
                                             ip_address=container_ip)

        port_request = mock.sentinel.port_request
        m_driver._get_port_request.return_value = port_request
        m_driver.lock = mock.MagicMock(spec=threading.Lock())
        neutron.create_port.return_value = container_port
        m_driver._get_parent_port.side_effect = n_exc.NeutronClientException

        self.assertRaises(n_exc.NeutronClientException, cls.request_vif,
                          m_driver, pod, project_id, subnets, security_groups)
        m_driver._get_port_request.assert_called_once_with(
            pod, project_id, subnets, security_groups)
        neutron.create_port.assert_not_called()
        m_driver._get_parent_port.assert_called_once_with(pod)
        m_driver._try_update_port.assert_not_called()
        m_to_vif.assert_not_called()
    def test_remove_from_allowed_address_pairs_no_update(self, m_mac):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        vm_port = self._get_fake_port(port_id)['port']

        mac_addr = 'fa:16:3e:1b:30:00' if m_mac else vm_port['mac_address']
        address_pairs = [
            {
                'ip_address': '10.0.0.30',
                'mac_address': mac_addr
            },
            {
                'ip_address': 'fe80::f816:3eff:fe1c:36a9',
                'mac_address': mac_addr
            },
        ]
        vm_port['allowed_address_pairs'].extend(address_pairs)

        ip_addr = ['10.0.0.29']

        cls._remove_from_allowed_address_pairs(m_driver, vm_port,
                                               frozenset(ip_addr), m_mac)

        m_driver._update_port_address_pairs.assert_not_called()
    def test_add_to_allowed_address_pairs_already_present(self):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        vm_port = self._get_fake_port(port_id)['port']
        address_pairs = [
            {
                'ip_address': '10.0.0.30',
                'mac_address': 'fa:16:3e:1b:30:00'
            },
            {
                'ip_address': 'fe80::f816:3eff:fe1c:36a9',
                'mac_address': 'fa:16:3e:1b:30:00'
            },
        ]
        vm_port['allowed_address_pairs'].extend(address_pairs)

        mac_addr = 'fa:16:3e:1b:30:00'
        ip_addr = '10.0.0.30'

        self.assertRaises(k_exc.AllowedAddressAlreadyPresent,
                          cls._add_to_allowed_address_pairs, m_driver, vm_port,
                          frozenset([ip_addr]), mac_addr)
    def test_add_to_allowed_address_pairs_same_ip(self):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        vm_port = self._get_fake_port(port_id)['port']
        address_pairs = [
            {
                'ip_address': '10.0.0.30',
                'mac_address': 'fa:16:3e:1b:30:00'
            },
            {
                'ip_address': 'fe80::f816:3eff:fe1c:36a9',
                'mac_address': 'fa:16:3e:1b:30:00'
            },
        ]
        vm_port['allowed_address_pairs'].extend(address_pairs)

        mac_addr = 'fa:16:3e:71:cb:80'
        ip_addr = '10.0.0.30'
        address_pairs.append({'ip_address': ip_addr, 'mac_address': mac_addr})

        cls._add_to_allowed_address_pairs(m_driver, vm_port,
                                          frozenset([ip_addr]), mac_addr)

        m_driver._update_port_address_pairs.assert_called_once_with(
            port_id, address_pairs, revision_number=1)
Exemple #15
0
    def test_create_pool_conflict(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).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,
                'tenant_id': pool.project_id,
                'listener_id': pool.listener_id,
                'loadbalancer_id': pool.loadbalancer_id,
                'protocol': pool.protocol,
                'lb_algorithm': lb_algorithm
            }
        }
        neutron.create_lbaas_pool.side_effect = n_exc.StateInvalidClient

        self.assertRaises(n_exc.StateInvalidClient, cls._create_pool, m_driver,
                          pool)
        neutron.create_lbaas_pool.assert_called_once_with(req)
        m_driver._cleanup_bogus_pool.assert_called_once_with(
            neutron, pool, lb_algorithm)
    def test__get_port_from_pool_pool_populate(self, m_eventlet):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pool_key = mock.sentinel.pool_key
        port_id = mock.sentinel.port_id
        port = mock.sentinel.port
        subnets = mock.sentinel.subnets

        pod = get_pod_obj()

        m_driver._available_ports_pools = {
            pool_key: collections.deque([port_id])}
        m_driver._existing_vifs = {port_id: port}

        oslo_cfg.CONF.set_override('ports_pool_min',
                                   5,
                                   group='vif_pool')
        pool_length = 3
        m_driver._get_pool_size.return_value = pool_length

        self.assertEqual(port, cls._get_port_from_pool(
            m_driver, pool_key, pod, subnets))

        neutron.update_port.assert_called_once_with(
            port_id,
            {
                "port": {
                    'name': pod['metadata']['name'],
                }
            })
        m_eventlet.assert_called_once()
Exemple #17
0
    def test_find_pool(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).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
                }]
            }]
        }
        neutron.list_lbaas_pools.return_value = resp

        ret = cls._find_pool(m_driver, pool)
        neutron.list_lbaas_pools.assert_called_once_with(
            name=pool.name,
            project_id=pool.project_id,
            tenant_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)
    def test__return_ports_to_pool_update_exception(self, m_sleep):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pool_key = ('node_ip', 'project_id', tuple(['security_group']))
        port_id = mock.sentinel.port_id
        pool_length = 5

        m_driver._recyclable_ports = {port_id: pool_key}
        m_driver._available_ports_pools = {}
        oslo_cfg.CONF.set_override('ports_pool_max',
                                   0,
                                   group='vif_pool')
        m_driver._get_pool_size.return_value = pool_length
        neutron.update_port.side_effect = n_exc.NeutronClientException

        self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)

        neutron.update_port.assert_called_once_with(
            port_id,
            {
                "port": {
                    'name': 'available-port',
                    'security_groups': ['security_group']
                }
            })
        neutron.delete_port.assert_not_called()
Exemple #19
0
    def test_ensure_loadbalancer(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        cls = d_lbaasv2.LBaaSv2Driver
        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
        expected_resp = obj_lbaas.LBaaSLoadBalancer(
            provider='octavia',
            port_id='D3FA400A-F543-4B91-9CD3-047AF0CE42E2',
            security_groups=[])
        project_id = 'TEST_PROJECT'
        subnet_id = 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1'
        ip = '1.2.3.4'
        sg_ids = ['foo', 'bar']
        lb_name = 'just_a_name'

        m_driver._ensure.return_value = expected_resp
        neutron.update_port = mock.Mock()
        resp = cls.ensure_loadbalancer(m_driver, lb_name, project_id,
                                       subnet_id, ip, sg_ids, 'ClusterIP')
        m_driver._ensure.assert_called_once_with(mock.ANY,
                                                 m_driver._create_loadbalancer,
                                                 m_driver._find_loadbalancer)
        req = m_driver._ensure.call_args[0][0]
        self.assertEqual(lb_name, req.name)
        self.assertEqual(project_id, req.project_id)
        self.assertEqual(subnet_id, req.subnet_id)
        self.assertEqual(ip, str(req.ip))
        self.assertEqual(expected_resp, resp)
        neutron.update_port.assert_not_called()
    def test__return_ports_to_pool_delete_key_error(self, m_sleep):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
        vif_driver = mock.MagicMock(spec=cls_vif_driver)
        m_driver._drv_vif = vif_driver

        pool_key = ('node_ip', 'project_id', tuple(['security_group']))
        port_id = mock.sentinel.port_id
        pool_length = 10
        p_port = mock.sentinel.p_port
        trunk_id = mock.sentinel.trunk_id

        m_driver._recyclable_ports = {port_id: pool_key}
        m_driver._available_ports_pools = {}
        m_driver._existing_vifs = {}
        oslo_cfg.CONF.set_override('ports_pool_max',
                                   5,
                                   group='vif_pool')
        m_driver._get_pool_size.return_value = pool_length
        m_driver._known_trunk_ids = {}
        m_driver._drv_vif._get_parent_port_by_host_ip.return_value = p_port
        m_driver._drv_vif._get_trunk_id.return_value = trunk_id

        self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)

        neutron.update_port.assert_not_called()
        m_driver._drv_vif._get_parent_port_by_host_ip.assert_called_once()
        m_driver._drv_vif._get_trunk_id.assert_called_once_with(p_port)
        m_driver._drv_vif._remove_subport.assert_called_once_with(neutron,
                                                                  trunk_id,
                                                                  port_id)
        neutron.delete_port.assert_not_called()
    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))
Exemple #22
0
    def test_find_listener(self):
        neutron = self.useFixture(k_fix.MockNeutronClient()).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'
        resp = {'listeners': [{'id': listener_id}]}
        neutron.list_listeners.return_value = resp

        ret = cls._find_listener(m_driver, listener)
        neutron.list_listeners.assert_called_once_with(
            name=listener.name,
            project_id=listener.project_id,
            tenant_id=listener.project_id,
            loadbalancer_id=listener.loadbalancer_id,
            protocol=listener.protocol,
            protocol_port=listener.port)
        for attr in listener.obj_fields:
            self.assertEqual(getattr(listener, attr), getattr(ret, attr))
        self.assertEqual(listener_id, ret.id)
    def test_release_vif_parent_not_found(self):
        cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        port_id = lib_utils.get_hash()
        pod = mock.sentinel.pod
        vif = mock.Mock()
        vif.id = port_id

        container_mac = mock.sentinel.mac_address
        container_ip = mock.sentinel.ip_address
        container_port = self._get_fake_port(port_id, container_ip,
                                             container_mac)
        neutron.show_port.return_value = container_port

        m_driver.lock = mock.MagicMock(spec=threading.Lock())
        m_driver._get_parent_port.side_effect = n_exc.NeutronClientException

        self.assertRaises(n_exc.NeutronClientException, cls.release_vif,
                          m_driver, pod, vif)
        neutron.show_port.assert_called_with(port_id)
        self.assertEqual(neutron.show_port.call_count, 1)
        m_driver._get_parent_port.assert_called_with(pod)
        self.assertEqual(m_driver._get_parent_port.call_count, 1)
        m_driver._remove_from_allowed_address_pairs.assert_not_called()
        neutron.delete_port.assert_not_called()
    def test_disassociate_neutron_exception(self):
        cls = d_public_ip.FipPubIpDriver
        m_driver = mock.Mock(spec=cls)
        res_id = mock.sentinel.res_id

        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        neutron.update_floatingip.side_effect = n_exc.NeutronClientException
        self.assertIsNone(cls.disassociate(m_driver, res_id))
Exemple #25
0
 def test_get_parent_port_subnet_id_not_configured(self):
     cls = nested_vlan_vif.NestedVlanPodVIFDriver
     m_driver = mock.Mock(spec=cls)
     neutron = self.useFixture(k_fix.MockNeutronClient()).client
     nested_vlan_vif.config.CONF.neutron_defaults.worker_nodes_subnet = ''
     pod = mock.MagicMock()
     self.assertRaises(oslo_cfg.RequiredOptError, cls._get_parent_port,
                       m_driver, neutron, pod)
    def test_request_vifs(self, m_to_vif):
        cls = nested_vlan_vif.NestedVlanPodVIFDriver
        m_driver = mock.Mock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        pod = mock.sentinel.pod
        project_id = mock.sentinel.project_id
        subnets = mock.sentinel.subnets
        security_groups = mock.sentinel.security_groups
        num_ports = 2

        parent_port = mock.sentinel.parent_port
        trunk_id = mock.sentinel.trunk_id
        port_request = mock.sentinel.port_request
        subports_info = [{
            'segmentation_id': 1,
            'port_id': '',
            'segmentation_type': 'vlan'
        }, {
            'segmentation_id': 2,
            'port_id': '',
            'segmentation_type': 'vlan'
        }]
        port = {'id': mock.sentinel.id}
        vif = mock.sentinel.vif

        bulk_rq = {'ports': [port_request for _ in range(len(subports_info))]}

        m_driver._get_parent_port.return_value = parent_port
        m_driver._get_trunk_id.return_value = trunk_id
        m_driver._create_subports_info.return_value = (port_request,
                                                       subports_info)
        neutron.create_port.return_value = {'ports': [port, port]}
        m_to_vif.return_value = vif

        self.assertEqual([vif, vif],
                         cls.request_vifs(m_driver, pod, project_id, subnets,
                                          security_groups, num_ports))

        m_driver._get_parent_port.assert_called_once_with(neutron, pod)
        m_driver._get_trunk_id.assert_called_once_with(parent_port)
        m_driver._create_subports_info.assert_called_once_with(pod,
                                                               project_id,
                                                               subnets,
                                                               security_groups,
                                                               trunk_id,
                                                               num_ports,
                                                               unbound=True)
        neutron.create_port.assert_called_once_with(bulk_rq)
        neutron.trunk_add_subports.assert_called_once_with(
            trunk_id, {'sub_ports': subports_info})
        neutron.delete_port.assert_not_called()

        calls = [
            mock.call(port, subnets, info['segmentation_id'])
            for info in subports_info
        ]
        m_to_vif.assert_has_calls(calls)
    def test_disassociate_succeeded(self):
        cls = d_public_ip.FipPubIpDriver
        m_driver = mock.Mock(spec=cls)
        res_id = mock.sentinel.res_id

        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        neutron.update_floatingip.return_value = None

        self.assertIsNone(cls.disassociate(m_driver, res_id))
    def test_free_ip_neutron_exception(self):
        cls = d_public_ip.FipPubIpDriver
        m_driver = mock.Mock(spec=cls)
        res_id = mock.sentinel.res_id

        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        neutron.delete_floatingip.side_effect = n_exc.NeutronClientException
        rc = cls.free_ip(m_driver, res_id)
        self.assertEqual(rc, False)
    def test_delete_sg(self):
        cls = namespace_security_groups.NamespacePodSecurityGroupsDriver
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        sg_id = mock.sentinel.sg_id

        cls.delete_sg(m_driver, sg_id)
        neutron.delete_security_group.assert_called_once_with(sg_id)
    def test__precreated_ports_no_ports(self, m_action):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        m_driver._get_ports_by_attrs.return_value = []

        cls._precreated_ports(m_driver, m_action)
        neutron.list_trunks.assert_not_called()