Пример #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)
Пример #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)
Пример #3
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)
Пример #4
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)
Пример #5
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"])
Пример #6
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'])
Пример #7
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)
Пример #8
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
     )
Пример #9
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
Пример #10
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)
Пример #11
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
Пример #12
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'])
Пример #13
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")
Пример #14
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)
Пример #15
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'])
Пример #16
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"]])
Пример #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']])
Пример #18
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')
Пример #19
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"])