diff options
author | Louis Taylor <louis@kragniz.eu> | 2015-04-07 16:10:07 +0000 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2015-04-08 10:59:44 -0700 |
commit | f53584c2688244f4f5b706aadac1875109a463c5 (patch) | |
tree | b249089b537c42496259aed3729959418b8e97dc | |
parent | 6dc5477a12b9b904332ac6fe7932abbc7a0275a7 (diff) | |
download | glance-f53584c2688244f4f5b706aadac1875109a463c5.tar.gz |
Move elasticsearch dep to test-requirements.txt
Move experimental feature deps to test-requirements Optional and experimental
features should not make glance dependant on the libraries they require. This
change moves the python bindings for elasticsearch from the main
requirements.txt to test-requirements.txt.
semantic_version should potentially also be moved here, but it is currently
required to do a db sync and is generally less alarming than an elasticsearch
dependency. It is instead moved to the bottom of requirements.txt and marked as
being artifacts related.
Co-Authored-By: Matt Riedemann <mriedem@us.ibm.com>
Change-Id: I7f8dfafdb11dbf7ba258e907fbd17d92319d0f52
Closes-bug: #1441239
-rw-r--r-- | glance/gateway.py | 25 | ||||
-rw-r--r-- | glance/tests/unit/test_gateway.py | 30 | ||||
-rw-r--r-- | requirements.txt | 5 | ||||
-rw-r--r-- | test-requirements.txt | 3 |
4 files changed, 58 insertions, 5 deletions
diff --git a/glance/gateway.py b/glance/gateway.py index bd4b9b6d0..15faa1e3c 100644 --- a/glance/gateway.py +++ b/glance/gateway.py @@ -14,10 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. import glance_store +from oslo_log import log as logging from glance.api import authorization from glance.api import policy from glance.api import property_protections +from glance.common import exception from glance.common import property_utils from glance.common import store_utils import glance.db @@ -25,7 +27,14 @@ import glance.domain import glance.location import glance.notifier import glance.quota -import glance.search +try: + import glance.search + glance_search = glance.search +except ImportError: + glance_search = None + + +LOG = logging.getLogger(__name__) class Gateway(object): @@ -36,7 +45,10 @@ class Gateway(object): self.store_utils = store_utils self.notifier = notifier or glance.notifier.Notifier() self.policy = policy_enforcer or policy.Enforcer() - self.es_api = es_api or glance.search.get_api() + if es_api: + self.es_api = es_api + else: + self.es_api = glance_search.get_api() if glance_search else None def get_image_factory(self, context): image_factory = glance.domain.ImageFactory() @@ -235,6 +247,15 @@ class Gateway(object): return authorized_tag_repo def get_catalog_search_repo(self, context): + if self.es_api is None: + # TODO(mriedem): Make this a separate exception or change to + # warning/error logging in Liberty once we're past string freeze. + # See bug 1441764. + LOG.debug('The search and index services are not available. ' + 'Ensure you have the necessary prerequisite ' + 'dependencies installed like elasticsearch to use these ' + 'services.') + raise exception.ServiceUnavailable() search_repo = glance.search.CatalogSearchRepo(context, self.es_api) policy_search_repo = policy.CatalogSearchRepoProxy( search_repo, context, self.policy) diff --git a/glance/tests/unit/test_gateway.py b/glance/tests/unit/test_gateway.py new file mode 100644 index 000000000..b7a96aa93 --- /dev/null +++ b/glance/tests/unit/test_gateway.py @@ -0,0 +1,30 @@ +# Copyright 2015 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock +from oslo_context import context + +from glance.common import exception +from glance import gateway +from glance.tests import utils as test_utils + + +class TestGateway(test_utils.BaseTestCase): + + @mock.patch.object(gateway, 'glance_search', None) + def test_get_catalog_search_repo_no_es_api(self): + gate = gateway.Gateway() + self.assertRaises(exception.ServiceUnavailable, + gate.get_catalog_search_repo, + context.get_admin_context()) diff --git a/requirements.txt b/requirements.txt index 45fd77441..04f82b948 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,7 +45,6 @@ Paste jsonschema>=2.0.0,<3.0.0 python-keystoneclient>=1.1.0 pyOpenSSL>=0.11 -semantic_version>=2.3.1 # Required by openstack.common libraries six>=1.9.0 @@ -62,5 +61,5 @@ osprofiler>=0.3.0 # Apache-2.0 # Glance Store glance_store>=0.3.0 # Apache-2.0 -# Glance catalog index -elasticsearch>=1.3.0 +# Artifact repository +semantic_version>=2.3.1 diff --git a/test-requirements.txt b/test-requirements.txt index 74617b36f..217038a58 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -29,3 +29,6 @@ xattr>=0.4 # Documentation oslosphinx>=2.5.0,<2.6.0 # Apache-2.0 + +# Glance catalog index +elasticsearch>=1.3.0 |