Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es8envs #498

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/pytest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 13 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions newsfragments/384.break.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for elastisearch older than 7
1 change: 1 addition & 0 deletions newsfragments/384.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support elasticsearch 8.
13 changes: 10 additions & 3 deletions pytest_elasticsearch/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
"""
18 changes: 10 additions & 8 deletions pytest_elasticsearch/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def elasticsearch_proc_fixture(
elasticsearch_index_store_type,
timeout=60,
)
print(elasticsearch_executor.command)

elasticsearch_executor.start()
yield elasticsearch_executor
Expand Down Expand Up @@ -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
40 changes: 25 additions & 15 deletions tests/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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"),
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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
Loading