コード例 #1
0
 def test_post_network_plug_with_host_routes(self):
     SUBNET_ID = 'SUBNET_ID'
     FIXED_IP1 = '192.0.2.2'
     FIXED_IP2 = '192.0.2.3'
     SUBNET_CIDR = '192.0.2.0/24'
     DEST1 = '198.51.100.0/24'
     DEST2 = '203.0.113.0/24'
     NEXTHOP = '192.0.2.1'
     host_routes = [
         network_models.HostRoute(destination=DEST1, nexthop=NEXTHOP),
         network_models.HostRoute(destination=DEST2, nexthop=NEXTHOP)
     ]
     subnet = network_models.Subnet(id=SUBNET_ID,
                                    cidr=SUBNET_CIDR,
                                    ip_version=4,
                                    host_routes=host_routes)
     fixed_ips = [
         network_models.FixedIP(subnet_id=subnet.id,
                                ip_address=FIXED_IP1,
                                subnet=subnet),
         network_models.FixedIP(subnet_id=subnet.id,
                                ip_address=FIXED_IP2,
                                subnet=subnet)
     ]
     port = network_models.Port(mac_address=FAKE_MAC_ADDRESS,
                                fixed_ips=fixed_ips,
                                network=self.network)
     self.driver.post_network_plug(self.amp, port)
     expected_fixed_ips = [{
         'ip_address':
         FIXED_IP1,
         'subnet_cidr':
         SUBNET_CIDR,
         'host_routes': [{
             'destination': DEST1,
             'nexthop': NEXTHOP
         }, {
             'destination': DEST2,
             'nexthop': NEXTHOP
         }]
     }, {
         'ip_address':
         FIXED_IP2,
         'subnet_cidr':
         SUBNET_CIDR,
         'host_routes': [{
             'destination': DEST1,
             'nexthop': NEXTHOP
         }, {
             'destination': DEST2,
             'nexthop': NEXTHOP
         }]
     }]
     self.driver.client.plug_network.assert_called_once_with(
         self.amp,
         dict(mac_address=FAKE_MAC_ADDRESS,
              fixed_ips=expected_fixed_ips,
              mtu=FAKE_MTU))
コード例 #2
0
    def create_port(self,
                    network_id,
                    name=None,
                    fixed_ips=(),
                    secondary_ips=(),
                    security_group_ids=(),
                    admin_state_up=True,
                    qos_policy_id=None):
        LOG.debug("Network %s no-op, create_port network_id %s",
                  self.__class__.__name__, network_id)
        if not name:
            name = 'no-op-port'
        port_id = uuidutils.generate_uuid()
        project_id = uuidutils.generate_uuid()

        fixed_ip_obj_list = []
        for fixed_ip in fixed_ips:
            if fixed_ip and not fixed_ip.get('ip_address'):
                fixed_ip_obj_list.append(
                    network_models.FixedIP(subnet_id=fixed_ip.get('subnet_id'),
                                           ip_address='198.51.100.56'))
            else:
                fixed_ip_obj_list.append(
                    network_models.FixedIP(
                        subnet_id=fixed_ip.get('subnet_id'),
                        ip_address=fixed_ip.get('ip_address')))
        if not fixed_ip_obj_list:
            fixed_ip_obj_list = [
                network_models.FixedIP(subnet_id=uuidutils.generate_uuid(),
                                       ip_address='198.51.100.56')
            ]

        self.networkconfigconfig[(network_id,
                                  'create_port')] = (network_id, name,
                                                     fixed_ip_obj_list,
                                                     secondary_ips,
                                                     security_group_ids,
                                                     admin_state_up,
                                                     qos_policy_id)
        return network_models.Port(id=port_id,
                                   name=name,
                                   device_id='no-op-device-id',
                                   device_owner='Octavia',
                                   mac_address='00:00:5E:00:53:05',
                                   network_id=network_id,
                                   status='UP',
                                   project_id=project_id,
                                   admin_state_up=admin_state_up,
                                   fixed_ips=fixed_ip_obj_list,
                                   qos_policy_id=qos_policy_id,
                                   security_group_ids=security_group_ids)
コード例 #3
0
    def _port_to_parent_port(self, port):
        fixed_ips = [
            n_data_models.FixedIP(subnet_id=fixed_ip.get('subnet_id'),
                                  ip_address=fixed_ip.get('ip_address'))
            for fixed_ip in port.get('fixed_ips', [])
        ]

        trunk_id = port['trunk_details']['trunk_id'] if port.get(
            'trunk_details') else None
        subports = port['trunk_details']['sub_ports'] if port.get(
            'trunk_details') else None
        subport_list = []
        if subports:
            subport_list = [
                data_models.Subport(
                    segmentation_id=subport['segmentation_id'],
                    port_id=subport['port_id'],
                    segmentation_type=subport['segmentation_type'],
                    mac_address=subport['mac_address']) for subport in subports
            ]
        return data_models.ParentPort(
            id=port.get('id'),
            name=port.get('name'),
            device_id=port.get('device_id'),
            device_owner=port.get('device_owner'),
            mac_address=port.get('mac_address'),
            network_id=port.get('network_id'),
            status=port.get('status'),
            project_id=port.get('project_id'),
            admin_state_up=port.get('admin_state_up'),
            fixed_ips=fixed_ips,
            qos_policy_id=port.get('qos_policy_id'),
            trunk_id=trunk_id,
            subports=subport_list)
コード例 #4
0
    def execute(self, amphora, ports):
        """Execute post_network_plug routine."""
        db_amp = self.amphora_repo.get(db_apis.get_session(),
                                       id=amphora[constants.ID])

        for port in ports:
            net = data_models.Network(**port.pop(constants.NETWORK))
            ips = port.pop(constants.FIXED_IPS)
            fixed_ips = []
            for ip in ips:
                subnet_arg = ip.pop(constants.SUBNET)
                host_routes = subnet_arg.get('host_routes')
                if host_routes:
                    subnet_arg['host_routes'] = [
                        data_models.HostRoute(**hr)
                        for hr in host_routes
                    ]
                fixed_ips.append(data_models.FixedIP(
                    subnet=data_models.Subnet(**subnet_arg), **ip))
            self.amphora_driver.post_network_plug(
                db_amp, data_models.Port(network=net, fixed_ips=fixed_ips,
                                         **port))

            LOG.debug("post_network_plug called on compute instance "
                      "%(compute_id)s for port %(port_id)s",
                      {"compute_id": amphora[constants.COMPUTE_ID],
                       "port_id": port[constants.ID]})
コード例 #5
0
 def test_get_interfaces_to_unplug(self):
     if1 = network_models.Interface()
     if1.network_id = 'if1-net'
     if1.port_id = 'if1-port'
     if1.fixed_ips = [network_models.FixedIP(ip_address='10.0.0.1')]
     if2 = network_models.Interface()
     if2.network_id = 'if2-net'
     if2.port_id = 'if2-port'
     if2.fixed_ips = [network_models.FixedIP(ip_address='11.0.0.1')]
     interfaces = [if1, if2]
     unpluggers = self.driver._get_interfaces_to_unplug(
         interfaces, 'if1-net')
     self.assertEqual([if1], unpluggers)
     unpluggers = self.driver._get_interfaces_to_unplug(
         interfaces, 'if1-net', ip_address='10.0.0.1')
     self.assertEqual([if1], unpluggers)
     unpluggers = self.driver._get_interfaces_to_unplug(
         interfaces, 'if1-net', ip_address='11.0.0.1')
     self.assertEqual([], unpluggers)
     unpluggers = self.driver._get_interfaces_to_unplug(
         interfaces, 'if3-net')
     self.assertEqual([], unpluggers)
コード例 #6
0
def convert_port_dict_to_model(port_dict):
    port = port_dict.get('port', port_dict)
    fixed_ips = [network_models.FixedIP(subnet_id=fixed_ip.get('subnet_id'),
                                        ip_address=fixed_ip.get('ip_address'))
                 for fixed_ip in port.get('fixed_ips', [])]
    return network_models.Port(
        id=port.get('id'),
        name=port.get('name'),
        device_id=port.get('device_id'),
        device_owner=port.get('device_owner'),
        mac_address=port.get('mac_address'),
        network_id=port.get('network_id'),
        status=port.get('status'),
        project_id=port.get('tenant_id'),
        admin_state_up=port.get('admin_state_up'),
        fixed_ips=fixed_ips
    )
コード例 #7
0
ファイル: utils.py プロジェクト: zongzw/octavia
def convert_port_dict_to_model(port_dict):
    port = port_dict.get('port', port_dict)
    fixed_ips = [
        network_models.FixedIP(subnet_id=fixed_ip.get('subnet_id'),
                               ip_address=fixed_ip.get('ip_address'))
        for fixed_ip in port.get('fixed_ips', [])
    ]
    return network_models.Port(id=port.get(constants.ID),
                               name=port.get(constants.NAME),
                               device_id=port.get('device_id'),
                               device_owner=port.get('device_owner'),
                               mac_address=port.get('mac_address'),
                               network_id=port.get('network_id'),
                               status=port.get('status'),
                               project_id=port.get(constants.TENANT_ID),
                               admin_state_up=port.get('admin_state_up'),
                               fixed_ips=fixed_ips,
                               qos_policy_id=port.get('qos_policy_id'),
                               security_group_ids=port.get(
                                   constants.SECURITY_GROUPS, []))
コード例 #8
0
ファイル: utils.py プロジェクト: zongzw/octavia
def convert_fixed_ip_dict_to_model(fixed_ip_dict):
    fixed_ip = fixed_ip_dict.get('fixed_ip', fixed_ip_dict)
    return network_models.FixedIP(subnet_id=fixed_ip.get('subnet_id'),
                                  ip_address=fixed_ip.get('ip_address'))
コード例 #9
0
from a10_octavia.controller.worker.tasks import a10_database_tasks as task
from a10_octavia.tests.common import a10constants
from a10_octavia.tests.unit import base

VTHUNDER = data_models.VThunder()
HW_THUNDER = data_models.HardwareThunder(
    project_id=a10constants.MOCK_PROJECT_ID,
    device_name="rack_thunder_1",
    undercloud=True,
    username="******",
    password="******",
    ip_address="10.10.10.10",
    partition_name="shared")
LB = o_data_models.LoadBalancer(id=a10constants.MOCK_LOAD_BALANCER_ID,
                                flavor_id=a10constants.MOCK_FLAVOR_ID)
FIXED_IP = n_data_models.FixedIP(ip_address='10.10.10.10')
PORT = n_data_models.Port(id=uuidutils.generate_uuid(), fixed_ips=[FIXED_IP])
VRID = data_models.VRID(id=1,
                        vrid=0,
                        owner=a10constants.MOCK_PROJECT_ID,
                        vrid_port_id=uuidutils.generate_uuid(),
                        vrid_floating_ip='10.0.12.32')
LISTENER = o_data_models.Listener(id=a10constants.MOCK_LISTENER_ID,
                                  load_balancer=LB)
POOL = o_data_models.Pool(id=a10constants.MOCK_POOL_ID, load_balancer=LB)
HM = o_data_models.HealthMonitor(id=a10constants, pool=POOL)
MEMBER_1 = o_data_models.Member(id=uuidutils.generate_uuid(),
                                project_id=a10constants.MOCK_PROJECT_ID,
                                subnet_id=a10constants.MOCK_SUBNET_ID,
                                pool=POOL)
MEMBER_2 = o_data_models.Member(id=uuidutils.generate_uuid(),