summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-04-08 20:33:56 +0000
committerGerrit Code Review <review@openstack.org>2015-04-08 20:33:56 +0000
commit9924aaa3f185824779e4a3aab90b6a37802c114a (patch)
treec296f23d72ac0fff55dea1a90fcebc696b941476
parent007b3ef39f2666609bdc03d8065b7551382d8e90 (diff)
parentf53584c2688244f4f5b706aadac1875109a463c5 (diff)
downloadglance-9924aaa3f185824779e4a3aab90b6a37802c114a.tar.gz
Merge "Move elasticsearch dep to test-requirements.txt"
-rw-r--r--glance/gateway.py25
-rw-r--r--glance/tests/unit/test_gateway.py30
-rw-r--r--requirements.txt5
-rw-r--r--test-requirements.txt3
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