Exemplo n.º 1
0
    def test_get_pod_subnet(self):
        subnet_id = mock.sentinel.subnet_id
        project_id = mock.sentinel.project_id
        target_ref = {
            'kind': k_const.K8S_OBJ_POD,
            'name': 'pod-name',
            'namespace': 'default'
        }
        ip = '1.2.3.4'
        m_handler = mock.Mock(spec=h_lbaas.LoadBalancerHandler)
        m_drv_pod_project = mock.Mock()
        m_drv_pod_project.get_project.return_value = project_id
        m_handler._drv_pod_project = m_drv_pod_project
        m_drv_pod_subnets = mock.Mock()
        m_drv_pod_subnets.get_subnets.return_value = {
            subnet_id:
            osv_network.Network(subnets=osv_subnet.SubnetList(
                objects=[osv_subnet.Subnet(cidr='1.2.3.0/24')]))
        }
        m_handler._drv_pod_subnets = m_drv_pod_subnets

        observed_subnet_id = h_lbaas.LoadBalancerHandler._get_pod_subnet(
            m_handler, target_ref, ip)

        self.assertEqual(subnet_id, observed_subnet_id)
Exemplo n.º 2
0
    def test_osvif_to_neutron_fixed_ips(self):
        ip11 = '1.1.1.1'
        ip12 = '2.2.2.2'
        ip3 = '3.3.3.3'
        subnet_id_1 = uuidutils.generate_uuid()
        subnet_id_2 = uuidutils.generate_uuid()
        subnet_id_3 = uuidutils.generate_uuid()

        subnet_1 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList(objects=[
            osv_fixed_ip.FixedIP(address=ip11),
            osv_fixed_ip.FixedIP(address=ip12)
        ]))
        subnet_2 = osv_subnet.Subnet()
        subnet_3 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList(
            objects=[osv_fixed_ip.FixedIP(address=ip3)]))

        net1 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_1]))
        net2 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_2]))
        net3 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_3]))

        subnets = {subnet_id_1: net1, subnet_id_2: net2, subnet_id_3: net3}

        expected = [{
            'subnet_id': subnet_id_1,
            'ip_address': ip11
        }, {
            'subnet_id': subnet_id_1,
            'ip_address': ip12
        }, {
            'subnet_id': subnet_id_2
        }, {
            'subnet_id': subnet_id_3,
            'ip_address': ip3
        }]

        ret = ovu.osvif_to_neutron_fixed_ips(subnets)

        def _sort_key(e):
            return (e.get('subnet_id'), e.get('ip_address'))

        self.assertEqual(sorted(expected, key=_sort_key),
                         sorted(ret, key=_sort_key))
Exemplo n.º 3
0
    def test_osvif_to_neutron_fixed_ips_invalid(self):
        subnet_id = uuidutils.generate_uuid()

        subnet_1 = osv_subnet.Subnet()
        subnet_2 = osv_subnet.Subnet()

        net = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_1, subnet_2]))

        subnets = {subnet_id: net}

        self.assertRaises(k_exc.IntegrityError, ovu.osvif_to_neutron_fixed_ips,
                          subnets)
Exemplo n.º 4
0
def neutron_to_osvif_network(neutron_network):
    """Converts Neutron network to os-vif Subnet.

    :param neutron_network: dict containing network information as returned by
                            neutron client's 'show_network'
    :return: an os-vif Network object
    """

    obj = osv_network.Network(id=neutron_network['id'])

    if neutron_network.get('name') is not None:
        obj.label = neutron_network['name']

    if neutron_network.get('mtu') is not None:
        obj.mtu = neutron_network['mtu']

    return obj
Exemplo n.º 5
0
def neutron_to_osvif_network(os_network):
    """Converts Neutron network to os-vif Subnet.

    :param os_network: openstack.network.v2.netwrork.Network object.
    :return: an os-vif Network object
    """

    obj = osv_network.Network(id=os_network.id)

    if os_network.name is not None:
        obj.label = os_network.name

    if os_network.mtu is not None:
        obj.mtu = os_network.mtu

    # Vlan information will be used later in Sriov binding driver
    if os_network.provider_network_type == 'vlan':
        obj.should_provide_vlan = True
        obj.vlan = os_network.provider_segmentation_id

    return obj
Exemplo n.º 6
0
def neutron_to_osvif_network(neutron_network):
    """Converts Neutron network to os-vif Subnet.

    :param neutron_network: dict containing network information as returned by
                            neutron client's 'show_network'
    :return: an os-vif Network object
    """

    obj = osv_network.Network(id=neutron_network['id'])

    if neutron_network.get('name') is not None:
        obj.label = neutron_network['name']

    if neutron_network.get('mtu') is not None:
        obj.mtu = neutron_network['mtu']

    # Vlan information will be used later in Sriov binding driver
    if neutron_network.get('provider:network_type') == 'vlan':
        obj.should_provide_vlan = True
        obj.vlan = neutron_network['provider:segmentation_id']

    return obj
Exemplo n.º 7
0
 def _make_test_net_obj(self, cidr_list):
     subnets = [osv_subnet.Subnet(cidr=cidr) for cidr in cidr_list]
     subnets_list = osv_subnet.SubnetList(objects=subnets)
     return osv_network.Network(subnets=subnets_list)