Skip to content

Commit

Permalink
Reorg into utils and test and change export to env
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <dxho@amazon.com>
  • Loading branch information
derek-ho committed Jan 10, 2024
1 parent e450957 commit 0dcfd3d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
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",
"opensearch-dashboards": "./opensearch-dashboards",
}
return start_cmd_map[self.filename]
Expand Down
7 changes: 2 additions & 5 deletions src/test_workflow/integ_test/service_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import os

import requests
import semver
import yaml
from requests.models import Response
from utils import get_password

from test_workflow.dependency_installer import DependencyInstaller
from test_workflow.integ_test.distribution import Distribution
Expand Down Expand Up @@ -64,12 +64,9 @@ def url(self, path: str = "") -> str:
return f'{"https" if self.security_enabled else "http"}://{self.endpoint()}:{self.port()}{path}'

def get_service_response(self) -> Response:
password = "admin"
if semver.compare(self.version, '2.12.0') != -1:
password = "myStrongPassword123!"
url = self.url("/_cluster/health")
logging.info(f"Pinging {url}")
return requests.get(url, verify=False, auth=("admin", 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
7 changes: 2 additions & 5 deletions src/test_workflow/integ_test/service_opensearch_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import subprocess

import requests
import semver
import yaml
from requests.models import Response
from utils import get_password

from system.os import current_platform
from test_workflow.dependency_installer import DependencyInstaller
Expand Down Expand Up @@ -85,12 +85,9 @@ def url(self, path: str = "") -> str:
return f'http://{self.endpoint()}:{self.port()}{path}'

def get_service_response(self) -> Response:
password = "admin"
if semver.compare(self.version, '2.12.0') != -1:
password = "myStrongPassword123!"
url = self.url("/api/status")
logging.info(f"Pinging {url}")
return requests.get(url, verify=False, auth=("admin", password) 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:
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
@@ -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 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"))

0 comments on commit 0dcfd3d

Please sign in to comment.