Пример #1
0
 def test_plug_lrouter_port_patch_attachment(self):
     tenant_id = 'pippo'
     transport_zones_config = [{
         'zone_uuid': _uuid(),
         'transport_type': 'stt'
     }]
     lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(),
                                        tenant_id, 'fake-switch',
                                        transport_zones_config)
     lport = switchlib.create_lport(self.fake_cluster, lswitch['uuid'],
                                    tenant_id, 'xyz', 'name', 'device_id',
                                    True)
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        tenant_id, 'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                  lrouter['uuid'], 'pippo',
                                                  'neutron_port_id', 'name',
                                                  True, ['192.168.0.1'],
                                                  '00:11:22:33:44:55:66')
     result = routerlib.plug_router_port_attachment(self.fake_cluster,
                                                    lrouter['uuid'],
                                                    lrouter_port['uuid'],
                                                    lport['uuid'],
                                                    'PatchAttachment')
     self.assertEqual(lport['uuid'],
                      result['LogicalPortAttachment']['peer_port_uuid'])
Пример #2
0
    def test_update_lrouter_port(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(), 'pippo',
                                           'fake-lrouter', '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                     lrouter['uuid'], 'pippo',
                                                     'neutron_port_id', 'name',
                                                     True, ['192.168.0.1'],
                                                     '00:11:22:33:44:55')
        routerlib.update_router_lport(self.fake_cluster, lrouter['uuid'],
                                      lrouter_port['uuid'], 'pippo',
                                      'another_port_id', 'name', False,
                                      ['192.168.0.1', '10.10.10.254'])

        ports = routerlib.query_lrouter_lports(self.fake_cluster,
                                               lrouter['uuid'])
        self.assertEqual(len(ports), 1)
        res_port = ports[0]
        port_tags = self._build_tag_dict(res_port['tags'])
        self.assertEqual(['192.168.0.1', '10.10.10.254'],
                         res_port['ip_addresses'])
        self.assertEqual('False', res_port['admin_status_enabled'])
        self.assertIn('os_tid', port_tags)
        self.assertIn('q_port_id', port_tags)
        self.assertEqual('pippo', port_tags['os_tid'])
        self.assertEqual('another_port_id', port_tags['q_port_id'])
Пример #3
0
    def test_update_lrouter_port(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(),
                                           'pippo',
                                           'fake-lrouter',
                                           '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(
            self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
            'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
        routerlib.update_router_lport(
            self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
            'pippo', 'another_port_id', 'name', False,
            ['192.168.0.1', '10.10.10.254'])

        ports = routerlib.query_lrouter_lports(
            self.fake_cluster, lrouter['uuid'])
        self.assertEqual(len(ports), 1)
        res_port = ports[0]
        port_tags = self._build_tag_dict(res_port['tags'])
        self.assertEqual(['192.168.0.1', '10.10.10.254'],
                         res_port['ip_addresses'])
        self.assertEqual('False', res_port['admin_status_enabled'])
        self.assertIn('os_tid', port_tags)
        self.assertIn('q_port_id', port_tags)
        self.assertEqual('pippo', port_tags['os_tid'])
        self.assertEqual('another_port_id', port_tags['q_port_id'])
Пример #4
0
 def test_plug_lrouter_port_patch_attachment(self):
     tenant_id = 'pippo'
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(self.fake_cluster,
                                        _uuid(),
                                        tenant_id, 'fake-switch',
                                        transport_zones_config)
     lport = switchlib.create_lport(self.fake_cluster, lswitch['uuid'],
                                    tenant_id, 'xyz',
                                    'name', 'device_id', True)
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        tenant_id,
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
         'name', True, ['192.168.0.1'], '00:11:22:33:44:55:66')
     result = routerlib.plug_router_port_attachment(
         self.fake_cluster, lrouter['uuid'],
         lrouter_port['uuid'],
         lport['uuid'], 'PatchAttachment')
     self.assertEqual(lport['uuid'],
                      result['LogicalPortAttachment']['peer_port_uuid'])
Пример #5
0
 def test_plug_lrouter_port_invalid_attachment_type_raises(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
         'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
     self.assertRaises(nsx_exc.InvalidAttachmentType,
                       routerlib.plug_router_port_attachment,
                       self.fake_cluster, lrouter['uuid'],
                       lrouter_port['uuid'], 'gw_att', 'BadType')
Пример #6
0
 def test_plug_lrouter_port_invalid_attachment_type_raises(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(), 'pippo',
                                        'fake-lrouter', '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                  lrouter['uuid'], 'pippo',
                                                  'neutron_port_id', 'name',
                                                  True, ['192.168.0.1'],
                                                  '00:11:22:33:44:55')
     self.assertRaises(nsx_exc.InvalidAttachmentType,
                       routerlib.plug_router_port_attachment,
                       self.fake_cluster, lrouter['uuid'],
                       lrouter_port['uuid'], 'gw_att', 'BadType')
Пример #7
0
 def test_update_lrouter_port_ips_remove_only(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(), 'pippo',
                                        'fake-lrouter', '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
         'name', True, ['192.168.0.1', '10.10.10.254'], '00:11:22:33:44:55')
     routerlib.update_lrouter_port_ips(self.fake_cluster, lrouter['uuid'],
                                       lrouter_port['uuid'], [],
                                       ['10.10.10.254'])
     ports = routerlib.query_lrouter_lports(self.fake_cluster,
                                            lrouter['uuid'])
     self.assertEqual(len(ports), 1)
     res_port = ports[0]
     self.assertEqual(['192.168.0.1'], res_port['ip_addresses'])
Пример #8
0
 def test_query_lrouter_ports(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     router_port_uuids = [routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo',
         'qp_id_%s' % k, 'port-%s' % k, True,
         ['192.168.0.%s' % k], '00:11:22:33:44:55')['uuid']
         for k in range(3)]
     ports = routerlib.query_lrouter_lports(
         self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(ports), 3)
     for res_port in ports:
         self.assertIn(res_port['uuid'], router_port_uuids)
Пример #9
0
 def test_plug_lrouter_port_l3_gw_attachment(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
         'name', True, ['192.168.0.1'], '00:11:22:33:44:55:66')
     result = routerlib.plug_router_port_attachment(
         self.fake_cluster, lrouter['uuid'],
         lrouter_port['uuid'],
         'gw_att', 'L3GatewayAttachment')
     self.assertEqual(
         'gw_att',
         result['LogicalPortAttachment']['l3_gateway_service_uuid'])
Пример #10
0
 def test_plug_lrouter_port_l3_gw_attachment_with_vlan(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(), 'pippo',
                                        'fake-lrouter', '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                  lrouter['uuid'], 'pippo',
                                                  'neutron_port_id', 'name',
                                                  True, ['192.168.0.1'],
                                                  '00:11:22:33:44:55')
     result = routerlib.plug_router_port_attachment(
         self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'], 'gw_att',
         'L3GatewayAttachment', 123)
     self.assertEqual(
         'gw_att',
         result['LogicalPortAttachment']['l3_gateway_service_uuid'])
     self.assertEqual('123', result['LogicalPortAttachment']['vlan_id'])
Пример #11
0
 def test_query_lrouter_ports(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     router_port_uuids = [routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo',
         'qp_id_%s' % k, 'port-%s' % k, True,
         ['192.168.0.%s' % k], '00:11:22:33:44:55')['uuid']
         for k in range(3)]
     ports = routerlib.query_lrouter_lports(
         self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(ports), 3)
     for res_port in ports:
         self.assertIn(res_port['uuid'], router_port_uuids)
Пример #12
0
 def test_delete_lrouter_port(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(), 'pippo',
                                        'fake-lrouter', '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                  lrouter['uuid'], 'pippo',
                                                  'x', 'y', True, [],
                                                  '00:11:22:33:44:55')
     ports = routerlib.query_lrouter_lports(self.fake_cluster,
                                            lrouter['uuid'])
     self.assertEqual(len(ports), 1)
     routerlib.delete_router_lport(self.fake_cluster, lrouter['uuid'],
                                   lrouter_port['uuid'])
     ports = routerlib.query_lrouter_lports(self.fake_cluster,
                                            lrouter['uuid'])
     self.assertFalse(len(ports))
Пример #13
0
 def test_delete_lrouter_port(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, [],
         '00:11:22:33:44:55')
     ports = routerlib.query_lrouter_lports(
         self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(ports), 1)
     routerlib.delete_router_lport(self.fake_cluster, lrouter['uuid'],
                                   lrouter_port['uuid'])
     ports = routerlib.query_lrouter_lports(
         self.fake_cluster, lrouter['uuid'])
     self.assertFalse(len(ports))
Пример #14
0
 def test_update_lrouter_port_ips_add_and_remove(self):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter_port = routerlib.create_router_lport(
         self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
         'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
     routerlib.update_lrouter_port_ips(
         self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
         ['10.10.10.254'], ['192.168.0.1'])
     ports = routerlib.query_lrouter_lports(
         self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(ports), 1)
     res_port = ports[0]
     self.assertEqual(['10.10.10.254'], res_port['ip_addresses'])
Пример #15
0
    def test_update_lrouter_port_ips_nsx_exception_raises(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(), 'pippo',
                                           'fake-lrouter', '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(self.fake_cluster,
                                                     lrouter['uuid'], 'pippo',
                                                     'neutron_port_id', 'name',
                                                     True, ['192.168.0.1'],
                                                     '00:11:22:33:44:55')

        def raise_nsx_exc(*args, **kwargs):
            raise api_exc.NsxApiException()

        with mock.patch.object(routerlib, 'do_request', new=raise_nsx_exc):
            self.assertRaises(nsx_exc.NsxPluginException,
                              routerlib.update_lrouter_port_ips,
                              self.fake_cluster, lrouter['uuid'],
                              lrouter_port['uuid'], [], [])
Пример #16
0
    def test_delete_peer_lrouter_port(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(),
                                           'pippo',
                                           'fake-lrouter',
                                           '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(
            self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, [],
            '00:11:22:33:44:55')

        def fakegetport(*args, **kwargs):
            return {'_relations': {'LogicalPortAttachment':
                                   {'peer_port_uuid': lrouter_port['uuid']}}}
        # mock get_port
        with mock.patch.object(switchlib, 'get_port', new=fakegetport):
            routerlib.delete_peer_router_lport(self.fake_cluster,
                                               lrouter_port['uuid'],
                                               'whatwever', 'whatever')
Пример #17
0
    def test_update_lrouter_port_ips_nsx_exception_raises(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(),
                                           'pippo',
                                           'fake-lrouter',
                                           '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(
            self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
            'name', True, ['192.168.0.1'], '00:11:22:33:44:55')

        def raise_nsx_exc(*args, **kwargs):
            raise api_exc.NsxApiException()

        with mock.patch.object(nsxlib, 'do_request', new=raise_nsx_exc):
            self.assertRaises(
                nsx_exc.NsxPluginException, routerlib.update_lrouter_port_ips,
                self.fake_cluster, lrouter['uuid'],
                lrouter_port['uuid'], [], [])
Пример #18
0
    def test_delete_peer_lrouter_port(self):
        lrouter = routerlib.create_lrouter(self.fake_cluster,
                                           uuidutils.generate_uuid(),
                                           'pippo',
                                           'fake-lrouter',
                                           '10.0.0.1')
        lrouter_port = routerlib.create_router_lport(
            self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, [],
            '00:11:22:33:44:55')

        def fakegetport(*args, **kwargs):
            return {'_relations': {'LogicalPortAttachment':
                                   {'peer_port_uuid': lrouter_port['uuid']}}}
        # mock get_port
        with mock.patch.object(routerlib, 'get_port', new=fakegetport):
            routerlib.delete_peer_router_lport(self.fake_cluster,
                                               lrouter_port['uuid'],
                                               'whatwever', 'whatever')