From 6a73ba5558df610d21e3f8c7aea699b9b495e550 Mon Sep 17 00:00:00 2001 From: Marc Chakiachvili Date: Mon, 17 Apr 2023 17:17:37 +0100 Subject: [PATCH 1/4] Added global ESConnectionManager --- requirements-test.txt | 1 + src/test/test_es.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/test/test_es.py diff --git a/requirements-test.txt b/requirements-test.txt index c0285ac..8722162 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,3 @@ pytest +elasticsearch>=6.8.1,<7.0.0 coverage[toml] \ No newline at end of file diff --git a/src/test/test_es.py b/src/test/test_es.py new file mode 100644 index 0000000..b86fa57 --- /dev/null +++ b/src/test/test_es.py @@ -0,0 +1,24 @@ +# See the NOTICE file distributed with this work for additional information +# regarding copyright ownership. +# 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 unittest + +from ensembl.production.core.es import ElasticsearchConnectionManager + +#TODO ADD more test with proper config in gitlab +class EsTest(unittest.TestCase): + def test_es_exception(self): + with self.assertRaises(RuntimeError) as expected: + with ElasticsearchConnectionManager(host="http://unknown", + port=9200) as elastic: + elastic.client.ping() + self.assertTrue('Cannot connect to Elasticsearch server' in expected) + From 0d03f64c81034e4bf3c3c7200f52ec495af48f65 Mon Sep 17 00:00:00 2001 From: Marc Chakiachvili Date: Mon, 17 Apr 2023 17:23:04 +0100 Subject: [PATCH 2/4] Added ES Core Connexion and basic tests. --- .travis.yml | 21 --------------- src/ensembl/production/core/es.py | 43 +++++++++++++++++++++++++++++++ src/test/test_es.py | 3 ++- 3 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 src/ensembl/production/core/es.py diff --git a/.travis.yml b/.travis.yml index 531579f..17342c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,24 +9,3 @@ install: script: - coverage run -m pytest - coverage report -m - -deploy: - - provider: pypi - username: __token__ - server: https://test.pypi.org/legacy/ - password: - secure: UCGgJqX0irr4E/Nw+hOWZojH4oj17a92opGGGMUCFsIN7vaOW7+rdEqLmvjR3cF3aTD2taMpDMBOIHOKy9xzv448FvA89ICpqbASaFhkb63UrCNCT8CMgBjrQyCqgONnlNlCDx8Od3LEd3muKUUJUzqWFVBTKD/OwFut7+Ju9rUnf5dYLUqQ1Mxl+T93G3wZtp7xCw1AyevEuF3adbDiukJDz93BGG3YiUlpIIg2DLJZMat0++O+4phCQKro6iYqbWWwCpj2t9BKeCqD7X4jG+ND3++Kg8K9SKTzpIWc5Rnk/ohuzTE0cDncrtR9HBopPaZwVyUzQkXJdIrjiW3wxPrh15SGWhpgmjvpRPkTYOfOnCB6JnvBGsErZ/sC/V5yT7u8btZ4Vi2Q8fTfThAU/ULD/15DtmHl08Hc+R+dV0gkgCCEVNUHBP65rlLKjXwHjItDlzpVtUBkDMH14E7QgN0X+lrysMXFs01MxcxLhGw8yL08XUPUjdoBgLWLTpVkR2rrhDvXSaIVa/OLJXILRfvdHkh5VoiffVqVyAmscUJnN8YTFi304aQix6/Ubs1Ajiq2oubF7tML9XCErL24IHzOkXelmtipmzO8uUV2WSxakLRX+EH6L7Cccvgba8cYFcsurgJxF29CU1ZAAHWhHGfpf2Y4pmZyRmDl0SP6YDw= - on: - tags: true - repo: Ensembl/ensembl-prodinf-core - condition: $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?-test(\.[0-9]+)?$ - skip_existing: true - - provider: pypi - username: __token__ - password: - secure: oStGO0suyyGYgYU2cckOz/0o2RgdTg2Kxg3Xs8c6M/V+BbffgKk9RNYCtSPmggXdMO4esKdhn8nHWzG8P49XiWo11v/W7O6N6DrJSLpk/Pt4P8u2U92TK6YLHKzvGd3LNVI42QOk4XaC63w4vkXU0afd5g2Fhflm3Hk4uEzYfRRhViJBm/SYt+/pQuZTpyGO7sh0s0VLVc1l3TMMyAvvuU6yQro1B7DugiwJqLVuV28qCZGIykbk5j6nXsNngmbVfb+Pxgu3j8XQAMh8KTWlZIW92iNWJyFVx6wRleM/NRcrWHzylq8flRYV3pbY/uZaGsd6x07NekvqVOz33gZJi7DiYSPJBf4S1ZIGorprlTj0+Y3IAOW9Y1MMmSxurjAQGZ69F8SLiuzUpd2GJaDFRP3nA2fzPzSwcFmVKzTSl2Ey8bpz8VDF33Zs6PM4sBg8EcE2PTRueJ14Kf5lDm5RbhQMFDqU4iMPPDlDBDNc3C1AsgQbrDE4I9YG893MruNgjIADIGMuqOcF/j0Dq5if/IfBCh2Au/JWLpejZgS6upr3m9NoyWWbmOYG3lc2k1gDaKS/B45NypbOvz43EwSbs5ajEkvekZpZJ3E/OUtcURNUctqZM7rEkwU2VtAxyHLLkUY+/65ZZK5GK+j5xbFV5RtayH/OX4zODvlBz6l3PC4= - on: - tags: true - repo: Ensembl/ensembl-prodinf-core - condition: $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ - skip_existing: true \ No newline at end of file diff --git a/src/ensembl/production/core/es.py b/src/ensembl/production/core/es.py new file mode 100644 index 0000000..a69af96 --- /dev/null +++ b/src/ensembl/production/core/es.py @@ -0,0 +1,43 @@ +# See the NOTICE file distributed with this work for additional information +# regarding copyright ownership. +# 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 ssl + +import urllib3 +from elasticsearch import Elasticsearch, ElasticsearchException +from elasticsearch.connection import create_ssl_context + + +class ElasticsearchConnectionManager: + def __init__(self, host: str, port: int, user: str = "", password: str = "", with_ssl: bool = False): + self.host = host + self.port = port + self.user = user + self.password = password + self.ssl = with_ssl + self.client = None + + def __enter__(self): + urllib3.disable_warnings(category=urllib3.connectionpool.InsecureRequestWarning) + ssl_context = create_ssl_context() + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE + self.client = Elasticsearch(hosts=[{'host': self.host, 'port': self.port}], + scheme="https" if self.ssl else "http", + ssl_context=ssl_context, + http_auth=(self.user, self.password)) + if not self.client.ping(): + raise RuntimeError( + f"Cannot connect to Elasticsearch server. User: {self.user}, Host: {self.host}:{self.port}") + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.client.transport.close() diff --git a/src/test/test_es.py b/src/test/test_es.py index b86fa57..72e6ae7 100644 --- a/src/test/test_es.py +++ b/src/test/test_es.py @@ -13,7 +13,8 @@ from ensembl.production.core.es import ElasticsearchConnectionManager -#TODO ADD more test with proper config in gitlab + +# TODO ADD more test with proper config in gitlab class EsTest(unittest.TestCase): def test_es_exception(self): with self.assertRaises(RuntimeError) as expected: From 882445c3a54976ddaefe62a36ec27149b2772e0c Mon Sep 17 00:00:00 2001 From: Marc Chakiachvili Date: Mon, 17 Apr 2023 17:35:38 +0100 Subject: [PATCH 3/4] Use GIT_COMMIT_TAG in setup. --- VERSION | 2 +- setup.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index e010258..157e54f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.5 +2.0.6 diff --git a/setup.py b/setup.py index 7b74561..10d615a 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ # 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 os import pathlib from setuptools import setup, find_namespace_packages @@ -27,7 +28,7 @@ def import_requirements(): name='ensembl-prodinf-core', description='Ensembl Production infrastructure core package', long_description=readme, - version=version, + version=os.getenv('CI_COMMIT_TAG', version), namespace_packages=['ensembl'], packages=find_namespace_packages(where='src', include=['ensembl*'], exclude=['test']), package_dir={'': 'src'}, From c8badd4e989d7904d219026969291e82fe8f1fcc Mon Sep 17 00:00:00 2001 From: Marc Chakiachvili Date: Mon, 17 Apr 2023 17:50:26 +0100 Subject: [PATCH 4/4] 2.0.5 target version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 157e54f..e010258 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.6 +2.0.5