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

Change password based on version in integtest health check #4331

Merged
merged 16 commits into from
Jan 9, 2024
3 changes: 2 additions & 1 deletion src/test_workflow/integ_test/service_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion src/test_workflow/perf_test/perf_test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down