"Fossies" - the Fresh Open Source Software Archive

Member "neutron-14.0.3/neutron/tests/unit/objects/test_router.py" (22 Oct 2019, 5850 Bytes) of package /linux/misc/openstack/neutron-14.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_router.py": 14.0.2_vs_15.0.0.

    1 # Copyright (c) 2016 Intel Corporation.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 from oslo_utils import uuidutils
   16 
   17 from neutron.objects import router
   18 from neutron.tests.unit.objects import test_base as obj_test_base
   19 from neutron.tests.unit import testlib_api
   20 
   21 
   22 class RouterRouteIfaceObjectTestCase(
   23     obj_test_base.BaseObjectIfaceTestCase):
   24 
   25     _test_class = router.RouterRoute
   26 
   27 
   28 class RouterRouteDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
   29                                   testlib_api.SqlTestCase):
   30 
   31     _test_class = router.RouterRoute
   32 
   33     def setUp(self):
   34         super(RouterRouteDbObjectTestCase, self).setUp()
   35         self.update_obj_fields(
   36             {'router_id': lambda: self._create_test_router_id()})
   37 
   38 
   39 class RouterExtraAttrsIfaceObjTestCase(obj_test_base.
   40                                        BaseObjectIfaceTestCase):
   41     _test_class = router.RouterExtraAttributes
   42 
   43 
   44 class RouterExtraAttrsDbObjTestCase(obj_test_base.BaseDbObjectTestCase,
   45                                     testlib_api.SqlTestCase):
   46     _test_class = router.RouterExtraAttributes
   47 
   48     def setUp(self):
   49         super(RouterExtraAttrsDbObjTestCase, self).setUp()
   50         self.update_obj_fields(
   51             {'router_id': lambda: self._create_test_router_id()})
   52 
   53 
   54 class RouterIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase):
   55 
   56     _test_class = router.Router
   57 
   58 
   59 class RouterDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
   60                              testlib_api.SqlTestCase):
   61 
   62     _test_class = router.Router
   63 
   64     def setUp(self):
   65         super(RouterDbObjectTestCase, self).setUp()
   66         self.update_obj_fields(
   67             {'gw_port_id': lambda: self._create_test_port_id(),
   68              'flavor_id': lambda: self._create_test_flavor_id()})
   69 
   70     def _create_router(self, router_id, gw_port_id, project_id):
   71         r = router.Router(self.context,
   72                           id=router_id,
   73                           gw_port_id=gw_port_id,
   74                           project_id=project_id)
   75         r.create()
   76 
   77     def test_check_routers_not_owned_by_projects(self):
   78         for obj in self.obj_fields:
   79             self._create_router(router_id=obj['id'],
   80                                 gw_port_id=obj['gw_port_id'],
   81                                 project_id=obj['project_id'])
   82         obj = self.obj_fields[0]
   83 
   84         gw_port = obj['gw_port_id']
   85         project = obj['project_id']
   86         new_project = project
   87 
   88         gw_port_no_match = uuidutils.generate_uuid()
   89         project_no_match = uuidutils.generate_uuid()
   90         new_project_no_match = uuidutils.generate_uuid()
   91 
   92         # Check router match with gw_port BUT no projects
   93         router_exist = router.Router.check_routers_not_owned_by_projects(
   94             self.context,
   95             [gw_port],
   96             [project_no_match, new_project_no_match])
   97         self.assertTrue(router_exist)
   98 
   99         # Check router doesn't match with gw_port
  100         router_exist = router.Router.check_routers_not_owned_by_projects(
  101             self.context,
  102             [gw_port_no_match],
  103             [project])
  104         self.assertFalse(router_exist)
  105 
  106         # Check router match with gw_port AND project
  107         router_exist = router.Router.check_routers_not_owned_by_projects(
  108             self.context,
  109             [gw_port],
  110             [project, new_project_no_match])
  111         self.assertFalse(router_exist)
  112 
  113         # Check router match with gw_port AND new project
  114         router_exist = router.Router.check_routers_not_owned_by_projects(
  115             self.context,
  116             [gw_port],
  117             [project_no_match, new_project])
  118         self.assertFalse(router_exist)
  119 
  120         # Check router match with gw_port AND project AND new project
  121         router_exist = router.Router.check_routers_not_owned_by_projects(
  122             self.context,
  123             [gw_port],
  124             [project, new_project])
  125         self.assertFalse(router_exist)
  126 
  127 
  128 class RouterPortIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase):
  129 
  130     _test_class = router.RouterPort
  131 
  132 
  133 class RouterPortDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
  134                                  testlib_api.SqlTestCase):
  135 
  136     _test_class = router.RouterPort
  137 
  138     def setUp(self):
  139         super(RouterPortDbObjectTestCase, self).setUp()
  140         self.update_obj_fields(
  141             {'router_id': lambda: self._create_test_router_id(),
  142              'port_id': lambda: self._create_test_port_id()})
  143 
  144 
  145 class DVRMacAddressIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase):
  146 
  147     _test_class = router.DVRMacAddress
  148 
  149 
  150 class DVRMacAddressDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
  151                                     testlib_api.SqlTestCase):
  152 
  153     _test_class = router.DVRMacAddress
  154 
  155 
  156 class FloatingIPIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase):
  157 
  158     _test_class = router.FloatingIP
  159 
  160 
  161 class FloatingIPDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
  162                                  testlib_api.SqlTestCase):
  163 
  164     _test_class = router.FloatingIP
  165 
  166     def setUp(self):
  167         super(FloatingIPDbObjectTestCase, self).setUp()
  168         self.update_obj_fields(
  169             {'floating_port_id': lambda: self._create_test_port_id(),
  170              'fixed_port_id': lambda: self._create_test_port_id(),
  171              'router_id': lambda: self._create_test_router_id()})