From edcda157fc976b04df10039d8c3fa9ab283a329c Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Thu, 30 Nov 2023 17:12:59 -0600 Subject: [PATCH 1/9] Add endpoints and authentication details as parameters Signed-off-by: Omar Khasawneh --- test/conftest.py | 35 +++++++++++++++++++++++++++++++++++ test/tests.py | 30 +++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 test/conftest.py diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 000000000..580944940 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,35 @@ +# conftest.py +import pytest + + +def pytest_addoption(parser): + parser.addoption("--source_endpoint", action="store") + parser.addoption("--target_endpoint", action="store") + parser.addoption("--auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + parser.addoption("--username", action="store", default="admin") + parser.addoption("--password", action="store", default="admin") + + +@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 auth_type(pytestconfig): + return pytestconfig.getoption("auth_type") + + +@pytest.fixture +def username(pytestconfig): + return pytestconfig.getoption("username") + + +@pytest.fixture +def password(pytestconfig): + return pytestconfig.getoption("password") diff --git a/test/tests.py b/test/tests.py index f07eea681..c6b3b7dc0 100644 --- a/test/tests.py +++ b/test/tests.py @@ -13,6 +13,8 @@ import uuid import string import secrets +import pytest + from requests.exceptions import ConnectionError, SSLError logger = logging.getLogger(__name__) @@ -69,13 +71,23 @@ def retry_request(request: Callable, args: Tuple = (), max_attempts: int = 15, d class E2ETests(unittest.TestCase): + + @pytest.fixture(autouse=True) + def init_fixtures(self, source_endpoint, target_endpoint, auth_type, username, password): + self.source_endpoint = source_endpoint + self.target_endpoint = target_endpoint + self.auth_type = auth_type + self.auth = self.setup_authentication(auth_type, username, password) + self.username = username + self.password = password + + def setup_authentication(self, auth_type, username, password): + if auth_type == "basic": + return (username, password) + return None + def set_common_values(self): self.proxy_endpoint = os.getenv('PROXY_ENDPOINT', 'https://localhost:9200') - self.source_endpoint = os.getenv('SOURCE_ENDPOINT', 'https://localhost:19200') - self.target_endpoint = os.getenv('TARGET_ENDPOINT', 'https://localhost:29200') - self.username = os.getenv('username', 'admin') - self.password = os.getenv('password', 'admin') - self.auth = (self.username, self.password) self.index = f"my_index_{uuid.uuid4()}" self.doc_id = '7' self.ignore_list = [] @@ -178,7 +190,7 @@ def test_0002_document(self): expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) - def test_0004_negativeAuth_invalidCreds(self): + def test_0003_negativeAuth_invalidCreds(self): # This test sends negative credentials to the clusters to validate that unauthorized access is prevented. alphabet = string.ascii_letters + string.digits for _ in range(10): @@ -195,7 +207,7 @@ def test_0004_negativeAuth_invalidCreds(self): response = requests.get(self.proxy_endpoint, auth=(user, pw), verify=False) self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED) - def test_0005_negativeAuth_missingCreds(self): + def test_0004_negativeAuth_missingCreds(self): # This test will use no credentials at all # With an empty authorization header response = requests.get(self.proxy_endpoint, auth=('', ''), verify=False) @@ -205,7 +217,7 @@ def test_0005_negativeAuth_missingCreds(self): response = requests.get(self.proxy_endpoint, verify=False) self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED) - def test_0006_invalidIncorrectUri(self): + def test_0005_invalidIncorrectUri(self): # This test will send an invalid URI invalidUri = "/invalidURI" response = requests.get(f'{self.proxy_endpoint}{invalidUri}', auth=self.auth, verify=False) @@ -216,7 +228,7 @@ def test_0006_invalidIncorrectUri(self): response = requests.get(f'{self.proxy_endpoint}{incorrectUri}', auth=self.auth, verify=False) self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED) - def test_0007_OSB(self): + def test_0006_OSB(self): cmd = ['docker', 'ps', '--format="{{.ID}}"', '--filter', 'name=migration'] container_id = subprocess.run(cmd, stdout=subprocess.PIPE, text=True).stdout.strip().replace('"', '') From 79b0b847231ab9c5b501d1d1adb05171f5ae9304 Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Fri, 1 Dec 2023 11:41:56 -0600 Subject: [PATCH 2/9] Add separate authentication details for both endpoints + update existing workflow Signed-off-by: Omar Khasawneh --- .github/workflows/e2eTest.yml | 2 +- test/conftest.py | 36 ++++++++++++---- test/tests.py | 78 +++++++++++++++++++---------------- 3 files changed, 71 insertions(+), 45 deletions(-) diff --git a/.github/workflows/e2eTest.yml b/.github/workflows/e2eTest.yml index 6380c1a85..2e8414055 100644 --- a/.github/workflows/e2eTest.yml +++ b/.github/workflows/e2eTest.yml @@ -44,4 +44,4 @@ jobs: run: | cd test chmod +x ./tests.py - pytest -n 3 tests.py + pytest -n 3 tests.py --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" diff --git a/test/conftest.py b/test/conftest.py index 580944940..d14efc09c 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -5,9 +5,12 @@ def pytest_addoption(parser): parser.addoption("--source_endpoint", action="store") parser.addoption("--target_endpoint", action="store") - parser.addoption("--auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) - parser.addoption("--username", action="store", default="admin") - parser.addoption("--password", action="store", default="admin") + parser.addoption("--source_auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + parser.addoption("--target_auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + 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") @pytest.fixture @@ -21,15 +24,30 @@ def target_endpoint(pytestconfig): @pytest.fixture -def auth_type(pytestconfig): - return pytestconfig.getoption("auth_type") +def source_auth_type(pytestconfig): + return pytestconfig.getoption("source_auth_type") @pytest.fixture -def username(pytestconfig): - return pytestconfig.getoption("username") +def source_username(pytestconfig): + return pytestconfig.getoption("source_username") @pytest.fixture -def password(pytestconfig): - return pytestconfig.getoption("password") +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") diff --git a/test/tests.py b/test/tests.py index c6b3b7dc0..c69d588f5 100644 --- a/test/tests.py +++ b/test/tests.py @@ -73,13 +73,18 @@ def retry_request(request: Callable, args: Tuple = (), max_attempts: int = 15, d class E2ETests(unittest.TestCase): @pytest.fixture(autouse=True) - def init_fixtures(self, source_endpoint, target_endpoint, auth_type, username, password): + def init_fixtures(self, source_endpoint, target_endpoint, source_auth_type, source_username, source_password, + target_auth_type, target_username, target_password): self.source_endpoint = source_endpoint self.target_endpoint = target_endpoint - self.auth_type = auth_type - self.auth = self.setup_authentication(auth_type, username, password) - self.username = username - self.password = password + self.source_auth_type = source_auth_type + self.source_auth = self.setup_authentication(source_auth_type, source_username, source_password) + self.source_username = source_username + self.source_password = source_password + self.target_auth_type = target_auth_type + self.target_auth = self.setup_authentication(target_auth_type, target_username, target_password) + self.target_username = target_username + self.target_password = target_password def setup_authentication(self, auth_type, username, password): if auth_type == "basic": @@ -94,14 +99,14 @@ def set_common_values(self): def setUp(self): self.set_common_values() - retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.auth), + retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.NOT_FOUND) - retry_request(delete_document, args=(self.proxy_endpoint, self.index, self.doc_id, self.auth), + retry_request(delete_document, args=(self.proxy_endpoint, self.index, self.doc_id, self.source_auth), expected_status_code=HTTPStatus.NOT_FOUND) def tearDown(self): - delete_index(self.proxy_endpoint, self.index, self.auth) - delete_document(self.proxy_endpoint, self.index, self.doc_id, self.auth) + delete_index(self.proxy_endpoint, self.index, self.source_auth) + delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) def test_0001_index(self): # This test will verify that an index will be created (then deleted) on the target cluster when one is created @@ -110,25 +115,25 @@ def test_0001_index(self): # replayer. # Creating an index, then asserting that the index was created on both targets. - proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.auth), + proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(source_response.status_code, HTTPStatus.OK) - proxy_response = retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.auth), + proxy_response = retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) @@ -139,25 +144,26 @@ def test_0002_document(self): # replayer. # Creating an index, then asserting that the index was created on both targets. - proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.auth), + proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(source_response.status_code, HTTPStatus.OK) # Creating a document, then asserting that the document was created on both targets. - proxy_response = create_document(self.proxy_endpoint, self.index, self.doc_id, self.auth) + proxy_response = create_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) self.assertEqual(proxy_response.status_code, HTTPStatus.CREATED) - source_response = get_document(self.source_endpoint, self.index, self.doc_id, self.auth) + source_response = get_document(self.source_endpoint, self.index, self.doc_id, self.source_auth) self.assertEqual(source_response.status_code, HTTPStatus.OK) - target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, self.auth), + target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, + self.target_auth), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) @@ -169,24 +175,26 @@ def test_0002_document(self): self.assertEqual(source_content, target_content) # Deleting the document that was created then asserting that it was deleted on both targets. - proxy_response = delete_document(self.proxy_endpoint, self.index, self.doc_id, self.auth) + proxy_response = delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, self.auth), + target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, + self.target_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) - source_response = retry_request(get_document, args=(self.source_endpoint, self.index, self.doc_id, self.auth), + source_response = retry_request(get_document, args=(self.source_endpoint, self.index, self.doc_id, + self.source_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) # Deleting the index that was created then asserting that it was deleted on both targets. - proxy_response = delete_index(self.proxy_endpoint, self.index, self.auth) + proxy_response = delete_index(self.proxy_endpoint, self.index, self.source_auth) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) @@ -199,8 +207,8 @@ def test_0003_negativeAuth_invalidCreds(self): credentials = [ (username, password), - (self.username, password), - (username, self.password) + (self.source_username, password), + (username, self.source_password) ] for user, pw in credentials: @@ -220,12 +228,12 @@ def test_0004_negativeAuth_missingCreds(self): def test_0005_invalidIncorrectUri(self): # This test will send an invalid URI invalidUri = "/invalidURI" - response = requests.get(f'{self.proxy_endpoint}{invalidUri}', auth=self.auth, verify=False) + response = requests.get(f'{self.proxy_endpoint}{invalidUri}', auth=self.source_auth, verify=False) self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) # This test will send an incorrect URI incorrectUri = "/_cluster/incorrectUri" - response = requests.get(f'{self.proxy_endpoint}{incorrectUri}', auth=self.auth, verify=False) + response = requests.get(f'{self.proxy_endpoint}{incorrectUri}', auth=self.source_auth, verify=False) self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED) def test_0006_OSB(self): @@ -240,8 +248,8 @@ def test_0006_OSB(self): logger.error("Migration-console container was not found, please double check that deployment was a success") self.assert_(False) - source_indices = get_indices(self.source_endpoint, self.auth) - target_indices = get_indices(self.target_endpoint, self.auth) + source_indices = get_indices(self.source_endpoint, self.source_auth) + target_indices = get_indices(self.target_endpoint, self.target_auth) common_indices = set(source_indices) & set(target_indices) valid_indices = [index for index in common_indices if index not in self.ignore_list and index != "searchguard"] @@ -249,8 +257,8 @@ def test_0006_OSB(self): self.assertTrue(valid_indices, "No valid indices found to compare after running OpenSearch Benchmark") for index in valid_indices: - source_count = get_doc_count(self.source_endpoint, index, self.auth) - target_count = get_doc_count(self.target_endpoint, index, self.auth) + source_count = get_doc_count(self.source_endpoint, index, self.source_auth) + target_count = get_doc_count(self.target_endpoint, index, self.target_auth) if source_count != target_count: logger.error(f'{index}: doc counts do not match - Source = {source_count}, Target = {target_count}') From bd3ab8eee32806a8342c6d59584ddc94ed7b667f Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Fri, 1 Dec 2023 15:26:38 -0600 Subject: [PATCH 3/9] Add more authentication parameters to support more scenarios Signed-off-by: Omar Khasawneh --- .github/workflows/e2eTest.yml | 2 +- test/conftest.py | 18 ++++++ test/operations.py | 27 +++++---- test/tests.py | 103 +++++++++++++++++++++------------- 4 files changed, 98 insertions(+), 52 deletions(-) diff --git a/.github/workflows/e2eTest.yml b/.github/workflows/e2eTest.yml index 2e8414055..e34b17aa6 100644 --- a/.github/workflows/e2eTest.yml +++ b/.github/workflows/e2eTest.yml @@ -44,4 +44,4 @@ jobs: run: | cd test chmod +x ./tests.py - pytest -n 3 tests.py --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" + pytest -n 3 tests.py --proxy_endpoint="https://localhost:9200" --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" --source_verify_ssl=False --target_verify_ssl=False diff --git a/test/conftest.py b/test/conftest.py index d14efc09c..f708f1ef5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,16 +3,24 @@ def pytest_addoption(parser): + parser.addoption("--proxy_endpoint", action="store") parser.addoption("--source_endpoint", action="store") parser.addoption("--target_endpoint", action="store") parser.addoption("--source_auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + parser.addoption("--source_verify_ssl", action="store", default="False", choices=["True", "False"]) parser.addoption("--target_auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + parser.addoption("--target_verify_ssl", action="store", default="False", choices=["True", "False"]) 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") +@pytest.fixture +def proxy_endpoint(pytestconfig): + return pytestconfig.getoption("proxy_endpoint") + + @pytest.fixture def source_endpoint(pytestconfig): return pytestconfig.getoption("source_endpoint") @@ -51,3 +59,13 @@ def target_username(pytestconfig): @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") diff --git a/test/operations.py b/test/operations.py index 541073969..73860f759 100644 --- a/test/operations.py +++ b/test/operations.py @@ -3,31 +3,33 @@ 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: Optional[Tuple[str, str]] = None, verify_ssl: bool = False): + response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) 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: Optional[Tuple[str, str]] = None, verify_ssl: bool = False): + 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: Optional[Tuple[str, str]] = None, 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: Optional[Tuple[str, str]] = None, + 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: Optional[Tuple[str, str]] = None, + verify_ssl: bool = False): document = { 'title': 'Test Document', 'content': 'This is a sample document for testing OpenSearch.' @@ -35,15 +37,16 @@ def create_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[ 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: Optional[Tuple[str, str]] = None, + 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 diff --git a/test/tests.py b/test/tests.py index c69d588f5..10efdec4c 100644 --- a/test/tests.py +++ b/test/tests.py @@ -6,7 +6,6 @@ from http import HTTPStatus from typing import Tuple, Callable import unittest -import os import logging import time import requests @@ -20,8 +19,8 @@ logger = logging.getLogger(__name__) -def get_indices(endpoint, auth): - response = requests.get(f'{endpoint}/_cat/indices', auth=auth, verify=False) +def get_indices(endpoint, auth, verify): + response = requests.get(f'{endpoint}/_cat/indices', auth=auth, verify=verify) indices = [] response_lines = response.text.strip().split('\n') for line in response_lines: @@ -31,8 +30,8 @@ def get_indices(endpoint, auth): return indices -def get_doc_count(endpoint, index, auth): - response = requests.get(f'{endpoint}/{index}/_count', auth=auth, verify=False) +def get_doc_count(endpoint, index, auth, verify): + response = requests.get(f'{endpoint}/{index}/_count', auth=auth, verify=verify) count = json.loads(response.text)['count'] return count @@ -73,8 +72,10 @@ def retry_request(request: Callable, args: Tuple = (), max_attempts: int = 15, d class E2ETests(unittest.TestCase): @pytest.fixture(autouse=True) - def init_fixtures(self, source_endpoint, target_endpoint, source_auth_type, source_username, source_password, - target_auth_type, target_username, target_password): + def init_fixtures(self, proxy_endpoint, source_endpoint, target_endpoint, source_auth_type, source_username, + source_password, target_auth_type, target_username, target_password, target_verify_ssl, + source_verify_ssl): + self.proxy_endpoint = proxy_endpoint self.source_endpoint = source_endpoint self.target_endpoint = target_endpoint self.source_auth_type = source_auth_type @@ -85,6 +86,8 @@ def init_fixtures(self, source_endpoint, target_endpoint, source_auth_type, sour self.target_auth = self.setup_authentication(target_auth_type, target_username, target_password) self.target_username = target_username self.target_password = target_password + self.source_verify_ssl = source_verify_ssl.lower() == 'true' + self.target_verify_ssl = target_verify_ssl.lower() == 'true' def setup_authentication(self, auth_type, username, password): if auth_type == "basic": @@ -92,21 +95,27 @@ def setup_authentication(self, auth_type, username, password): return None def set_common_values(self): - self.proxy_endpoint = os.getenv('PROXY_ENDPOINT', 'https://localhost:9200') self.index = f"my_index_{uuid.uuid4()}" self.doc_id = '7' self.ignore_list = [] def setUp(self): self.set_common_values() - retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth), + print(f"Proxy Endpoint: {self.proxy_endpoint}") + retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth, self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) - retry_request(delete_document, args=(self.proxy_endpoint, self.index, self.doc_id, self.source_auth), + retry_request(delete_document, args=(self.proxy_endpoint, self.index, self.doc_id, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) def tearDown(self): - delete_index(self.proxy_endpoint, self.index, self.source_auth) - delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) + source_all_indices = get_indices(self.proxy_endpoint, self.source_auth, self.source_verify_ssl) + target_all_indices = get_indices(self.target_endpoint, self.target_auth, self.target_verify_ssl) + + for index in source_all_indices: + delete_index(self.proxy_endpoint, index, self.source_auth, self.source_verify_ssl) + for index in target_all_indices: + delete_index(self.target_endpoint, index, self.target_auth, self.target_verify_ssl) def test_0001_index(self): # This test will verify that an index will be created (then deleted) on the target cluster when one is created @@ -115,25 +124,31 @@ def test_0001_index(self): # replayer. # Creating an index, then asserting that the index was created on both targets. - proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth), + proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth, + self.target_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(source_response.status_code, HTTPStatus.OK) - proxy_response = retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth), + proxy_response = retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth, + self.target_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) @@ -144,26 +159,31 @@ def test_0002_document(self): # replayer. # Creating an index, then asserting that the index was created on both targets. - proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth), + proxy_response = retry_request(create_index, args=(self.proxy_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth, + self.target_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(source_response.status_code, HTTPStatus.OK) # Creating a document, then asserting that the document was created on both targets. - proxy_response = create_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) + proxy_response = create_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth, + self.source_verify_ssl) self.assertEqual(proxy_response.status_code, HTTPStatus.CREATED) - source_response = get_document(self.source_endpoint, self.index, self.doc_id, self.source_auth) + source_response = get_document(self.source_endpoint, self.index, self.doc_id, self.source_auth, + self.source_verify_ssl) self.assertEqual(source_response.status_code, HTTPStatus.OK) target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, - self.target_auth), + self.target_auth, self.target_verify_ssl), expected_status_code=HTTPStatus.OK) self.assertEqual(target_response.status_code, HTTPStatus.OK) @@ -175,26 +195,29 @@ def test_0002_document(self): self.assertEqual(source_content, target_content) # Deleting the document that was created then asserting that it was deleted on both targets. - proxy_response = delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth) + proxy_response = delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth, + self.source_verify_ssl) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) target_response = retry_request(get_document, args=(self.target_endpoint, self.index, self.doc_id, - self.target_auth), + self.target_auth, self.target_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) source_response = retry_request(get_document, args=(self.source_endpoint, self.index, self.doc_id, - self.source_auth), + self.source_auth, self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) # Deleting the index that was created then asserting that it was deleted on both targets. - proxy_response = delete_index(self.proxy_endpoint, self.index, self.source_auth) + proxy_response = delete_index(self.proxy_endpoint, self.index, self.source_auth, self.source_verify_ssl) self.assertEqual(proxy_response.status_code, HTTPStatus.OK) - target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth), + target_response = retry_request(check_index, args=(self.target_endpoint, self.index, self.target_auth, + self.target_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(target_response.status_code, HTTPStatus.NOT_FOUND) - source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth), + source_response = retry_request(check_index, args=(self.source_endpoint, self.index, self.source_auth, + self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) self.assertEqual(source_response.status_code, HTTPStatus.NOT_FOUND) @@ -212,28 +235,30 @@ def test_0003_negativeAuth_invalidCreds(self): ] for user, pw in credentials: - response = requests.get(self.proxy_endpoint, auth=(user, pw), verify=False) + response = requests.get(self.proxy_endpoint, auth=(user, pw), verify=self.source_verify_ssl) self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED) def test_0004_negativeAuth_missingCreds(self): # This test will use no credentials at all # With an empty authorization header - response = requests.get(self.proxy_endpoint, auth=('', ''), verify=False) + response = requests.get(self.proxy_endpoint, auth=('', ''), verify=self.source_verify_ssl) self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED) # Without an authorization header. - response = requests.get(self.proxy_endpoint, verify=False) + response = requests.get(self.proxy_endpoint, verify=self.source_verify_ssl) self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED) def test_0005_invalidIncorrectUri(self): # This test will send an invalid URI invalidUri = "/invalidURI" - response = requests.get(f'{self.proxy_endpoint}{invalidUri}', auth=self.source_auth, verify=False) + response = requests.get(f'{self.proxy_endpoint}{invalidUri}', auth=self.source_auth, + verify=self.source_verify_ssl) self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) # This test will send an incorrect URI incorrectUri = "/_cluster/incorrectUri" - response = requests.get(f'{self.proxy_endpoint}{incorrectUri}', auth=self.source_auth, verify=False) + response = requests.get(f'{self.proxy_endpoint}{incorrectUri}', auth=self.source_auth, + verify=self.source_verify_ssl) self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED) def test_0006_OSB(self): @@ -248,8 +273,8 @@ def test_0006_OSB(self): logger.error("Migration-console container was not found, please double check that deployment was a success") self.assert_(False) - source_indices = get_indices(self.source_endpoint, self.source_auth) - target_indices = get_indices(self.target_endpoint, self.target_auth) + source_indices = get_indices(self.source_endpoint, self.source_auth, self.source_verify_ssl) + target_indices = get_indices(self.target_endpoint, self.target_auth, self.target_verify_ssl) common_indices = set(source_indices) & set(target_indices) valid_indices = [index for index in common_indices if index not in self.ignore_list and index != "searchguard"] @@ -257,8 +282,8 @@ def test_0006_OSB(self): self.assertTrue(valid_indices, "No valid indices found to compare after running OpenSearch Benchmark") for index in valid_indices: - source_count = get_doc_count(self.source_endpoint, index, self.source_auth) - target_count = get_doc_count(self.target_endpoint, index, self.target_auth) + source_count = get_doc_count(self.source_endpoint, index, self.source_auth, self.source_verify_ssl) + target_count = get_doc_count(self.target_endpoint, index, self.target_auth, self.target_verify_ssl) if source_count != target_count: logger.error(f'{index}: doc counts do not match - Source = {source_count}, Target = {target_count}') From e16999af3bafdae272b19fea8524ee8f10c3dabd Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Fri, 1 Dec 2023 16:06:19 -0600 Subject: [PATCH 4/9] Fix failing workflow Signed-off-by: Omar Khasawneh --- .github/workflows/e2eTest.yml | 2 +- test/tests.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2eTest.yml b/.github/workflows/e2eTest.yml index e34b17aa6..7d5bd660b 100644 --- a/.github/workflows/e2eTest.yml +++ b/.github/workflows/e2eTest.yml @@ -44,4 +44,4 @@ jobs: run: | cd test chmod +x ./tests.py - pytest -n 3 tests.py --proxy_endpoint="https://localhost:9200" --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" --source_verify_ssl=False --target_verify_ssl=False + pytest tests.py --proxy_endpoint="https://localhost:9200" --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" --source_verify_ssl=False --target_verify_ssl=False diff --git a/test/tests.py b/test/tests.py index 10efdec4c..83bae3209 100644 --- a/test/tests.py +++ b/test/tests.py @@ -101,7 +101,6 @@ def set_common_values(self): def setUp(self): self.set_common_values() - print(f"Proxy Endpoint: {self.proxy_endpoint}") retry_request(delete_index, args=(self.proxy_endpoint, self.index, self.source_auth, self.source_verify_ssl), expected_status_code=HTTPStatus.NOT_FOUND) retry_request(delete_document, args=(self.proxy_endpoint, self.index, self.doc_id, self.source_auth, @@ -109,13 +108,8 @@ def setUp(self): expected_status_code=HTTPStatus.NOT_FOUND) def tearDown(self): - source_all_indices = get_indices(self.proxy_endpoint, self.source_auth, self.source_verify_ssl) - target_all_indices = get_indices(self.target_endpoint, self.target_auth, self.target_verify_ssl) - - for index in source_all_indices: - delete_index(self.proxy_endpoint, index, self.source_auth, self.source_verify_ssl) - for index in target_all_indices: - delete_index(self.target_endpoint, index, self.target_auth, self.target_verify_ssl) + delete_index(self.proxy_endpoint, self.index, self.source_auth, self.source_verify_ssl) + delete_document(self.proxy_endpoint, self.index, self.doc_id, self.source_auth, self.source_verify_ssl) def test_0001_index(self): # This test will verify that an index will be created (then deleted) on the target cluster when one is created From c009947235963a875418900140200d015a1a2f7f Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Wed, 6 Dec 2023 14:53:46 -0600 Subject: [PATCH 5/9] Add default values for parameters + Update documentation Signed-off-by: Omar Khasawneh --- test/README.md | 54 +++++++++++++++++++++++++++++++++++++++++------- test/conftest.py | 10 ++++----- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/test/README.md b/test/README.md index e7fbe1534..957c66ba1 100644 --- a/test/README.md +++ b/test/README.md @@ -24,14 +24,52 @@ pytest tests.py The test script, by default, uses the ports assigned to the containers in this [docker-compose file](../TrafficCapture/dockerSolution/src/main/docker/docker-compose.yml), so if the Docker solution in its current setup started with no issues, then the test script will run as is. If for any reason -the user changed the ports in that file, they must also either, change the following environment variables: -`PROXY_ENDPOINT`, `SOURCE_ENDPOINT`, and `TARGET_ENDPOINT` respectively, or update the default value -(which can be found below) for them in [tests.py](tests.py). - -The following are the default values for the only endpoints touched by this script: -* `PROXY_ENDPOINT = https://localhost:9200` -* `SOURCE_ENDPOINT = http://localhost:19200` -* `TARGET_ENDPOINT = https://localhost:29200` +the user changed the ports in that file, they must also either, provide the following parameters variables: +`proxy_endpoint`, `source_endpoint`, and `target_endpoint` respectively, or update the default value + for them in [conftest.py](conftest.py). + + +#### Script Parameters + +This script accepts various parameters to customize its behavior. Below is a list of available parameters along with their default values and acceptable choices: + +- `--proxy_endpoint`: The endpoint for the proxy endpoint. + - Default: `https://localhost:9200` + +- `--source_endpoint`: The endpoint for the source endpoint. + - Default: `https://localhost:19200` + +- `--target_endpoint`: The endpoint for the target endpoint. + - Default: `https://localhost:29200` + +- `--source_auth_type`: Specifies the authentication type for the source endpoint. + - Default: `basic` + - Choices: `none`, `basic`, `sigv4` + +- `--source_verify_ssl`: Determines whether to verify the SSL certificate for the source endpoint. + - Default: `False` + - Choices: `True`, `False` + +- `--target_auth_type`: Specifies the authentication type for the target endpoint. + - Default: `basic` + - Choices: `none`, `basic`, `sigv4` + +- `--target_verify_ssl`: Determines whether to verify the SSL certificate for the target endpoint. + - Default: `False` + - Choices: `True`, `False` + +- `--source_username`: Username for authentication with the source endpoint. + - Default: `admin` + +- `--source_password`: Password for authentication with the source endpoint. + - Default: `admin` + +- `--target_username`: Username for authentication with the target endpoint. + - Default: `admin` + +- `--target_password`: Password for authentication with the target endpoint. + - Default: `admin` + #### Clean Up The test script is implemented with a setup and teardown functions that are ran after diff --git a/test/conftest.py b/test/conftest.py index f708f1ef5..de02de51f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,12 +3,12 @@ def pytest_addoption(parser): - parser.addoption("--proxy_endpoint", action="store") - parser.addoption("--source_endpoint", action="store") - parser.addoption("--target_endpoint", action="store") - parser.addoption("--source_auth_type", action="store", default="none", choices=["none", "basic", "sigv4"]) + 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="none", choices=["none", "basic", "sigv4"]) + 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("--source_username", action="store", default="admin") parser.addoption("--source_password", action="store", default="admin") From f7213996e07c7bd07c97c9567df4319b4ca305d6 Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Tue, 2 Jan 2024 17:25:12 -0600 Subject: [PATCH 6/9] No longer need to specify parameters as there are default values now Signed-off-by: Omar Khasawneh --- .github/workflows/e2eTest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2eTest.yml b/.github/workflows/e2eTest.yml index 7d5bd660b..9b029dbe4 100644 --- a/.github/workflows/e2eTest.yml +++ b/.github/workflows/e2eTest.yml @@ -44,4 +44,4 @@ jobs: run: | cd test chmod +x ./tests.py - pytest tests.py --proxy_endpoint="https://localhost:9200" --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" --source_verify_ssl=False --target_verify_ssl=False + pytest tests.py From 8e2a3c6bf7cfcc98e67d620ab096584126920c81 Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Wed, 3 Jan 2024 09:10:06 -0600 Subject: [PATCH 7/9] Add SigV4 Support Signed-off-by: Omar Khasawneh --- test/conftest.py | 12 ++++++++++++ test/operations.py | 15 ++++++--------- test/requirements.txt | 2 ++ test/tests.py | 8 ++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index de02de51f..c72147a8a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,18 @@ # 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") diff --git a/test/operations.py b/test/operations.py index 73860f759..0962f4b26 100644 --- a/test/operations.py +++ b/test/operations.py @@ -1,34 +1,33 @@ import requests import json -from typing import Optional, Tuple -def create_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = 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) return response -def check_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = 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, verify_ssl: bool = 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, +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', @@ -36,17 +35,15 @@ def create_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[ } 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=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=verify_ssl) return response diff --git a/test/requirements.txt b/test/requirements.txt index cd894ab19..98a491507 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -8,3 +8,5 @@ pytest==7.3.1 pytest-xdist==3.3.1 requests==2.31.0 urllib3==2.0.7 +requests_aws4auth +boto3 \ No newline at end of file diff --git a/test/tests.py b/test/tests.py index 83bae3209..d14594a97 100644 --- a/test/tests.py +++ b/test/tests.py @@ -13,6 +13,8 @@ import string import secrets import pytest +import boto3 +from requests_aws4auth import AWS4Auth from requests.exceptions import ConnectionError, SSLError @@ -92,6 +94,12 @@ def init_fixtures(self, proxy_endpoint, source_endpoint, target_endpoint, source def setup_authentication(self, auth_type, username, password): if auth_type == "basic": return (username, password) + elif auth_type == "sigv4": + session = boto3.Session() + credentials = session.get_credentials() + aws_auth = AWS4Auth(credentials.access_key, credentials.secret_key, session.region_name, 'es', + session_token=credentials.token) + return aws_auth return None def set_common_values(self): From cb13a8588b1b57aff842705ed3e2ee7620948d6c Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Mon, 8 Jan 2024 16:55:17 -0600 Subject: [PATCH 8/9] Add unique index parameter + accomodate cloud deployment for OSB test Signed-off-by: Omar Khasawneh --- .github/workflows/e2eTest.yml | 2 +- test/conftest.py | 12 ++++++++++++ test/tests.py | 29 ++++++++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.github/workflows/e2eTest.yml b/.github/workflows/e2eTest.yml index 9b029dbe4..7393ca28c 100644 --- a/.github/workflows/e2eTest.yml +++ b/.github/workflows/e2eTest.yml @@ -44,4 +44,4 @@ jobs: run: | cd test chmod +x ./tests.py - pytest tests.py + pytest tests.py --unique_id="testindex" diff --git a/test/conftest.py b/test/conftest.py index c72147a8a..c88069a1d 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -22,10 +22,12 @@ def pytest_addoption(parser): 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 @@ -81,3 +83,13 @@ def target_verify_ssl(pytestconfig): @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") diff --git a/test/tests.py b/test/tests.py index d14594a97..38882bcac 100644 --- a/test/tests.py +++ b/test/tests.py @@ -9,7 +9,6 @@ import logging import time import requests -import uuid import string import secrets import pytest @@ -76,7 +75,7 @@ class E2ETests(unittest.TestCase): @pytest.fixture(autouse=True) def init_fixtures(self, proxy_endpoint, source_endpoint, target_endpoint, source_auth_type, source_username, source_password, target_auth_type, target_username, target_password, target_verify_ssl, - source_verify_ssl): + source_verify_ssl, deployment_type, unique_id): self.proxy_endpoint = proxy_endpoint self.source_endpoint = source_endpoint self.target_endpoint = target_endpoint @@ -90,6 +89,8 @@ def init_fixtures(self, proxy_endpoint, source_endpoint, target_endpoint, source self.target_password = target_password self.source_verify_ssl = source_verify_ssl.lower() == 'true' self.target_verify_ssl = target_verify_ssl.lower() == 'true' + self.deployment_type = deployment_type + self.unique_id = unique_id def setup_authentication(self, auth_type, username, password): if auth_type == "basic": @@ -103,7 +104,7 @@ def setup_authentication(self, auth_type, username, password): return None def set_common_values(self): - self.index = f"my_index_{uuid.uuid4()}" + self.index = self.unique_id self.doc_id = '7' self.ignore_list = [] @@ -264,16 +265,22 @@ def test_0005_invalidIncorrectUri(self): self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED) def test_0006_OSB(self): - cmd = ['docker', 'ps', '--format="{{.ID}}"', '--filter', 'name=migration'] - container_id = subprocess.run(cmd, stdout=subprocess.PIPE, text=True).stdout.strip().replace('"', '') - - if container_id: - cmd_exec = f"docker exec {container_id} ./runTestBenchmarks.sh" - logger.warning(f"Running command: {cmd_exec}") + if self.deployment_type == "cloud": + cmd_exec = f"./runTestBenchmarks --unique-id {self.index}" + logger.warning(f"Running local command: {cmd_exec}") subprocess.run(cmd_exec, shell=True) else: - logger.error("Migration-console container was not found, please double check that deployment was a success") - self.assert_(False) + cmd = ['docker', 'ps', '--format="{{.ID}}"', '--filter', 'name=migration'] + container_id = subprocess.run(cmd, stdout=subprocess.PIPE, text=True).stdout.strip().replace('"', '') + + if container_id: + cmd_exec = f"docker exec {container_id} ./runTestBenchmarks.sh" + logger.warning(f"Running command: {cmd_exec}") + subprocess.run(cmd_exec, shell=True) + else: + logger.error("Migration-console container was not found," + " please double check that deployment was a success") + self.assert_(False) source_indices = get_indices(self.source_endpoint, self.source_auth, self.source_verify_ssl) target_indices = get_indices(self.target_endpoint, self.target_auth, self.target_verify_ssl) From c7c1da39b7fad2433489e682f0ad3d7fddf85981 Mon Sep 17 00:00:00 2001 From: Omar Khasawneh Date: Tue, 9 Jan 2024 11:48:07 -0600 Subject: [PATCH 9/9] fix path + update index name Signed-off-by: Omar Khasawneh --- test/operations.py | 4 ++-- test/tests.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/operations.py b/test/operations.py index 0962f4b26..f3a7d986f 100644 --- a/test/operations.py +++ b/test/operations.py @@ -2,13 +2,13 @@ import json -def create_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'): +def create_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False): response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) return response -def check_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'): +def check_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False): response = requests.get(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl) return response diff --git a/test/tests.py b/test/tests.py index 38882bcac..2febde075 100644 --- a/test/tests.py +++ b/test/tests.py @@ -104,7 +104,7 @@ def setup_authentication(self, auth_type, username, password): return None def set_common_values(self): - self.index = self.unique_id + self.index = f"test_index_{self.unique_id}" self.doc_id = '7' self.ignore_list = [] @@ -266,7 +266,7 @@ def test_0005_invalidIncorrectUri(self): def test_0006_OSB(self): if self.deployment_type == "cloud": - cmd_exec = f"./runTestBenchmarks --unique-id {self.index}" + cmd_exec = f"/root/runTestBenchmarks.sh --unique-id {self.unique_id}" logger.warning(f"Running local command: {cmd_exec}") subprocess.run(cmd_exec, shell=True) else: