From 6eb6f8b3530fdf3099c9ed2fb2663b9e4e19c4b8 Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Tue, 9 Jan 2024 17:40:40 -0500 Subject: [PATCH] Change password based on version in integtest health check (#4331) Signed-off-by: Derek Ho --- src/test_workflow/integ_test/service_opensearch.py | 3 ++- src/test_workflow/perf_test/perf_test_cluster.py | 8 +++++++- .../perf_test/data/bundle_manifest.yml | 2 +- .../perf_test/test_perf_test_cluster.py | 11 ++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/test_workflow/integ_test/service_opensearch.py b/src/test_workflow/integ_test/service_opensearch.py index 3f6d23790c..0f9cef9413 100644 --- a/src/test_workflow/integ_test/service_opensearch.py +++ b/src/test_workflow/integ_test/service_opensearch.py @@ -40,6 +40,7 @@ def __init__( self.dist = Distributions.get_distribution("opensearch", distribution, version, work_dir) self.dependency_installer = dependency_installer self.install_dir = self.dist.install_dir + self.password = 'myStrongPassword123!' if float('.'.join(self.version.split('.')[:2])) >= 2.12 else 'admin' def start(self) -> None: self.dist.install(self.download()) @@ -65,7 +66,7 @@ def url(self, path: str = "") -> str: def get_service_response(self) -> Response: url = self.url("/_cluster/health") logging.info(f"Pinging {url}") - return requests.get(url, verify=False, auth=("admin", "admin")) + return requests.get(url, verify=False, auth=("admin", self.password)) def __add_plugin_specific_config(self, additional_config: dict) -> None: with open(self.opensearch_yml_path, "a") as yamlfile: diff --git a/src/test_workflow/perf_test/perf_test_cluster.py b/src/test_workflow/perf_test/perf_test_cluster.py index 93213f0402..6a034a0d9b 100644 --- a/src/test_workflow/perf_test/perf_test_cluster.py +++ b/src/test_workflow/perf_test/perf_test_cluster.py @@ -15,6 +15,7 @@ from typing import Any, Generator, List import requests +import semver from requests.auth import HTTPBasicAuth from retry.api import retry_call # type: ignore @@ -108,11 +109,16 @@ def dependencies(self) -> List[Service]: return [] def wait_for_processing(self, tries: int = 3, delay: int = 15, backoff: int = 2) -> None: + password = 'admin' + if self.manifest: + if semver.compare(self.manifest.build.version, '2.12.0') != -1: + password = 'myStrongPassword123!' + # Should be invoked only if the endpoint is public. assert self.is_endpoint_public, "wait_for_processing should be invoked only when cluster is public" logging.info("Waiting for domain to be up") url = "".join([self.endpoint_with_port, "/_cluster/health"]) - retry_call(requests.get, fkwargs={"url": url, "auth": HTTPBasicAuth('admin', 'admin'), "verify": False}, + retry_call(requests.get, fkwargs={"url": url, "auth": HTTPBasicAuth('admin', password), "verify": False}, tries=tries, delay=delay, backoff=backoff) @abc.abstractmethod diff --git a/tests/tests_test_workflow/test_perf_workflow/perf_test/data/bundle_manifest.yml b/tests/tests_test_workflow/test_perf_workflow/perf_test/data/bundle_manifest.yml index 425c1fa2a3..b819854cee 100644 --- a/tests/tests_test_workflow/test_perf_workflow/perf_test/data/bundle_manifest.yml +++ b/tests/tests_test_workflow/test_perf_workflow/perf_test/data/bundle_manifest.yml @@ -5,7 +5,7 @@ build: id: 41d5ae25183d4e699e92debfbe3f83bd location: https://artifacts.opensearch.org/bundles/1.0.0/41d5ae25183d4e699e92debfbe3f83bd/opensearch-1.0.0-linux-x64.tar.gz name: OpenSearch - version: 1.0.0 + version: 3.0.0 components: - commit_id: fb25458f38c30a7ab06de21b0068f1fe3ad56134 location: https://artifacts.opensearch.org/builds/1.0.0/41d5ae25183d4e699e92debfbe3f83bd/bundle/opensearch-min-1.0.0-linux-x64.tar.gz diff --git a/tests/tests_test_workflow/test_perf_workflow/perf_test/test_perf_test_cluster.py b/tests/tests_test_workflow/test_perf_workflow/perf_test/test_perf_test_cluster.py index 632a772c9a..f31fbebb53 100644 --- a/tests/tests_test_workflow/test_perf_workflow/perf_test/test_perf_test_cluster.py +++ b/tests/tests_test_workflow/test_perf_workflow/perf_test/test_perf_test_cluster.py @@ -7,7 +7,9 @@ import os import unittest -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, Mock, patch + +from requests.auth import HTTPBasicAuth from manifests.bundle_manifest import BundleManifest from test_workflow.perf_test.perf_test_cluster import PerfTestCluster @@ -37,6 +39,13 @@ def test_create(self) -> None: mock_chdir.assert_called_once_with(os.path.join(self.perf_test_cluster.current_workspace, "test_dir")) self.assertEqual(mock_check_call.call_count, 1) + @patch("requests.get") + def test_get_service_response(self, mock_requests_get: Mock) -> None: + self.perf_test_cluster.is_endpoint_public = True + self.perf_test_cluster.cluster_endpoint_with_port = '' + self.perf_test_cluster.wait_for_processing() + mock_requests_get.assert_called_with(url='/_cluster/health', verify=False, auth=HTTPBasicAuth('admin', 'myStrongPassword123!')) + def test_endpoint(self) -> None: self.assertEqual(self.perf_test_cluster.endpoint_with_port, None)