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

Pass in strong password to OSD integ test if version >= 2.12.0 #4334

Merged
merged 25 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/test_workflow/integ_test/distribution_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def install(self, bundle_name: str) -> None:
@property
def start_cmd(self) -> str:
start_cmd_map = {
"opensearch": "export OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! && ./opensearch-tar-install.sh",
"opensearch": "env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! ./opensearch-tar-install.sh",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to env from suggestion from @peterzhuamazon. Can somebody with insight explain why this might work better? From the jenkins failures it looks like either the cluster is not being spun up successfully with strong password, or the health check is not using the correct credential, even though I have made changes that I think should solve both of these. It seems like this command is run with python subprocess, might that have something to do with it?

"opensearch-dashboards": "./opensearch-dashboards",
}
return start_cmd_map[self.filename]
Expand Down
4 changes: 2 additions & 2 deletions src/test_workflow/integ_test/service_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distributions import Distributions
from test_workflow.integ_test.service import Service
from test_workflow.integ_test.utils import get_password


class ServiceOpenSearch(Service):
Expand All @@ -40,7 +41,6 @@ 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 @@ -66,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", self.password))
return requests.get(url, verify=False, auth=("admin", get_password(self.version)))

def __add_plugin_specific_config(self, additional_config: dict) -> None:
with open(self.opensearch_yml_path, "a") as yamlfile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distributions import Distributions
from test_workflow.integ_test.service import Service
from test_workflow.integ_test.utils import get_password


class ServiceOpenSearchDashboards(Service):
Expand Down Expand Up @@ -86,7 +87,7 @@ def url(self, path: str = "") -> str:
def get_service_response(self) -> Response:
url = self.url("/api/status")
logging.info(f"Pinging {url}")
return requests.get(url, verify=False, auth=("admin", "admin") if self.security_enabled else None)
return requests.get(url, verify=False, auth=("admin", get_password(self.version)) if self.security_enabled else None)

def __add_plugin_specific_config(self, additional_config: dict) -> None:
with open(self.opensearch_dashboards_yml_path, "a") as yamlfile:
Expand Down
16 changes: 16 additions & 0 deletions src/test_workflow/integ_test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import semver


def get_password(version: str) -> str:
# Starting in 2.12.0, demo configuration setup script requires a strong password
if semver.compare(version, '2.12.0') != -1:
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
return "myStrongPassword123!"
else:
return "admin"
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_install(self) -> None:
mock_tarfile_extractall.assert_called_with(self.work_dir)

def test_start_cmd(self) -> None:
self.assertEqual(self.distribution_tar.start_cmd, "export OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! && ./opensearch-tar-install.sh")
self.assertEqual(self.distribution_tar.start_cmd, "env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! ./opensearch-tar-install.sh")
self.assertEqual(self.distribution_tar_dashboards.start_cmd, "./opensearch-dashboards")

@patch("subprocess.check_call")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_start(self, mock_tarfile_open: Mock, mock_dump: Mock, mock_file: Mock,
# call test target function
service.start()

mock_process.assert_called_once_with("export OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! && ./opensearch-tar-install.sh", os.path.join(self.work_dir, "opensearch-1.1.0"), False)
mock_process.assert_called_once_with("env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! && ./opensearch-tar-install.sh", os.path.join(self.work_dir, "opensearch-1.1.0"), False)
derek-ho marked this conversation as resolved.
Show resolved Hide resolved

mock_dump.assert_called_once_with(self.additional_config)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import unittest

from test_workflow.integ_test.utils import get_password


class TestUtils(unittest.TestCase):
def test_strong_password(self) -> None:
self.assertEqual("admin", get_password("2.11.1"))
self.assertEqual("myStrongPassword123!", get_password("3.0.0"))
Loading