Esempio n. 1
0
 def test_create_and_get_lswitches_multiple(self):
     tenant_id = 'pippo'
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     network_id = _uuid()
     main_lswitch = switchlib.create_lswitch(
         self.fake_cluster, network_id,
         tenant_id, 'fake-switch', transport_zones_config,
         tags=[{'scope': 'multi_lswitch', 'tag': 'True'}])
     # Create secondary lswitch
     second_lswitch = switchlib.create_lswitch(
         self.fake_cluster, network_id,
         tenant_id, 'fake-switch-2', transport_zones_config)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           network_id)
     self.assertEqual(len(res_lswitch), 2)
     switch_uuids = [ls['uuid'] for ls in res_lswitch]
     self.assertIn(main_lswitch['uuid'], switch_uuids)
     self.assertIn(second_lswitch['uuid'], switch_uuids)
     for ls in res_lswitch:
         if ls['uuid'] == main_lswitch['uuid']:
             main_ls = ls
         else:
             second_ls = ls
     main_ls_tags = self._build_tag_dict(main_ls['tags'])
     second_ls_tags = self._build_tag_dict(second_ls['tags'])
     self.assertIn('multi_lswitch', main_ls_tags)
     self.assertNotIn('multi_lswitch', second_ls_tags)
     self.assertIn('quantum_net_id', main_ls_tags)
     self.assertIn('quantum_net_id', second_ls_tags)
     self.assertEqual(main_ls_tags['quantum_net_id'],
                      network_id)
     self.assertEqual(second_ls_tags['quantum_net_id'],
                      network_id)
Esempio n. 2
0
 def test_get_port_by_tag_not_find_wildcard_lswitch_returns_none(self):
     tenant_id = 'pippo'
     neutron_port_id = 'whatever'
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     switchlib.create_lswitch(
         self.fake_cluster, tenant_id, _uuid(),
         'fake-switch', transport_zones_config)
     lport = switchlib.get_port_by_neutron_tag(
         self.fake_cluster, '*', neutron_port_id)
     self.assertIsNone(lport)
Esempio n. 3
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'])
Esempio n. 4
0
    def create_network_precommit(self, context):
        """Add a network to NSX

        This method does not handle provider networks correctly and
        is out-of-scope for now.
        """
        net_data = context.current

        if net_data['admin_state_up'] is False:
             LOG.warning(_("Network with admin_state_up=False are not yet "
                           "supported by this plugin. Ignoring setting for "
                           "network %s"), net_data.get('name', '<unknown>'))

        transport_zone_config = self._convert_to_transport_zones(net_data)

        nsx_switch = switchlib.create_lswitch(
            self.cluster,
            net_data['id'],
            net_data['tenant_id'],
            net_data.get('name'),
            transport_zone_config,
            shared=bool(net_data.get('shared'))
        )

        nsx_db.add_neutron_nsx_network_mapping(
           context._plugin_context.session,
           net_data['id'],
           nsx_switch['uuid']
        )
Esempio n. 5
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'])
Esempio n. 6
0
 def test_delete_networks(self):
     transport_zones_config = [{
         'zone_uuid': _uuid(),
         'transport_type': 'stt'
     }]
     lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(), 'pippo',
                                        'fake-switch',
                                        transport_zones_config)
     switchlib.delete_networks(self.fake_cluster, lswitch['uuid'],
                               [lswitch['uuid']])
     self.assertRaises(exceptions.NotFound, switchlib.get_lswitches,
                       self.fake_cluster, lswitch['uuid'])
Esempio n. 7
0
 def test_get_port_by_tag_not_found_with_switch_id_raises_not_found(self):
     tenant_id = 'pippo'
     neutron_port_id = 'whatever'
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(
         self.fake_cluster, tenant_id, _uuid(),
         'fake-switch', transport_zones_config)
     self.assertRaises(exceptions.NotFound,
                       switchlib.get_port_by_neutron_tag,
                       self.fake_cluster, lswitch['uuid'],
                       neutron_port_id)
Esempio n. 8
0
 def _create_switch_and_port(self, tenant_id='pippo',
                             neutron_port_id='whatever',
                             name='name', device_id='device_id'):
     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, neutron_port_id,
                                    name, device_id, True)
     return lswitch, lport
Esempio n. 9
0
 def test_create_and_get_lswitches_single(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)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['uuid'], lswitch['uuid'])
Esempio n. 10
0
 def test_delete_networks(self):
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(self.fake_cluster,
                                        _uuid(),
                                        'pippo',
                                        'fake-switch',
                                        transport_zones_config)
     switchlib.delete_networks(self.fake_cluster, lswitch['uuid'],
                               [lswitch['uuid']])
     self.assertRaises(exceptions.NotFound,
                       switchlib.get_lswitches,
                       self.fake_cluster,
                       lswitch['uuid'])
Esempio n. 11
0
 def test_create_and_get_lswitches_single_name_exceeds_40_chars(self):
     tenant_id = 'pippo'
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(self.fake_cluster,
                                        tenant_id,
                                        _uuid(),
                                        '*' * 50,
                                        transport_zones_config)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['uuid'], lswitch['uuid'])
     self.assertEqual(res_lswitch[0]['display_name'], '*' * 40)
Esempio n. 12
0
 def test_create_and_get_lswitches_single(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)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['uuid'],
                      lswitch['uuid'])
Esempio n. 13
0
 def test_create_and_get_lswitches_single_name_exceeds_40_chars(self):
     tenant_id = 'pippo'
     transport_zones_config = [{
         'zone_uuid': _uuid(),
         'transport_type': 'stt'
     }]
     lswitch = switchlib.create_lswitch(self.fake_cluster, tenant_id,
                                        _uuid(), '*' * 50,
                                        transport_zones_config)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['uuid'], lswitch['uuid'])
     self.assertEqual(res_lswitch[0]['display_name'], '*' * 40)
Esempio n. 14
0
 def test_update_lswitch(self):
     new_name = 'new-name'
     new_tags = [{'scope': 'new_tag', 'tag': 'xxx'}]
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(self.fake_cluster,
                                        _uuid(),
                                        'pippo',
                                        'fake-switch',
                                        transport_zones_config)
     switchlib.update_lswitch(self.fake_cluster, lswitch['uuid'],
                              new_name, tags=new_tags)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['display_name'], new_name)
     switch_tags = self._build_tag_dict(res_lswitch[0]['tags'])
     self.assertIn('new_tag', switch_tags)
     self.assertEqual(switch_tags['new_tag'], 'xxx')
Esempio n. 15
0
 def _test_update_lswitch(self, tenant_id, name, tags):
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(self.fake_cluster,
                                        _uuid(),
                                        'pippo',
                                        'fake-switch',
                                        transport_zones_config)
     switchlib.update_lswitch(self.fake_cluster, lswitch['uuid'],
                              name, tenant_id=tenant_id, tags=tags)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['display_name'], name)
     if not tags:
         # no need to validate tags
         return
     switch_tags = self._build_tag_dict(res_lswitch[0]['tags'])
     for tag in tags:
         self.assertIn(tag['scope'], switch_tags)
         self.assertEqual(tag['tag'], switch_tags[tag['scope']])
Esempio n. 16
0
 def test_plug_l2_gw_port_attachment(self):
     tenant_id = 'pippo'
     node_uuid = _uuid()
     transport_zones_config = [{'zone_uuid': _uuid(),
                                'transport_type': 'stt'}]
     lswitch = switchlib.create_lswitch(
         self.fake_cluster, _uuid(), tenant_id,
         'fake-switch', transport_zones_config)
     gw_id = self._create_gw_service(node_uuid, 'fake-gw')['uuid']
     lport = switchlib.create_lport(
         self.fake_cluster, lswitch['uuid'], tenant_id, _uuid(),
         'fake-gw-port', gw_id, True)
     l2gwlib.plug_l2_gw_service(
         self.fake_cluster, lswitch['uuid'],
         lport['uuid'], gw_id)
     uri = nsxlib._build_uri_path(switchlib.LSWITCHPORT_RESOURCE,
                                  lport['uuid'],
                                  lswitch['uuid'],
                                  is_attachment=True)
     resp_obj = nsxlib.do_request("GET", uri,
                                  cluster=self.fake_cluster)
     self.assertIn('LogicalPortAttachment', resp_obj)
     self.assertEqual(resp_obj['LogicalPortAttachment']['type'],
                      'L2GatewayAttachment')
Esempio n. 17
0
 def _test_update_lswitch(self, tenant_id, name, tags):
     transport_zones_config = [{
         'zone_uuid': _uuid(),
         'transport_type': 'stt'
     }]
     lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(), 'pippo',
                                        'fake-switch',
                                        transport_zones_config)
     switchlib.update_lswitch(self.fake_cluster,
                              lswitch['uuid'],
                              name,
                              tenant_id=tenant_id,
                              tags=tags)
     res_lswitch = switchlib.get_lswitches(self.fake_cluster,
                                           lswitch['uuid'])
     self.assertEqual(len(res_lswitch), 1)
     self.assertEqual(res_lswitch[0]['display_name'], name)
     if not tags:
         # no need to validate tags
         return
     switch_tags = self._build_tag_dict(res_lswitch[0]['tags'])
     for tag in tags:
         self.assertIn(tag['scope'], switch_tags)
         self.assertEqual(tag['tag'], switch_tags[tag['scope']])