-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add endpoints and authentication details (including SigV4) as parameters to E2E test script #461
Changes from 11 commits
edcda15
79b0b84
bd3ab8e
e16999a
6d59979
c009947
2930a32
f721399
ae0e482
8e2a3c6
cb13a85
c7c1da3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,4 @@ jobs: | |
run: | | ||
cd test | ||
chmod +x ./tests.py | ||
pytest -n 3 tests.py | ||
pytest tests.py --unique_id="testindex" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# conftest.py | ||
import pytest | ||
|
||
import logging | ||
|
||
|
||
def pytest_configure(config): | ||
# Configure logging | ||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s - %(levelname)s - %(message)s', | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
|
||
# This line ensures that log messages are displayed on the console during test runs | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--proxy_endpoint", action="store", default="https://localhost:9200") | ||
parser.addoption("--source_endpoint", action="store", default="https://localhost:19200") | ||
parser.addoption("--target_endpoint", action="store", default="https://localhost:29200") | ||
parser.addoption("--source_auth_type", action="store", default="basic", choices=["none", "basic", "sigv4"]) | ||
parser.addoption("--source_verify_ssl", action="store", default="False", choices=["True", "False"]) | ||
parser.addoption("--target_auth_type", action="store", default="basic", choices=["none", "basic", "sigv4"]) | ||
parser.addoption("--target_verify_ssl", action="store", default="False", choices=["True", "False"]) | ||
parser.addoption("--deployment_type", action="store", default="local", choices=["local", "cloud"]) | ||
parser.addoption("--source_username", action="store", default="admin") | ||
parser.addoption("--source_password", action="store", default="admin") | ||
parser.addoption("--target_username", action="store", default="admin") | ||
parser.addoption("--target_password", action="store", default="admin") | ||
parser.addoption("--unique_id", action="store", default="") | ||
|
||
|
||
@pytest.fixture | ||
def proxy_endpoint(pytestconfig): | ||
return pytestconfig.getoption("proxy_endpoint") | ||
|
||
|
||
@pytest.fixture | ||
def source_endpoint(pytestconfig): | ||
return pytestconfig.getoption("source_endpoint") | ||
|
||
|
||
@pytest.fixture | ||
def target_endpoint(pytestconfig): | ||
return pytestconfig.getoption("target_endpoint") | ||
|
||
|
||
@pytest.fixture | ||
def source_auth_type(pytestconfig): | ||
return pytestconfig.getoption("source_auth_type") | ||
|
||
|
||
@pytest.fixture | ||
def source_username(pytestconfig): | ||
return pytestconfig.getoption("source_username") | ||
|
||
|
||
@pytest.fixture | ||
def source_password(pytestconfig): | ||
return pytestconfig.getoption("source_password") | ||
|
||
|
||
@pytest.fixture | ||
def target_auth_type(pytestconfig): | ||
return pytestconfig.getoption("target_auth_type") | ||
|
||
|
||
@pytest.fixture | ||
def target_username(pytestconfig): | ||
return pytestconfig.getoption("target_username") | ||
|
||
|
||
@pytest.fixture | ||
def target_password(pytestconfig): | ||
return pytestconfig.getoption("target_password") | ||
|
||
|
||
@pytest.fixture | ||
def target_verify_ssl(pytestconfig): | ||
return pytestconfig.getoption("target_verify_ssl") | ||
|
||
|
||
@pytest.fixture | ||
def source_verify_ssl(pytestconfig): | ||
return pytestconfig.getoption("source_verify_ssl") | ||
|
||
|
||
@pytest.fixture | ||
def deployment_type(pytestconfig): | ||
return pytestconfig.getoption("deployment_type") | ||
|
||
|
||
@pytest.fixture | ||
def unique_id(pytestconfig): | ||
return pytestconfig.getoption("unique_id") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import requests | ||
import json | ||
from typing import Optional, Tuple | ||
|
||
|
||
def create_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None): | ||
response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=False) | ||
def create_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'): | ||
response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the requests library is smart enough to see if it has basic or sigv4 auth passed to it and parse accordingly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct! |
||
|
||
return response | ||
|
||
|
||
def check_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None): | ||
response = requests.get(f'{endpoint}/{index_name}', auth=auth, verify=False) | ||
def check_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'): | ||
response = requests.get(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) | ||
|
||
return response | ||
|
||
|
||
def delete_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None): | ||
response = requests.delete(f'{endpoint}/{index_name}', auth=auth, verify=False) | ||
def delete_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False): | ||
response = requests.delete(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) | ||
|
||
return response | ||
|
||
|
||
def delete_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None): | ||
response = requests.delete(f'{endpoint}/{index_name}/_doc/{doc_id}', auth=auth, verify=False) | ||
def delete_document(endpoint: str, index_name: str, doc_id: str, auth, | ||
verify_ssl: bool = False): | ||
response = requests.delete(f'{endpoint}/{index_name}/_doc/{doc_id}', auth=auth, verify=verify_ssl) | ||
|
||
return response | ||
|
||
|
||
def create_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None): | ||
def create_document(endpoint: str, index_name: str, doc_id: str, auth, | ||
verify_ssl: bool = False): | ||
document = { | ||
'title': 'Test Document', | ||
'content': 'This is a sample document for testing OpenSearch.' | ||
} | ||
url = f'{endpoint}/{index_name}/_doc/{doc_id}' | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
response = requests.put(url, headers=headers, data=json.dumps(document), auth=auth, verify=False) | ||
response = requests.put(url, headers=headers, data=json.dumps(document), auth=auth, verify=verify_ssl) | ||
|
||
return response | ||
|
||
|
||
def get_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None): | ||
def get_document(endpoint: str, index_name: str, doc_id: str, auth, | ||
verify_ssl: bool = False): | ||
url = f'{endpoint}/{index_name}/_doc/{doc_id}' | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
response = requests.get(url, headers=headers, auth=auth, verify=False) | ||
response = requests.get(url, headers=headers, auth=auth, verify=verify_ssl) | ||
|
||
return response |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ pytest==7.3.1 | |
pytest-xdist==3.3.1 | ||
requests==2.31.0 | ||
urllib3==2.0.7 | ||
requests_aws4auth | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this what FetchMigration uses as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, although one has a "-" and the other has a "_", but they're the exact same. |
||
boto3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the protocol argument being used in these methods? And why do only some methods have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove this. Mistakenly added from something else I was testing.