Skip to content

Commit 172a317

Browse files
authored
Add support to test against various versions of OpenSearch (opensearch-project#146)
* Adding support to run integration tests across various versions of OpenSearch Signed-off-by: Vacha Shah <vachshah@amazon.com> * Adding a compatibility matrix and getting started guide with formatting Signed-off-by: Vacha Shah <vachshah@amazon.com> * Splitting jobs for opendistro and opensearch Signed-off-by: Vacha Shah <vachshah@amazon.com>
1 parent fe1730a commit 172a317

12 files changed

+260
-205
lines changed

.ci/opensearch/Dockerfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
ARG OPENSEARCH_VERSION=1.0.0
1+
ARG OPENSEARCH_VERSION
22
FROM opensearchproject/opensearch:$OPENSEARCH_VERSION
33

44
ARG opensearch_path=/usr/share/opensearch
55
ARG opensearch_yml=$opensearch_path/config/opensearch.yml
66

77
ARG SECURE_INTEGRATION
88
RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then echo "plugins.security.disabled: true" >> $opensearch_yml; fi
9-
10-
COPY --chown=opensearch:opensearch .ci/opensearch/opensearch-run.sh $opensearch_path/
11-
12-
CMD /usr/share/opensearch/opensearch-run.sh

.ci/opensearch/opensearch-run.sh

-4
This file was deleted.

.ci/run-opensearch.sh

+10-14
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,8 @@
33
# Launch one or more OpenSearch nodes via the Docker image,
44
# to form a cluster suitable for running the REST API tests.
55
#
6-
# Export the STACK_VERSION variable, eg. '8.0.0-SNAPSHOT'.
7-
# Export the TEST_SUITE variable, i.e. 'oss'
86
# Export the NUMBER_OF_NODES variable to start more than 1 node
97

10-
# Version 1.4.0
11-
# - Initial version of the run-opensearch.sh script
12-
# - Deleting the volume should not dependent on the container still running
13-
# - Fixed `ES_JAVA_OPTS` config
14-
# - Moved to STACK_VERSION and TEST_VERSION
15-
# - Refactored into functions and imports
16-
# - Support NUMBER_OF_NODES
17-
# - Added 5 retries on docker pull for fixing transient network errors
18-
# - Added flags to make local CCR configurations work
19-
# - Added action.destructive_requires_name=false as the default will be true in v8
20-
218
script_path=$(dirname $(realpath -s $0))
229
source $script_path/functions/imports.sh
2310
set -euo pipefail
@@ -32,7 +19,7 @@ declare -a volumes
3219
environment=($(cat <<-END
3320
--env node.name=$opensearch_node_name
3421
--env cluster.name=$cluster_name
35-
--env cluster.initial_master_nodes=$master_node_name
22+
--env discovery.type=single-node
3623
--env discovery.seed_hosts=$master_node_name
3724
--env cluster.routing.allocation.disk.threshold_enabled=false
3825
--env bootstrap.memory_lock=true
@@ -43,6 +30,13 @@ environment=($(cat <<-END
4330
END
4431
))
4532

33+
if [[ "$SECURE_INTEGRATION" == "false" ]] && [[ "$CLUSTER" == "opensearch" ]]; then
34+
security=($(cat <<-END
35+
--env plugins.security.disabled=true
36+
END
37+
))
38+
fi
39+
4640
NUMBER_OF_NODES=${NUMBER_OF_NODES-1}
4741
http_port=9200
4842
for (( i=0; i<$NUMBER_OF_NODES; i++, http_port++ )); do
@@ -68,6 +62,7 @@ END
6862
docker build \
6963
--file=.ci/$CLUSTER/Dockerfile \
7064
--build-arg SECURE_INTEGRATION=$SECURE_INTEGRATION \
65+
--build-arg OPENSEARCH_VERSION=$OPENSEARCH_VERSION \
7166
--tag=$CLUSTER-secure-$SECURE_INTEGRATION \
7267
.
7368

@@ -84,6 +79,7 @@ END
8479
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \
8580
"${environment[@]}" \
8681
"${volumes[@]}" \
82+
"${security[@]}" \
8783
--publish "$http_port":9200 \
8884
--ulimit nofile=65536:65536 \
8985
--ulimit memlock=-1:-1 \

.ci/run-tests

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env bash
22
#
3-
# Version 1.1
4-
# - Moved to .ci folder and seperated out `run-repository.sh`
5-
# - Add `$RUNSCRIPTS` env var for running opensearch dependent products
3+
# Entrypoint to run integration tests
64

75
# Default environment variables
86
export TEST_SUITE="${TEST_SUITE:=oss}"
97
export PYTHON_VERSION="${PYTHON_VERSION:=3.9}"
108
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=Urllib3HttpConnection}"
119
export CLUSTER="${1:-opensearch}"
1210
export SECURE_INTEGRATION="${2:-false}"
11+
export OPENSEARCH_VERSION="${3:-latest}"
1312
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
1413
export OPENSEARCH_URL_EXTENSION="https"
1514
else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Integration tests with OpenDistro
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
integration:
7+
name: Integ
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
secured: ["true", "false"]
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Integ opendistro secured=${{ matrix.secured }}
18+
run: "./.ci/run-tests opendistro ${{ matrix.secured }}"

.github/workflows/integration.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
cluster: ["opendistro", "opensearch"]
12+
cluster: ["opensearch"]
1313
secured: ["true", "false"]
14+
opensearch_version: [1.0.0, 1.0.1, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.3.0, 1.3.1]
1415

1516
steps:
1617
- name: Checkout
1718
uses: actions/checkout@v2
18-
- run: "./.ci/run-tests ${{ matrix.cluster }} ${{ matrix.secured }}"
19-
name: Integ ${{ matrix.stack_version }} ${{ matrix.cluster }} secured=${{ matrix.secured }}
19+
- name: Integ ${{ matrix.cluster }} secured=${{ matrix.secured }} version=${{matrix.opensearch_version}}
20+
run: "./.ci/run-tests ${{ matrix.cluster }} ${{ matrix.secured }} ${{ matrix.opensearch_version }}"

ADMINS.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
- [Overview](#overview)
2+
- [Current Admins](#current-admins)
3+
- [Admin Responsibilities](#admin-responsibilities)
4+
- [Prioritize Security](#prioritize-security)
5+
- [Enforce Code of Conduct](#enforce-code-of-conduct)
6+
- [Adopt Organizational Best Practices](#adopt-organizational-best-practices)
7+
18
## Overview
29

310
This document explains who the admins are (see below), what they do in this repo, and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).

COMPATIBILITY.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- [Compatibility with OpenSearch](#compatibility-with-opensearch)
2+
3+
## Compatibility with OpenSearch
4+
5+
The below matrix shows the compatibility of the [`opensearch-py`](https://pypi.org/project/opensearch-py/) with versions of [`OpenSearch`](https://opensearch.org/downloads.html#opensearch).
6+
7+
| OpenSearch Version | Client Version |
8+
| --- | --- |
9+
| 1.0.0 | 1.0.0 |
10+
| 1.0.1 | 1.0.0 |
11+
| 1.1.0 | 1.1.0 |
12+
| 1.2.0 | 1.1.0 |
13+
| 1.2.1 | 1.0.0 |
14+
| 1.2.2 | 1.0.0 |
15+
| 1.2.3 | 1.0.0 |
16+
| 1.2.4 | 1.0.0 |
17+
| 1.3.0 | 1.1.0 |
18+
| 1.3.1 | 1.1.0 |

DEVELOPER_GUIDE.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
- [Developer Guide](#developer-guide)
2+
- [Linter and Test Suite](#linter-and-test-suite)
3+
- [Integration Tests](#integration-tests)
4+
- [Build the Documentation with Sphinx](#build-the-documentation-with-sphinx)
5+
16
# Developer Guide
27

38
## Linter and Test Suite
@@ -18,10 +23,12 @@ $ nox -rs test
1823
To run the integration tests locally, run:
1924

2025
```
21-
./.ci/run-tests opensearch true
26+
./.ci/run-tests opensearch true 1.3.0
2227
```
2328

24-
The first argument, `opensearch` tells the server type to run integration test against. Valid values are `opensearch` and `opendistro`. The second argument tells whether to run server with security plugin enabled or not.
29+
The first argument, `opensearch` tells the server type to run integration test against. Valid values are `opensearch` and `opendistro`.
30+
The second argument tells whether to run server with security plugin enabled or not.
31+
The third argument specifies the version of OpenSearch the tests should run against, if not specified, the tests run against the latest version. This argument is ignored if the server type is `opendistro`.
2532

2633
Note that integration tests require docker to be installed and running, and downloads quite a bit of data from over the internet and hence take few minutes to complete.
2734

GETTING_STARTED.md

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
- [Getting Started with the OpenSearch Python Client](#getting-started-with-the-opensearch-python-client)
2+
- [Setup](#setup)
3+
- [Sample code](#sample-code)
4+
- [Using IAM credentials for authentication](#using-iam-credentials-for-authentication)
5+
- [Pre-requisites to use `AWSV4SignerAuth`](#pre-requisites-to-use-awsv4signerauth)
6+
7+
# Getting Started with the OpenSearch Python Client
8+
9+
## Setup
10+
11+
To add the client to your project, install it using [pip](https://pip.pypa.io/):
12+
13+
```bash
14+
pip install opensearch-py
15+
```
16+
17+
Then import it like any other module:
18+
19+
```python
20+
from opensearchpy import OpenSearch
21+
```
22+
23+
If you prefer to add the client manually or just want to examine the source code, see [opensearch-py on GitHub](https://github.com/opensearch-project/opensearch-py).
24+
25+
26+
## Sample code
27+
28+
```python
29+
from opensearchpy import OpenSearch
30+
31+
host = 'localhost'
32+
port = 9200
33+
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
34+
ca_certs_path = '/full/path/to/root-ca.pem' # Provide a CA bundle if you use intermediate CAs with your root CA.
35+
36+
# Optional client certificates if you don't want to use HTTP basic authentication.
37+
# client_cert_path = '/full/path/to/client.pem'
38+
# client_key_path = '/full/path/to/client-key.pem'
39+
40+
# Create the client with SSL/TLS enabled, but hostname verification disabled.
41+
client = OpenSearch(
42+
hosts = [{'host': host, 'port': port}],
43+
http_compress = True, # enables gzip compression for request bodies
44+
http_auth = auth,
45+
# client_cert = client_cert_path,
46+
# client_key = client_key_path,
47+
use_ssl = True,
48+
verify_certs = True,
49+
ssl_assert_hostname = False,
50+
ssl_show_warn = False,
51+
ca_certs = ca_certs_path
52+
)
53+
54+
# Create an index with non-default settings.
55+
index_name = 'python-test-index3'
56+
index_body = {
57+
'settings': {
58+
'index': {
59+
'number_of_shards': 4
60+
}
61+
}
62+
}
63+
64+
response = client.indices.create(index_name, body=index_body)
65+
print('\nCreating index:')
66+
print(response)
67+
68+
# Add a document to the index.
69+
document = {
70+
'title': 'Moneyball',
71+
'director': 'Bennett Miller',
72+
'year': '2011'
73+
}
74+
id = '1'
75+
76+
response = client.index(
77+
index = index_name,
78+
body = document,
79+
id = id,
80+
refresh = True
81+
)
82+
83+
print('\nAdding document:')
84+
print(response)
85+
86+
# Search for the document.
87+
q = 'miller'
88+
query = {
89+
'size': 5,
90+
'query': {
91+
'multi_match': {
92+
'query': q,
93+
'fields': ['title^2', 'director']
94+
}
95+
}
96+
}
97+
98+
response = client.search(
99+
body = query,
100+
index = index_name
101+
)
102+
print('\nSearch results:')
103+
print(response)
104+
105+
# Delete the document.
106+
response = client.delete(
107+
index = index_name,
108+
id = id
109+
)
110+
111+
print('\nDeleting document:')
112+
print(response)
113+
114+
# Delete the index.
115+
response = client.indices.delete(
116+
index = index_name
117+
)
118+
119+
print('\nDeleting index:')
120+
print(response)
121+
```
122+
123+
## Using IAM credentials for authentication
124+
125+
Refer the AWS documentation regarding usage of IAM credentials to sign requests to OpenSearch APIs - [Signing HTTP requests to Amazon OpenSearch Service.](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/request-signing.html#request-signing-python)
126+
127+
Opensearch-py client library also provides an in-house IAM based authentication feature, `AWSV4SignerAuth` that will help users to connect to their opensearch clusters by making use of IAM roles.
128+
129+
#### Pre-requisites to use `AWSV4SignerAuth`
130+
- Python version 3.6 or above,
131+
- Install [botocore](https://pypi.org/project/botocore/) using pip
132+
133+
`pip install botocore`
134+
135+
Here is the sample code that uses `AWSV4SignerAuth` -
136+
137+
```python
138+
from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth
139+
import boto3
140+
141+
host = '' # cluster endpoint, for example: my-test-domain.us-east-1.es.amazonaws.com
142+
region = 'us-west-2'
143+
credentials = boto3.Session().get_credentials()
144+
auth = AWSV4SignerAuth(credentials, region)
145+
index_name = 'python-test-index3'
146+
147+
client = OpenSearch(
148+
hosts = [{'host': host, 'port': 443}],
149+
http_auth = auth,
150+
use_ssl = True,
151+
verify_certs = True,
152+
connection_class = RequestsHttpConnection
153+
)
154+
155+
q = 'miller'
156+
query = {
157+
'size': 5,
158+
'query': {
159+
'multi_match': {
160+
'query': q,
161+
'fields': ['title^2', 'director']
162+
}
163+
}
164+
}
165+
166+
response = client.search(
167+
body = query,
168+
index = index_name
169+
)
170+
171+
print('\nSearch results:')
172+
print(response)
173+
```

MAINTAINERS.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
- [Overview](#overview)
22
- [Current Maintainers](#current-maintainers)
33
- [Maintainer Responsibilities](#maintainer-responsibilities)
4-
- [Uphold Code of Conduct](#uphold-code-of-conduct)
5-
- [Prioritize Security](#prioritize-security)
6-
- [Review Pull Requests](#review-pull-requests)
7-
- [Triage Open Issues](#triage-open-issues)
8-
- [Be Responsive](#be-responsive)
9-
- [Maintain Overall Health of the Repo](#maintain-overall-health-of-the-repo)
10-
- [Use Semver](#use-semver)
11-
- [Release Frequently](#release-frequently)
12-
- [Promote Other Maintainers](#promote-other-maintainers)
4+
- [Uphold Code of Conduct](#uphold-code-of-conduct)
5+
- [Prioritize Security](#prioritize-security)
6+
- [Review Pull Requests](#review-pull-requests)
7+
- [Triage Open Issues](#triage-open-issues)
8+
- [Be Responsive](#be-responsive)
9+
- [Maintain Overall Health of the Repo](#maintain-overall-health-of-the-repo)
10+
- [Use Semver](#use-semver)
11+
- [Release Frequently](#release-frequently)
12+
- [Promote Other Maintainers](#promote-other-maintainers)
1313

1414
## Overview
1515

0 commit comments

Comments
 (0)