"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/tests/unit/test_backend_templated.py" (13 May 2020, 14023 Bytes) of package /linux/misc/openstack/keystone-17.0.0.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 latest Fossies "Diffs" side-by-side code changes report for "test_backend_templated.py": 16.0.1_vs_17.0.0.

    1 # Copyright 2012 OpenStack Foundation
    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 unittest import mock
   16 import uuid
   17 
   18 from keystone.catalog.backends import base as catalog_base
   19 from keystone.common import provider_api
   20 from keystone.tests import unit
   21 from keystone.tests.unit.catalog import test_backends as catalog_tests
   22 from keystone.tests.unit import default_fixtures
   23 from keystone.tests.unit.ksfixtures import database
   24 
   25 
   26 PROVIDERS = provider_api.ProviderAPIs
   27 BROKEN_WRITE_FUNCTIONALITY_MSG = ("Templated backend doesn't correctly "
   28                                   "implement write operations")
   29 
   30 
   31 class TestTemplatedCatalog(unit.TestCase, catalog_tests.CatalogTests):
   32 
   33     DEFAULT_FIXTURE = {
   34         'RegionOne': {
   35             'compute': {
   36                 'adminURL': 'http://localhost:8774/v1.1/bar',
   37                 'publicURL': 'http://localhost:8774/v1.1/bar',
   38                 'internalURL': 'http://localhost:8774/v1.1/bar',
   39                 'name': "'Compute Service'",
   40                 'id': '2'
   41             },
   42             'identity': {
   43                 'adminURL': 'http://localhost:35357/v3',
   44                 'publicURL': 'http://localhost:5000/v3',
   45                 'internalURL': 'http://localhost:35357/v3',
   46                 'name': "'Identity Service'",
   47                 'id': '1'
   48             }
   49         }
   50     }
   51 
   52     def setUp(self):
   53         super(TestTemplatedCatalog, self).setUp()
   54         self.useFixture(database.Database())
   55         self.load_backends()
   56         self.load_fixtures(default_fixtures)
   57 
   58     def config_overrides(self):
   59         super(TestTemplatedCatalog, self).config_overrides()
   60         self.config_fixture.config(
   61             group='catalog',
   62             driver='templated',
   63             template_file=unit.dirs.tests('default_catalog.templates'))
   64 
   65     def test_get_catalog(self):
   66         catalog_ref = PROVIDERS.catalog_api.get_catalog('foo', 'bar')
   67         self.assertDictEqual(self.DEFAULT_FIXTURE, catalog_ref)
   68 
   69     # NOTE(lbragstad): This test is skipped because the catalog is being
   70     # modified within the test and not through the API.
   71     @unit.skip_if_cache_is_enabled('catalog')
   72     def test_catalog_ignored_malformed_urls(self):
   73         # both endpoints are in the catalog
   74         catalog_ref = PROVIDERS.catalog_api.get_catalog('foo', 'bar')
   75         self.assertEqual(2, len(catalog_ref['RegionOne']))
   76 
   77         region = PROVIDERS.catalog_api.driver.templates['RegionOne']
   78         region['compute']['adminURL'] = 'http://localhost:8774/v1.1/$(tenant)s'
   79 
   80         # the malformed one has been removed
   81         catalog_ref = PROVIDERS.catalog_api.get_catalog('foo', 'bar')
   82         self.assertEqual(1, len(catalog_ref['RegionOne']))
   83 
   84     def test_get_v3_catalog_endpoint_disabled(self):
   85         self.skip_test_overrides(
   86             "Templated backend doesn't have disabled endpoints")
   87 
   88     def assert_catalogs_equal(self, expected, observed):
   89         def sort_key(d):
   90             return d['id']
   91         for e, o in zip(sorted(expected, key=sort_key),
   92                         sorted(observed, key=sort_key)):
   93             expected_endpoints = e.pop('endpoints')
   94             observed_endpoints = o.pop('endpoints')
   95             self.assertDictEqual(e, o)
   96             self.assertItemsEqual(expected_endpoints, observed_endpoints)
   97 
   98     def test_get_v3_catalog(self):
   99         user_id = uuid.uuid4().hex
  100         project_id = uuid.uuid4().hex
  101         catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(user_id, project_id)
  102         exp_catalog = [
  103             {'endpoints': [
  104                 {'interface': 'admin',
  105                  'region': 'RegionOne',
  106                  'url': 'http://localhost:8774/v1.1/%s' % project_id},
  107                 {'interface': 'public',
  108                  'region': 'RegionOne',
  109                  'url': 'http://localhost:8774/v1.1/%s' % project_id},
  110                 {'interface': 'internal',
  111                  'region': 'RegionOne',
  112                  'url': 'http://localhost:8774/v1.1/%s' % project_id}],
  113              'type': 'compute',
  114              'name': "'Compute Service'",
  115              'id': '2'},
  116             {'endpoints': [
  117                 {'interface': 'admin',
  118                  'region': 'RegionOne',
  119                  'url': 'http://localhost:35357/v3'},
  120                 {'interface': 'public',
  121                  'region': 'RegionOne',
  122                  'url': 'http://localhost:5000/v3'},
  123                 {'interface': 'internal',
  124                  'region': 'RegionOne',
  125                  'url': 'http://localhost:35357/v3'}],
  126              'type': 'identity',
  127              'name': "'Identity Service'",
  128              'id': '1'}]
  129         self.assert_catalogs_equal(exp_catalog, catalog_ref)
  130 
  131     def test_get_multi_region_v3_catalog(self):
  132         user_id = uuid.uuid4().hex
  133         project_id = uuid.uuid4().hex
  134 
  135         catalog_api = PROVIDERS.catalog_api
  136 
  137         # Load the multi-region catalog.
  138         catalog_api._load_templates(
  139             unit.dirs.tests('default_catalog_multi_region.templates'))
  140 
  141         catalog_ref = catalog_api.get_v3_catalog(user_id, project_id)
  142         exp_catalog = [
  143             {'endpoints': [
  144                 {'interface': 'admin',
  145                  'region': 'RegionOne',
  146                  'url': 'http://region-one:8774/v1.1/%s' % project_id},
  147                 {'interface': 'public',
  148                  'region': 'RegionOne',
  149                  'url': 'http://region-one:8774/v1.1/%s' % project_id},
  150                 {'interface': 'internal',
  151                  'region': 'RegionOne',
  152                  'url': 'http://region-one:8774/v1.1/%s' % project_id},
  153                 {'interface': 'admin',
  154                  'region': 'RegionTwo',
  155                  'url': 'http://region-two:8774/v1.1/%s' % project_id},
  156                 {'interface': 'public',
  157                  'region': 'RegionTwo',
  158                  'url': 'http://region-two:8774/v1.1/%s' % project_id},
  159                 {'interface': 'internal',
  160                  'region': 'RegionTwo',
  161                  'url': 'http://region-two:8774/v1.1/%s' % project_id}],
  162                 'type': 'compute',
  163                 'name': "'Compute Service'",
  164                 'id': '2'},
  165             {'endpoints': [
  166                 {'interface': 'admin',
  167                  'region': 'RegionOne',
  168                  'url': 'http://region-one:35357/v3'},
  169                 {'interface': 'public',
  170                  'region': 'RegionOne',
  171                  'url': 'http://region-one:5000/v3'},
  172                 {'interface': 'internal',
  173                  'region': 'RegionOne',
  174                  'url': 'http://region-one:35357/v3'},
  175                 {'interface': 'admin',
  176                  'region': 'RegionTwo',
  177                  'url': 'http://region-two:35357/v3'},
  178                 {'interface': 'public',
  179                  'region': 'RegionTwo',
  180                  'url': 'http://region-two:5000/v3'},
  181                 {'interface': 'internal',
  182                  'region': 'RegionTwo',
  183                  'url': 'http://region-two:35357/v3'}],
  184                 'type': 'identity',
  185                 'name': "'Identity Service'",
  186                 'id': '1'}]
  187         self.assert_catalogs_equal(exp_catalog, catalog_ref)
  188 
  189     def test_get_catalog_ignores_endpoints_with_invalid_urls(self):
  190         user_id = uuid.uuid4().hex
  191         project_id = None
  192         # If the URL has no 'project_id' to substitute, we will skip the
  193         # endpoint which contains this kind of URL.
  194         catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(user_id, project_id)
  195         exp_catalog = [
  196             {'endpoints': [],
  197              'type': 'compute',
  198              'name': "'Compute Service'",
  199              'id': '2'},
  200             {'endpoints': [
  201                 {'interface': 'admin',
  202                  'region': 'RegionOne',
  203                  'url': 'http://localhost:35357/v3'},
  204                 {'interface': 'public',
  205                  'region': 'RegionOne',
  206                  'url': 'http://localhost:5000/v3'},
  207                 {'interface': 'internal',
  208                  'region': 'RegionOne',
  209                  'url': 'http://localhost:35357/v3'}],
  210              'type': 'identity',
  211              'name': "'Identity Service'",
  212              'id': '1'}]
  213         self.assert_catalogs_equal(exp_catalog, catalog_ref)
  214 
  215     def test_list_regions_filtered_by_parent_region_id(self):
  216         self.skip_test_overrides('Templated backend does not support hints')
  217 
  218     def test_service_filtering(self):
  219         self.skip_test_overrides("Templated backend doesn't support filtering")
  220 
  221     def test_list_services_with_hints(self):
  222         hints = {}
  223         services = PROVIDERS.catalog_api.list_services(hints=hints)
  224         exp_services = [
  225             {'type': 'compute',
  226              'description': '',
  227              'enabled': True,
  228              'name': "'Compute Service'",
  229              'id': 'compute'},
  230             {'type': 'identity',
  231              'description': '',
  232              'enabled': True,
  233              'name': "'Identity Service'",
  234              'id': 'identity'}]
  235         self.assertItemsEqual(exp_services, services)
  236 
  237     # NOTE(dstanek): the following methods have been overridden
  238     # from unit.catalog.test_backends.CatalogTests.
  239 
  240     def test_region_crud(self):
  241         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  242 
  243     @unit.skip_if_cache_disabled('catalog')
  244     def test_cache_layer_region_crud(self):
  245         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  246 
  247     @unit.skip_if_cache_disabled('catalog')
  248     def test_invalidate_cache_when_updating_region(self):
  249         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  250 
  251     def test_update_region_extras(self):
  252         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  253 
  254     def test_create_region_with_duplicate_id(self):
  255         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  256 
  257     def test_delete_region_returns_not_found(self):
  258         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  259 
  260     def test_create_region_invalid_parent_region_returns_not_found(self):
  261         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  262 
  263     def test_avoid_creating_circular_references_in_regions_update(self):
  264         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  265 
  266     @mock.patch.object(catalog_base.CatalogDriverBase,
  267                        "_ensure_no_circle_in_hierarchical_regions")
  268     def test_circular_regions_can_be_deleted(self, mock_ensure_on_circle):
  269         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  270 
  271     def test_service_crud(self):
  272         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  273 
  274     @unit.skip_if_cache_disabled('catalog')
  275     def test_cache_layer_service_crud(self):
  276         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  277 
  278     @unit.skip_if_cache_disabled('catalog')
  279     def test_invalidate_cache_when_updating_service(self):
  280         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  281 
  282     def test_delete_service_with_endpoint(self):
  283         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  284 
  285     def test_cache_layer_delete_service_with_endpoint(self):
  286         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  287 
  288     def test_delete_service_returns_not_found(self):
  289         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  290 
  291     def test_update_endpoint_nonexistent_service(self):
  292         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  293 
  294     def test_create_endpoint_nonexistent_region(self):
  295         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  296 
  297     def test_update_endpoint_nonexistent_region(self):
  298         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  299 
  300     def test_get_endpoint_returns_not_found(self):
  301         self.skip_test_overrides(
  302             "Templated backend doesn't use IDs for endpoints.")
  303 
  304     def test_delete_endpoint_returns_not_found(self):
  305         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  306 
  307     def test_create_endpoint(self):
  308         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  309 
  310     def test_update_endpoint(self):
  311         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  312 
  313     def test_list_endpoints(self):
  314         expected_urls = set(['http://localhost:$(public_port)s/v3',
  315                              'http://localhost:$(admin_port)s/v3',
  316                              'http://localhost:8774/v1.1/$(tenant_id)s'])
  317         endpoints = PROVIDERS.catalog_api.list_endpoints()
  318         self.assertEqual(expected_urls, set(e['url'] for e in endpoints))
  319 
  320     @unit.skip_if_cache_disabled('catalog')
  321     def test_invalidate_cache_when_updating_endpoint(self):
  322         self.skip_test_overrides(BROKEN_WRITE_FUNCTIONALITY_MSG)
  323 
  324     def test_delete_endpoint_group_association_by_project(self):
  325         # Deleting endpoint group association is not supported by the templated
  326         # driver, but it should be silent about it and not raise an error.
  327         PROVIDERS.catalog_api.delete_endpoint_group_association_by_project(
  328             uuid.uuid4().hex)
  329 
  330     def test_delete_association_by_endpoint(self):
  331         # Deleting endpoint association is not supported by the templated
  332         # driver, but it should be silent about it and not raise an error.
  333         PROVIDERS.catalog_api.delete_association_by_endpoint(
  334             uuid.uuid4().hex)
  335 
  336     def test_delete_association_by_project(self):
  337         # Deleting endpoint association is not supported by the templated
  338         # driver, but it should be silent about it and not raise an error.
  339         PROVIDERS.catalog_api.delete_association_by_project(
  340             uuid.uuid4().hex)