From 35bb9023550cda84689e04517a813f7111a56e3c Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 19 Oct 2022 15:47:12 -0400 Subject: [PATCH] Add windows integTest to OpenSearch Clusters (#2761) * Add new setups Signed-off-by: Peter Zhu * Add windows integTest to OpenSearch Clusters Signed-off-by: Your Name Signed-off-by: Peter Zhu * Restructure zip tests Signed-off-by: Peter Zhu Signed-off-by: Peter Zhu Signed-off-by: Your Name Co-authored-by: Your Name --- .../integ_test/distribution_zip.py | 43 ++++++++ src/test_workflow/integ_test/distributions.py | 2 + .../integ_test/integ_test_suite.py | 2 +- .../service_opensearch_dashboards.py | 4 +- .../dist/opensearch-min-2.4.0-windows-x64.zip | Bin 0 -> 566 bytes .../integ_test/test_distribution_zip.py | 96 ++++++++++++++++++ ..._integ_test_suite_opensearch_dashboards.py | 2 +- .../test_service_opensearch_dashboards.py | 4 +- 8 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 src/test_workflow/integ_test/distribution_zip.py create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-2.4.0-windows-x64.zip create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_zip.py diff --git a/src/test_workflow/integ_test/distribution_zip.py b/src/test_workflow/integ_test/distribution_zip.py new file mode 100644 index 0000000000..39089c9886 --- /dev/null +++ b/src/test_workflow/integ_test/distribution_zip.py @@ -0,0 +1,43 @@ +# 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 logging +import os +import subprocess + +from system.zip_file import ZipFile +from test_workflow.integ_test.distribution import Distribution + + +class DistributionZip(Distribution): + def __init__(self, filename: str, version: str, work_dir: str) -> None: + super().__init__(filename, version, work_dir) + + @property + def install_dir(self) -> str: + return os.path.join(self.work_dir, f"{self.filename}-{self.version}") + + @property + def config_dir(self) -> str: + return os.path.join(self.install_dir, "config") + + def install(self, bundle_name: str) -> None: + logging.info(f"Installing {bundle_name} in {self.install_dir}") + with ZipFile(bundle_name, "r") as zip: + zip.extractall(self.work_dir) + + @property + def start_cmd(self) -> str: + start_cmd_map = { + "opensearch": "./opensearch-windows-install.bat", + "opensearch-dashboards": "./opensearch-dashboards.bat", + } + return start_cmd_map[self.filename] + + def uninstall(self) -> None: + logging.info(f"Cleanup {self.work_dir}/* content after the test") + subprocess.check_call(f"rm -rf {self.work_dir}/*", shell=True) diff --git a/src/test_workflow/integ_test/distributions.py b/src/test_workflow/integ_test/distributions.py index 7337fa63bd..19d7970a9e 100644 --- a/src/test_workflow/integ_test/distributions.py +++ b/src/test_workflow/integ_test/distributions.py @@ -10,12 +10,14 @@ from test_workflow.integ_test.distribution import Distribution from test_workflow.integ_test.distribution_rpm import DistributionRpm from test_workflow.integ_test.distribution_tar import DistributionTar +from test_workflow.integ_test.distribution_zip import DistributionZip class Distributions: DISTRIBUTIONS_MAP = { "tar": DistributionTar, "rpm": DistributionRpm, + "zip": DistributionZip, } @classmethod diff --git a/src/test_workflow/integ_test/integ_test_suite.py b/src/test_workflow/integ_test/integ_test_suite.py index 876da30684..d1f273376a 100644 --- a/src/test_workflow/integ_test/integ_test_suite.py +++ b/src/test_workflow/integ_test/integ_test_suite.py @@ -76,7 +76,7 @@ def execute_tests(self) -> TestComponentResults: def execute_integtest_sh(self, endpoint: str, port: int, security: bool, test_config: str) -> int: script = ScriptFinder.find_integ_test_script(self.component.name, self.repo.working_directory) if os.path.exists(script): - cmd = f"{script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}" + cmd = f"bash {script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}" self.repo_work_dir = os.path.join( self.repo.dir, self.test_config.working_directory) if self.test_config.working_directory is not None else self.repo.dir (status, stdout, stderr) = execute(cmd, self.repo_work_dir, True, False) diff --git a/src/test_workflow/integ_test/service_opensearch_dashboards.py b/src/test_workflow/integ_test/service_opensearch_dashboards.py index 2a393c858e..f8efe61fc6 100644 --- a/src/test_workflow/integ_test/service_opensearch_dashboards.py +++ b/src/test_workflow/integ_test/service_opensearch_dashboards.py @@ -13,6 +13,7 @@ import yaml from requests.models import Response +from system.os import current_platform from test_workflow.dependency_installer import DependencyInstaller from test_workflow.integ_test.distribution import Distribution from test_workflow.integ_test.distributions import Distributions @@ -66,7 +67,8 @@ def __set_logging_dest(self) -> None: def __remove_security(self) -> None: self.security_plugin_dir = os.path.join(self.install_dir, "plugins", "securityDashboards") if os.path.isdir(self.security_plugin_dir): - subprocess.check_call("./opensearch-dashboards-plugin remove --allow-root securityDashboards", cwd=self.executable_dir, shell=True) + plugin_script = "opensearch-dashboards-plugin.bat" if current_platform() == "windows" else "bash opensearch-dashboards-plugin" + subprocess.check_call(f"{plugin_script} remove --allow-root securityDashboards", cwd=self.executable_dir, shell=True) with open(self.opensearch_dashboards_yml_dir, "w") as yamlfile: yamlfile.close() diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-2.4.0-windows-x64.zip b/tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-2.4.0-windows-x64.zip new file mode 100644 index 0000000000000000000000000000000000000000..ae959c5d146205885eb67cc4b74a3d382676721e GIT binary patch literal 566 zcmWIWW@h1H0D+2aL7`vV~XQb$4p+exEt zgFoq0(i2izR){indpaDMp^(Jo;KX<&Ev&KQ@kU{W&=6h*c4j^QWDtI@>z^C|cc4MO zbZ|CzP`nDzdJvXpD8O_e!o_+e6(zwg(J<%MyQ>$I>RfMR*9Hp-7^-#5V44uXusKxW zQNwt6-BZvn82?3Ps literal 0 HcmV?d00001 diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_zip.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_zip.py new file mode 100644 index 0000000000..538ddcd726 --- /dev/null +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_zip.py @@ -0,0 +1,96 @@ +# 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 os +import unittest +from unittest.mock import MagicMock, Mock, patch + +from test_workflow.integ_test.distribution_zip import DistributionZip + + +class TestDistributionZipOpenSearch(unittest.TestCase): + + def setUp(self) -> None: + + self.work_dir = os.path.join(os.path.dirname(__file__), "data") + self.product = "opensearch" + self.version = "2.4.0" + self.distribution_zip = DistributionZip(self.product, self.version, self.work_dir) + + def test_distribution_zip_vars(self) -> None: + self.assertEqual(self.distribution_zip.filename, self.product) + self.assertEqual(self.distribution_zip.version, self.version) + self.assertEqual(self.distribution_zip.work_dir, self.work_dir) + + def test_install_dir(self) -> None: + self.assertEqual(self.distribution_zip.install_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}")) + + def test_config_dir(self) -> None: + self.assertEqual(self.distribution_zip.config_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "config")) + + def test_install(self) -> None: + with patch("test_workflow.integ_test.distribution_zip.ZipFile") as mock_zipfile_open: + mock_zipfile_extractall = MagicMock() + mock_zipfile_open.return_value.__enter__.return_value.extractall = mock_zipfile_extractall + + self.distribution_zip.install(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip")) + + mock_zipfile_open.assert_called_with(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"), "r") + mock_zipfile_extractall.assert_called_with(self.work_dir) + + def test_start_cmd(self) -> None: + self.assertEqual(self.distribution_zip.start_cmd, "./opensearch-windows-install.bat") + + @patch("subprocess.check_call") + def test_uninstall(self, check_call_mock: Mock) -> None: + self.distribution_zip.uninstall() + args_list = check_call_mock.call_args_list + + self.assertEqual(check_call_mock.call_count, 1) + self.assertEqual(f"rm -rf {self.work_dir}/*", args_list[0][0][0]) + + +class TestDistributionZipOpenSearchDashboards(unittest.TestCase): + + def setUp(self) -> None: + + self.work_dir = os.path.join(os.path.dirname(__file__), "data") + self.product = "opensearch-dashboards" + self.version = "2.4.0" + self.distribution_zip = DistributionZip(self.product, self.version, self.work_dir) + + def test_distribution_zip_vars(self) -> None: + self.assertEqual(self.distribution_zip.filename, self.product) + self.assertEqual(self.distribution_zip.version, self.version) + self.assertEqual(self.distribution_zip.work_dir, self.work_dir) + + def test_install_dir(self) -> None: + self.assertEqual(self.distribution_zip.install_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}")) + + def test_config_dir(self) -> None: + self.assertEqual(self.distribution_zip.config_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "config")) + + def test_install(self) -> None: + with patch("test_workflow.integ_test.distribution_zip.ZipFile") as mock_zipfile_open: + mock_zipfile_extractall = MagicMock() + mock_zipfile_open.return_value.__enter__.return_value.extractall = mock_zipfile_extractall + + self.distribution_zip.install(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip")) + + mock_zipfile_open.assert_called_with(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"), "r") + mock_zipfile_extractall.assert_called_with(self.work_dir) + + def test_start_cmd(self) -> None: + self.assertEqual(self.distribution_zip.start_cmd, "./opensearch-dashboards.bat") + + @patch("subprocess.check_call") + def test_uninstall(self, check_call_mock: Mock) -> None: + self.distribution_zip.uninstall() + args_list = check_call_mock.call_args_list + + self.assertEqual(check_call_mock.call_count, 1) + self.assertEqual(f"rm -rf {self.work_dir}/*", args_list[0][0][0]) diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_integ_test_suite_opensearch_dashboards.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_integ_test_suite_opensearch_dashboards.py index 1c109d453b..a7495d62d8 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_integ_test_suite_opensearch_dashboards.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_integ_test_suite_opensearch_dashboards.py @@ -135,7 +135,7 @@ def test_execute_integtest_sh(self, mock_execute: Mock, mock_git: Mock, mock_tes status = suite.execute_integtest_sh("test_endpoint", 1234, True, "with-security") self.assertEqual(status, "test_status") - mock_execute.assert_called_once_with('./integtest.sh -b test_endpoint -p 1234 -s true -v 1.2.0', + mock_execute.assert_called_once_with('bash ./integtest.sh -b test_endpoint -p 1234 -s true -v 1.2.0', os.path.join("dir", "test_working_directory"), True, False) mock_test_result_data.assert_called_once_with( diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch_dashboards.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch_dashboards.py index f07658635b..f351def8cb 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch_dashboards.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch_dashboards.py @@ -10,6 +10,7 @@ from typing import Any from unittest.mock import MagicMock, Mock, PropertyMock, call, mock_open, patch +from system.os import current_platform from test_workflow.dependency_installer import DependencyInstaller from test_workflow.integ_test.service_opensearch_dashboards import ServiceOpenSearchDashboards @@ -119,8 +120,9 @@ def test_start_without_security(self, mock_tarfile_open: Mock, mock_dump: Mock, [call(os.path.join(self.work_dir, "opensearch-dashboards-1.1.0", "config", "opensearch_dashboards.yml"), "a")], ) + plugin_script = "opensearch-dashboards-plugin.bat" if current_platform() == "windows" else "bash opensearch-dashboards-plugin" mock_check_call.assert_called_once_with( - "./opensearch-dashboards-plugin remove --allow-root securityDashboards", + f"{plugin_script} remove --allow-root securityDashboards", cwd=os.path.join("test_work_dir", "opensearch-dashboards-1.1.0", "bin"), shell=True )