diff --git a/.github/actions/pytest/action.yml b/.github/actions/pytest/action.yml index 2239975e..a1dfcb0b 100644 --- a/.github/actions/pytest/action.yml +++ b/.github/actions/pytest/action.yml @@ -22,6 +22,9 @@ runs: uses: ankane/setup-elasticsearch@v1 with: elasticsearch-version: ${{ inputs.elasticsearch }} + - name: Stop running elasticsearch + shell: bash + run: killall elasticsearch - name: Run test uses: fizyk/actions-reuse/.github/actions/pipenv@v2.1.2 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ae9a4e72..7a36dd22 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,22 @@ on: branches: [ main ] jobs: + tests_8_0: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.8] + env: + OS: ubuntu-latest + PYTHON: ${{ matrix.python-version }} +# ES_JAVA_OPTS: "-Xms256m -Xmx512m" + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/pytest + with: + python-version: ${{ matrix.python-version }} + elasticsearch: "8.0" tests_7_17: runs-on: ubuntu-latest strategy: @@ -44,7 +60,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.8] + python-version: ["3.10", pypy-3.8] env: OS: ubuntu-latest PYTHON: ${{ matrix.python-version }} @@ -60,7 +76,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.8] + python-version: ["3.10"] env: OS: ubuntu-latest PYTHON: ${{ matrix.python-version }} diff --git a/Pipfile b/Pipfile index ece418ce..6f8b55cf 100644 --- a/Pipfile +++ b/Pipfile @@ -7,7 +7,7 @@ name = "pypi" pytest = "==7.3.2" port-for = "==0.7.0" mirakuru = "==2.5.1" -elasticsearch = "==7.17.0" +elasticsearch = "==8.0.1" [dev-packages] towncrier = "==23.6.0" diff --git a/Pipfile.lock b/Pipfile.lock index 63cec624..063bef2f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "fa90ace3f6b5b886b8322b8420da2faf771e064176d436a9cd68e317a8fc3f11" + "sha256": "f9c8d21d7a68efdc5ad1d220f434940b72c8de8283132c8d4b415d5019f69837" }, "pipfile-spec": 6, "requires": {}, @@ -19,16 +19,24 @@ "sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082", "sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9" ], - "index": "pypi", + "markers": "python_version >= '3.6'", "version": "==2023.7.22" }, + "elastic-transport": { + "hashes": [ + "sha256:19db271ab79c9f70f8c43f8f5b5111408781a6176b54ab2e54d713b6d9ceb815", + "sha256:b9ad708ceb7fcdbc6b30a96f886609a109f042c0b9d9f2e44403b3133ba7ff10" + ], + "markers": "python_version >= '3.6'", + "version": "==8.4.0" + }, "elasticsearch": { "hashes": [ - "sha256:406013783cc36af28ea36cd58cf184cd646530e47eea41336b386322fb878b59", - "sha256:ccbf3d1651eb79798a55c1e84b8be850db3873f0329e74086a2cfba37e8c288c" + "sha256:68598bd9cb297199523bf28c4a71c63d559ebca42107110f39ef2a748b58c6d7", + "sha256:b9facb8d7db71ad0d3c0ccc87dc224985abfe00bea888acd1d187cb0972c61f2" ], "index": "pypi", - "version": "==7.17.0" + "version": "==8.0.1" }, "iniconfig": { "hashes": [ diff --git a/README.rst b/README.rst index 55b2ecbd..f07745aa 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ You can pick which you prefer, but remember that these settings are handled in t - 127.0.0.1 * - port - port - - -elasticsearch-port + - --elasticsearch-port - elasticsearch_port - 6300 - random diff --git a/newsfragments/384.break.rst b/newsfragments/384.break.rst new file mode 100644 index 00000000..973dae43 --- /dev/null +++ b/newsfragments/384.break.rst @@ -0,0 +1 @@ +Drop support for elastisearch older than 7 \ No newline at end of file diff --git a/newsfragments/384.feature.rst b/newsfragments/384.feature.rst new file mode 100644 index 00000000..cf13306d --- /dev/null +++ b/newsfragments/384.feature.rst @@ -0,0 +1 @@ +Support elasticsearch 8. \ No newline at end of file diff --git a/pytest_elasticsearch/executor.py b/pytest_elasticsearch/executor.py index 349f27c7..1ead52d2 100644 --- a/pytest_elasticsearch/executor.py +++ b/pytest_elasticsearch/executor.py @@ -48,7 +48,7 @@ def __init__( :param pathlib.Path executable: Executable path :param str host: hostname under which elasticsearch will be running :param int port: port elasticsearch listens on - :param int tcp_port: port used for unternal communication + :param int tcp_port: port used for internal communication :param pathlib.Path pidfile: pidfile location :param pathlib.Path logs_path: log files location :param pathlib.Path works_path: workdir location @@ -63,6 +63,7 @@ def __init__( self.executable = executable self.host = host self.port = port + # TODO: rename to transport_port self.tcp_port = tcp_port self.pidfile = pidfile self.logs_path = logs_path @@ -109,15 +110,21 @@ def _exec_command(self): :return: command to run elasticsearch :rtype: str """ - if self.version < parse_version("6.0.0"): + port_param = "transport.port" + if self.version < parse_version("7.0.0"): raise RuntimeError("This elasticsearch version is not supported.") + elif self.version < parse_version("8.0.0"): + port_param = "transport.tcp.port" + else: + port_param = "transport.port" return f""" {self.executable} -p {self.pidfile} -E http.port={self.port} - -E transport.tcp.port={self.tcp_port} + -E {port_param}={self.tcp_port} -E path.logs={self.logs_path} -E path.data={self.works_path} -E cluster.name={self.cluster_name} -E network.host='{self.network_publish_host}' -E index.store.type={self.index_store_type} + -E xpack.security.enabled=false """ diff --git a/pytest_elasticsearch/factories.py b/pytest_elasticsearch/factories.py index bf7b9b81..7340d132 100644 --- a/pytest_elasticsearch/factories.py +++ b/pytest_elasticsearch/factories.py @@ -116,6 +116,7 @@ def elasticsearch_proc_fixture( elasticsearch_index_store_type, timeout=60, ) + print(elasticsearch_executor.command) elasticsearch_executor.start() yield elasticsearch_executor @@ -169,14 +170,15 @@ def elasticsearch_fixture(request): process = request.getfixturevalue(process_fixture_name) if not process.running(): process.start() + client = Elasticsearch( + hosts=[{"host": process.host, "port": process.port, "scheme": "http"}], + request_timeout=30, + verify_certs=False, + ) + client.options(ignore_status=400) - client = Elasticsearch([{"host": process.host, "port": process.port}]) - - def drop_indexes(): - client.indices.delete(index="*") - - request.addfinalizer(drop_indexes) - - return client + yield client + for index in client.indices.get_alias(): + client.indices.delete(index=index) return elasticsearch_fixture diff --git a/tests/test_elastic.py b/tests/test_elastic.py index 3ac15bf3..83341f63 100644 --- a/tests/test_elastic.py +++ b/tests/test_elastic.py @@ -3,17 +3,13 @@ import mock import pytest +from elasticsearch import Elasticsearch from pkg_resources import parse_version +from pytest import FixtureRequest from pytest_elasticsearch import factories from pytest_elasticsearch.executor import ElasticSearchExecutor -VERSION_STRING_6_8 = ( - "OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was " - "deprecated in version 9.0 and will likely be removed in a future release." - "\nVersion: 6.8.12, Build: default/zip/7a15d2a/2020-08-12T07:27:20.804867Z," - " JVM: 11.0.2" -) VERSION_STRING_7_3 = ( "OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was " "deprecated in version 9.0 and will likely be removed in a future release." @@ -83,11 +79,22 @@ "2021-08-26T09:01:05.390870785Z, JVM: 11.0.11" ) +VERSION_STRING_7_17 = ( + "OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was " + "deprecated in version 9.0 and will likely be removed in a future release." + "\nVersion: 7.17.0, Build: default/tar/bee86328705acaa9a6daede7140defd4d9ec56bd/" + "2022-01-28T08:36:04.875279988Z, JVM: 11.0.14" +) + +VERSION_STRING_8_0 = ( + "Version: 8.0.0, Build: default/tar/1b6a7ece17463df5ff54a3e1302d825889aa1161/" + "2022-02-03T16:47:57.507843096Z, JVM: 17.0.1" +) + @pytest.mark.parametrize( "output, expected_version", ( - (VERSION_STRING_6_8, "6.8.12"), (VERSION_STRING_7_3, "7.3.0"), (VERSION_STRING_7_3_2, "7.3.2"), (VERSION_STRING_7_4, "7.4.2"), @@ -99,6 +106,8 @@ (VERSION_STRING_7_10, "7.10.0"), (VERSION_STRING_7_12, "7.12.1"), (VERSION_STRING_7_14, "7.14.1"), + (VERSION_STRING_7_17, "7.17.0"), + (VERSION_STRING_8_0, "8.0.0"), ), ) def test_version_extraction(output, expected_version): @@ -123,7 +132,7 @@ def test_elasticsearch(elasticsearch): assert info["status"] == "green" -def test_default_configuration(request): +def test_default_configuration(request: FixtureRequest): """Test default configuration.""" config = factories.return_config(request) @@ -134,22 +143,23 @@ def test_default_configuration(request): assert config["index_store_type"] == "mmapfs" -def test_external_elastic(elasticsearch2, elasticsearch_proc2, elasticsearch2_noop): +def test_external_elastic( + elasticsearch2: Elasticsearch, + elasticsearch2_noop: Elasticsearch, +): """Check that nooproc connects to the same redis.""" - if elasticsearch_proc2.version < parse_version("7.0.0"): - pytest.skip("Search response differes for earlier versions") - elasticsearch2.indices.create(index="test-index", ignore=400) + elasticsearch2.indices.create(index="test-index") doc = { "author": "kimchy", "text": "Elasticsearch: cool. bonsai cool.", "timestamp": datetime.utcnow(), } - res = elasticsearch2.index(index="test-index", doc_type="tweet", id=1, body=doc) + res = elasticsearch2.index(index="test-index", id=1, document=doc) assert res["result"] == "created" - res = elasticsearch2_noop.get(index="test-index", doc_type="tweet", id=1) + res = elasticsearch2_noop.get(index="test-index", id=1) assert res["found"] is True elasticsearch2.indices.refresh(index="test-index") - res = elasticsearch2_noop.search(index="test-index", body={"query": {"match_all": {}}}) + res = elasticsearch2_noop.search(index="test-index", query={"match_all": {}}) assert res["hits"]["total"]["value"] == 1