From 74b532bc6146f2b91f2db46ba551a8d104fc6a68 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 20 Apr 2022 15:49:36 -0400 Subject: [PATCH] Add rpm support in integTest framework (2nd PR) (#2000) * Add rpm support in integTest framework (2nd PR) Signed-off-by: Peter Zhu * Add syntax checks Signed-off-by: Peter Zhu * Update tests Signed-off-by: Peter Zhu * Fix isort Signed-off-by: Peter Zhu * More typo fixes Signed-off-by: Peter Zhu * Rename vars Signed-off-by: Peter Zhu * More map removal Signed-off-by: Peter Zhu * More tweaks Signed-off-by: Peter Zhu --- src/test_workflow/integ_test/distribution.py | 54 ++++++++++++++++++ .../integ_test/distribution_rpm.py | 50 ++++++++++++++++ .../integ_test/distribution_tar.py | 37 ++++++++++++ src/test_workflow/integ_test/distributions.py | 31 ++++++++++ .../integ_test/local_test_cluster.py | 1 + ...ocal_test_cluster_opensearch_dashboards.py | 6 +- src/test_workflow/integ_test/service.py | 12 +++- .../integ_test/service_opensearch.py | 28 ++++----- .../service_opensearch_dashboards.py | 31 ++++------ .../opensearch-min-1.3.0-linux-x64.tar.gz | Bin 0 -> 223 bytes .../integ_test/test_distribution_rpm.py | 51 +++++++++++++++++ .../integ_test/test_distribution_tar.py | 45 +++++++++++++++ .../integ_test/test_distributions.py | 27 +++++++++ .../integ_test/test_local_test_cluster.py | 2 + ...ocal_test_cluster_opensearch_dashboards.py | 4 ++ .../integ_test/test_service_opensearch.py | 20 ++++++- .../test_service_opensearch_dashboards.py | 14 ++++- 17 files changed, 369 insertions(+), 44 deletions(-) create mode 100644 src/test_workflow/integ_test/distribution.py create mode 100644 src/test_workflow/integ_test/distribution_rpm.py create mode 100644 src/test_workflow/integ_test/distribution_tar.py create mode 100644 src/test_workflow/integ_test/distributions.py create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-1.3.0-linux-x64.tar.gz create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_tar.py create mode 100644 tests/tests_test_workflow/test_integ_workflow/integ_test/test_distributions.py diff --git a/src/test_workflow/integ_test/distribution.py b/src/test_workflow/integ_test/distribution.py new file mode 100644 index 0000000000..e16664537f --- /dev/null +++ b/src/test_workflow/integ_test/distribution.py @@ -0,0 +1,54 @@ +# 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. + +from abc import ABC, abstractmethod + + +class Distribution(ABC): + def __enter__(self) -> 'Distribution': + return self + + def __init__(self, filename: str, version: str, work_dir: str) -> None: + self.filename = filename + self.version = version + self.work_dir = work_dir + + @property + @abstractmethod + def install_dir(self) -> str: + """ + Return the install directory for the distribution + """ + pass + + @property + @abstractmethod + def config_dir(self, bundle_name: str) -> str: + """ + Return the config directory for the distribution + """ + pass + + @abstractmethod + def install(self) -> None: + """ + The detailed method to install the distribution before start the service + """ + pass + + @property + @abstractmethod + def start_cmd(self) -> str: + """ + Return the start command for the distribution + """ + pass + + def uninstall(self) -> None: + """ + Allow distribution that is not 'tar' to do proper cleanup + """ + pass diff --git a/src/test_workflow/integ_test/distribution_rpm.py b/src/test_workflow/integ_test/distribution_rpm.py new file mode 100644 index 0000000000..3a71ddbfce --- /dev/null +++ b/src/test_workflow/integ_test/distribution_rpm.py @@ -0,0 +1,50 @@ +# 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 test_workflow.integ_test.distribution import Distribution + + +class DistributionRpm(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(os.sep, "usr", "share", self.filename) + + @property + def config_dir(self) -> str: + return os.path.join(os.sep, "etc", self.filename) + + def install(self, bundle_name: str) -> None: + logging.info(f"Installing {bundle_name} in {self.install_dir}") + logging.info("rpm installation requires sudo, script will exit if current user does not have sudo access") + rpm_install_cmd = " ".join( + [ + 'yum', + 'remove', + '-y', + self.filename, + '&&', + 'yum', + 'install', + '-y', + bundle_name + ] + ) + subprocess.check_call(rpm_install_cmd, cwd=self.work_dir, shell=True) + + @property + def start_cmd(self) -> str: + return f"systemctl start {self.filename}" + + def uninstall(self) -> None: + logging.info("Uninstall {self.filename} package after the test") + subprocess.check_call(f"yum remove -y {self.filename}", shell=True) diff --git a/src/test_workflow/integ_test/distribution_tar.py b/src/test_workflow/integ_test/distribution_tar.py new file mode 100644 index 0000000000..b45c2dccc7 --- /dev/null +++ b/src/test_workflow/integ_test/distribution_tar.py @@ -0,0 +1,37 @@ +# 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 tarfile + +from test_workflow.integ_test.distribution import Distribution + + +class DistributionTar(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 tarfile.open(bundle_name, 'r:gz') as bundle_tar: + bundle_tar.extractall(self.work_dir) + + @property + def start_cmd(self) -> str: + start_cmd_map = { + "opensearch": "./opensearch-tar-install.sh", + "opensearch-dashboards": "./opensearch-dashboards", + } + return start_cmd_map[self.filename] diff --git a/src/test_workflow/integ_test/distributions.py b/src/test_workflow/integ_test/distributions.py new file mode 100644 index 0000000000..739e535496 --- /dev/null +++ b/src/test_workflow/integ_test/distributions.py @@ -0,0 +1,31 @@ +# 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 + +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 + + +class Distributions: + DISTRIBUTIONS_MAP = { + "tar": DistributionTar, + "rpm": DistributionRpm, + } + + @classmethod + def from_name(cls, name: str) -> Distribution: + klass = cls.DISTRIBUTIONS_MAP.get(name, None) + if not klass: + raise ValueError(f"Unsupported distribution: {name}") + return klass # type: ignore[return-value] + + @classmethod + def get_distribution(cls, filename: str, distribution: str, version: str, work_dir: str) -> Distribution: + klass = cls.from_name(distribution) + logging.info(f"{filename} distribution: {distribution}") + return klass(filename, version, work_dir) # type: ignore[no-any-return, operator] diff --git a/src/test_workflow/integ_test/local_test_cluster.py b/src/test_workflow/integ_test/local_test_cluster.py index 35b7306798..11b5d7ba6c 100644 --- a/src/test_workflow/integ_test/local_test_cluster.py +++ b/src/test_workflow/integ_test/local_test_cluster.py @@ -40,6 +40,7 @@ def __init__( self.service_opensearch = ServiceOpenSearch( self.manifest.build.version, + self.manifest.build.distribution, self.additional_cluster_config, self.security_enabled, self.dependency_installer, diff --git a/src/test_workflow/integ_test/local_test_cluster_opensearch_dashboards.py b/src/test_workflow/integ_test/local_test_cluster_opensearch_dashboards.py index 4ec5097403..23e147e912 100644 --- a/src/test_workflow/integ_test/local_test_cluster_opensearch_dashboards.py +++ b/src/test_workflow/integ_test/local_test_cluster_opensearch_dashboards.py @@ -45,15 +45,15 @@ def __init__( self.service_opensearch = ServiceOpenSearch( self.manifest_opensearch.build.version, + self.manifest_opensearch.build.distribution, {}, self.security_enabled, self.dependency_installer_opensearch, self.work_dir) - build = self.manifest_opensearch_dashboards.build - self.service_opensearch_dashboards = ServiceOpenSearchDashboards( - build.version, + self.manifest_opensearch_dashboards.build.version, + self.manifest_opensearch_dashboards.build.distribution, self.additional_cluster_config, self.security_enabled, self.dependency_installer_opensearch_dashboards, diff --git a/src/test_workflow/integ_test/service.py b/src/test_workflow/integ_test/service.py index 41a2708034..67587e0c24 100644 --- a/src/test_workflow/integ_test/service.py +++ b/src/test_workflow/integ_test/service.py @@ -6,6 +6,7 @@ import abc import logging +import os import time import requests @@ -19,9 +20,10 @@ class Service(abc.ABC): Abstract base class for all types of test clusters. """ - def __init__(self, work_dir, version, security_enabled, additional_config, dependency_installer): + def __init__(self, work_dir, version, distribution, security_enabled, additional_config, dependency_installer): self.work_dir = work_dir self.version = version + self.distribution = distribution self.security_enabled = security_enabled self.additional_config = additional_config self.dependency_installer = dependency_installer @@ -43,6 +45,8 @@ def terminate(self): self.return_code = self.process_handler.terminate() + self.uninstall() + return ServiceTerminationResult(self.return_code, self.process_handler.stdout_data, self.process_handler.stderr_data, self.log_files) def endpoint(self): @@ -80,6 +84,12 @@ def service_alive(self): else: return False + def download(self): + logging.info("Downloading bundle artifact") + bundle_name = self.dependency_installer.download_dist(self.work_dir) + logging.info(f"Downloaded bundle to {os.path.realpath(bundle_name)}") + return bundle_name + def wait_for_service(self): logging.info("Waiting for service to become available") diff --git a/src/test_workflow/integ_test/service_opensearch.py b/src/test_workflow/integ_test/service_opensearch.py index 4f3ec7386c..a8a98ff38b 100644 --- a/src/test_workflow/integ_test/service_opensearch.py +++ b/src/test_workflow/integ_test/service_opensearch.py @@ -6,11 +6,11 @@ import logging import os -import tarfile import requests import yaml +from test_workflow.integ_test.distributions import Distributions from test_workflow.integ_test.service import Service @@ -18,21 +18,22 @@ class ServiceOpenSearch(Service): def __init__( self, version, + distribution, additional_config, security_enabled, dependency_installer, work_dir ): - super().__init__(work_dir, version, security_enabled, additional_config, dependency_installer) + super().__init__(work_dir, version, distribution, security_enabled, additional_config, dependency_installer) + self.dist = Distributions.get_distribution("opensearch", distribution, version, work_dir) self.dependency_installer = dependency_installer - - self.install_dir = os.path.join(self.work_dir, f"opensearch-{self.version}") + self.install_dir = self.dist.install_dir def start(self): - self.__download() + self.dist.install(self.download()) - self.opensearch_yml_dir = os.path.join(self.install_dir, "config", "opensearch.yml") + self.opensearch_yml_dir = os.path.join(self.dist.config_dir, "opensearch.yml") self.security_plugin_dir = os.path.join(self.install_dir, "plugins", "opensearch-security") if not self.security_enabled and os.path.isdir(self.security_plugin_dir): @@ -41,20 +42,11 @@ def start(self): if self.additional_config: self.__add_plugin_specific_config(self.additional_config) - self.process_handler.start("./opensearch-tar-install.sh", self.install_dir) + self.process_handler.start(self.dist.start_cmd, self.install_dir) logging.info(f"Started OpenSearch with parent PID {self.process_handler.pid}") - def __download(self): - logging.info(f"Creating local test cluster in {self.work_dir}") - logging.info("Downloading bundle") - bundle_name = self.dependency_installer.download_dist(self.work_dir) - logging.info(f"Downloaded bundle to {os.path.realpath(bundle_name)}") - - logging.info(f"Unpacking {bundle_name}") - with tarfile.open(bundle_name, 'r') as bundle_tar: - bundle_tar.extractall(self.work_dir) - - logging.info(f"Unpacked {bundle_name}") + def uninstall(self): + self.dist.uninstall() def url(self, path=""): return f'{"https" if self.security_enabled else "http"}://{self.endpoint()}:{self.port()}{path}' diff --git a/src/test_workflow/integ_test/service_opensearch_dashboards.py b/src/test_workflow/integ_test/service_opensearch_dashboards.py index 7e9744ff55..8304cd71e7 100644 --- a/src/test_workflow/integ_test/service_opensearch_dashboards.py +++ b/src/test_workflow/integ_test/service_opensearch_dashboards.py @@ -7,11 +7,11 @@ import logging import os import subprocess -import tarfile import requests import yaml +from test_workflow.integ_test.distributions import Distributions from test_workflow.integ_test.service import Service @@ -19,19 +19,20 @@ class ServiceOpenSearchDashboards(Service): def __init__( self, version, + distribution, additional_config, security_enabled, dependency_installer, work_dir ): - super().__init__(work_dir, version, security_enabled, additional_config, dependency_installer) - self.install_dir = os.path.join(self.work_dir, f"opensearch-dashboards-{self.version}") + super().__init__(work_dir, version, distribution, security_enabled, additional_config, dependency_installer) + self.dist = Distributions.get_distribution("opensearch-dashboards", distribution, version, work_dir) + self.install_dir = self.dist.install_dir def start(self): - logging.info(f"Starting OpenSearch Dashboards service from {self.work_dir}") - self.__download() + self.dist.install(self.download()) - self.opensearch_dashboards_yml_dir = os.path.join(self.install_dir, "config", "opensearch_dashboards.yml") + self.opensearch_dashboards_yml_dir = os.path.join(self.dist.config_dir, "opensearch_dashboards.yml") self.executable_dir = os.path.join(self.install_dir, "bin") if not self.security_enabled: @@ -42,9 +43,12 @@ def start(self): if self.additional_config: self.__add_plugin_specific_config(self.additional_config) - self.process_handler.start("./opensearch-dashboards", self.executable_dir) + self.process_handler.start(self.dist.start_cmd, self.executable_dir) logging.info(f"Started OpenSearch Dashboards with parent PID {self.process_handler.pid}") + def uninstall(self): + self.dist.uninstall() + def __set_logging_dest(self): self.log_dir = os.path.join(self.install_dir, "logs") os.makedirs(self.log_dir, exist_ok=True) @@ -53,22 +57,11 @@ def __set_logging_dest(self): def __remove_security(self): 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 securityDashboards", cwd=self.executable_dir, shell=True) + subprocess.check_call("./opensearch-dashboards-plugin remove --allow-root securityDashboards", cwd=self.executable_dir, shell=True) with open(self.opensearch_dashboards_yml_dir, "w") as yamlfile: yamlfile.close() - def __download(self): - logging.info("Downloading OpenSearch Dashboards bundle") - bundle_name = self.dependency_installer.download_dist(self.work_dir) - logging.info(f"Downloaded bundle to {os.path.realpath(bundle_name)}") - - logging.info(f"Unpacking {bundle_name}") - with tarfile.open(bundle_name, 'r') as bundle_tar: - bundle_tar.extractall(self.work_dir) - - logging.info(f"Unpacked {bundle_name}") - def url(self, path=""): return f'http://{self.endpoint()}:{self.port()}{path}' diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-1.3.0-linux-x64.tar.gz b/tests/tests_test_workflow/test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-1.3.0-linux-x64.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..afc2a9438a123ab9610531ca431c9f04eb440020 GIT binary patch literal 223 zcmV<503iP#iwFR&0uy2Y1MSg4Zo)7Sg<-Ebg)cywA#rk%UceMX+@=m9Mxv}xFV?H! zAP`bZ)lEtl{lArG#?p-Ry0r_vvzw=8Dp`@`4{CgQQX8WVL-Fyx7-}iYQ~yj!DKe9) zu4JatFgK#K`Gs4)*!IzGv{w6O`|Rz`fA`P6+I<)9anW6MpYy*qvbc+*>=**BQr?H5 zxRrl;U-CCnr2MP8sFlt~+5Urnp8sRxd%d None: + + self.work_dir = os.path.join(os.path.dirname(__file__), "data") + self.distribution_rpm = DistributionRpm("opensearch", "1.3.0", self.work_dir) + self.distribution_rpm_dashboards = DistributionRpm("opensearch-dashboards", "1.3.0", self.work_dir) + + def test_distribution_rpm_vars(self) -> None: + self.assertEqual(self.distribution_rpm.filename, 'opensearch') + self.assertEqual(self.distribution_rpm.version, '1.3.0') + self.assertEqual(self.distribution_rpm.work_dir, self.work_dir) + + def test_install_dir(self) -> None: + self.assertEqual(self.distribution_rpm.install_dir, os.path.join(os.sep, "usr", "share", "opensearch")) + + def test_config_dir(self) -> None: + self.assertEqual(self.distribution_rpm.config_dir, os.path.join(os.sep, "etc", "opensearch")) + + @patch("subprocess.check_call") + def test_install(self, check_call_mock: Mock) -> None: + self.distribution_rpm.install("opensearch.rpm") + args_list = check_call_mock.call_args_list + + self.assertEqual(check_call_mock.call_count, 1) + self.assertEqual("yum remove -y opensearch && yum install -y opensearch.rpm", args_list[0][0][0]) + + def test_start_cmd(self) -> None: + self.assertEqual(self.distribution_rpm.start_cmd, "systemctl start opensearch") + self.assertEqual(self.distribution_rpm_dashboards.start_cmd, "systemctl start opensearch-dashboards") + + @patch("subprocess.check_call") + def test_uninstall(self, check_call_mock: Mock) -> None: + self.distribution_rpm.uninstall() + args_list = check_call_mock.call_args_list + + self.assertEqual(check_call_mock.call_count, 1) + self.assertEqual("yum remove -y opensearch", args_list[0][0][0]) diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_tar.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_tar.py new file mode 100644 index 0000000000..0805c9edc9 --- /dev/null +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_tar.py @@ -0,0 +1,45 @@ +# 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, patch + +from test_workflow.integ_test.distribution_tar import DistributionTar + + +class TestDistributionTar(unittest.TestCase): + + def setUp(self) -> None: + + self.work_dir = os.path.join(os.path.dirname(__file__), "data") + self.distribution_tar = DistributionTar("opensearch", "1.3.0", self.work_dir) + self.distribution_tar_dashboards = DistributionTar("opensearch-dashboards", "1.3.0", self.work_dir) + + def test_distribution_tar_vars(self) -> None: + self.assertEqual(self.distribution_tar.filename, 'opensearch') + self.assertEqual(self.distribution_tar.version, '1.3.0') + self.assertEqual(self.distribution_tar.work_dir, self.work_dir) + + def test_install_dir(self) -> None: + self.assertEqual(self.distribution_tar.install_dir, os.path.join(self.work_dir, "opensearch-1.3.0")) + + def test_config_dir(self) -> None: + self.assertEqual(self.distribution_tar.config_dir, os.path.join(self.work_dir, "opensearch-1.3.0", "config")) + + def test_install(self) -> None: + with patch("tarfile.open") as mock_tarfile_open: + mock_tarfile_extractall = MagicMock() + mock_tarfile_open.return_value.__enter__.return_value.extractall = mock_tarfile_extractall + + self.distribution_tar.install(os.path.join(self.work_dir, "artifacts", "dist", "opensearch-min-1.3.0-linux-x64.tar.gz")) + + mock_tarfile_open.assert_called_with(os.path.join(self.work_dir, "artifacts", "dist", "opensearch-min-1.3.0-linux-x64.tar.gz"), "r:gz") + mock_tarfile_extractall.assert_called_with(self.work_dir) + + def test_start_cmd(self) -> None: + self.assertEqual(self.distribution_tar.start_cmd, "./opensearch-tar-install.sh") + self.assertEqual(self.distribution_tar_dashboards.start_cmd, "./opensearch-dashboards") diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distributions.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distributions.py new file mode 100644 index 0000000000..3bebb7fce7 --- /dev/null +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distributions.py @@ -0,0 +1,27 @@ +# 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 test_workflow.integ_test.distributions import Distributions + + +class TestDistributions(unittest.TestCase): + + def setUp(self) -> None: + + self.distributions = Distributions + + def test_distribution_map(self) -> None: + self.assertEqual(self.distributions.DISTRIBUTIONS_MAP['tar'].__name__, 'DistributionTar') + self.assertEqual(self.distributions.DISTRIBUTIONS_MAP['rpm'].__name__, 'DistributionRpm') + + def test_create_dist(self) -> None: + return_cls_tar = self.distributions.get_distribution("opensearch", "tar", "1.3.0", os.path.join(os.path.dirname(__file__), "data")) + self.assertEqual(return_cls_tar.__class__.__name__, 'DistributionTar') + return_cls_rpm = self.distributions.get_distribution("opensearch", "rpm", "1.3.0", os.path.join(os.path.dirname(__file__), "data")) + self.assertEqual(return_cls_rpm.__class__.__name__, 'DistributionRpm') diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster.py index 339107e92a..392c453e39 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster.py @@ -18,6 +18,7 @@ class LocalTestClusterTests(unittest.TestCase): def setUp(self): mock_manifest = MagicMock() mock_manifest.build.version = "1.1.0" + mock_manifest.build.distribution = "tar" self.manifest = mock_manifest self.work_dir = "test_work_dir" @@ -54,6 +55,7 @@ def test_start(self, mock_service): mock_service.assert_called_once_with( "1.1.0", + "tar", self.additional_cluster_config, self.security_enabled, self.dependency_installer, diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster_opensearch_dashboards.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster_opensearch_dashboards.py index 335ca34f70..39f2447e39 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster_opensearch_dashboards.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_local_test_cluster_opensearch_dashboards.py @@ -18,10 +18,12 @@ class LocalTestClusterOpenSearchDashboardsTests(unittest.TestCase): def setUp(self): mock_bundle_manifest_opensearch = MagicMock() mock_bundle_manifest_opensearch.build.version = "1.1.0" + mock_bundle_manifest_opensearch.build.distribution = "tar" self.mock_bundle_manifest_opensearch = mock_bundle_manifest_opensearch mock_bundle_manifest_opensearch_dashboards = MagicMock() mock_bundle_manifest_opensearch_dashboards.build.version = "1.1.0" + mock_bundle_manifest_opensearch_dashboards.build.distribution = "tar" self.mock_bundle_manifest_opensearch_dashboards = mock_bundle_manifest_opensearch_dashboards dependency_installer_opensearch = MagicMock() @@ -70,6 +72,7 @@ def test_start(self, mock_service_opensearch_dashboards, mock_service_opensearch mock_service_opensearch.assert_called_once_with( "1.1.0", + "tar", {}, self.security_enabled, self.dependency_installer_opensearch, @@ -81,6 +84,7 @@ def test_start(self, mock_service_opensearch_dashboards, mock_service_opensearch mock_service_opensearch_dashboards.assert_called_once_with( "1.1.0", + "tar", self.additional_cluster_config, self.security_enabled, self.dependency_installer_opensearch_dashboards, diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch.py index f6dfa07973..3900558c35 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_service_opensearch.py @@ -17,6 +17,7 @@ class ServiceOpenSearchTests(unittest.TestCase): def setUp(self): self.version = "1.1.0" + self.distribution = "tar" self.work_dir = "test_work_dir" self.additional_config = {"script.context.field.max_compilations_rate": "1000/1m"} self.dependency_installer = "" @@ -33,6 +34,7 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, dependency_installer, @@ -59,7 +61,7 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro mock_file.return_value.write.assert_called_once_with(mock_dump_result) dependency_installer.download_dist.assert_called_once_with(self.work_dir) - mock_tarfile_open.assert_called_once_with(bundle_full_name, "r") + mock_tarfile_open.assert_called_once_with(bundle_full_name, "r:gz") mock_bundle_tar.extractall.assert_called_once_with(self.work_dir) self.assertEqual(mock_pid.call_count, 1) @@ -76,6 +78,7 @@ def test_start_security_disabled(self, mock_tarfile_open, mock_dump, mock_file, service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, False, dependency_installer, @@ -125,6 +128,7 @@ def test_start_security_disabled_and_not_installed(self, mock_tarfile_open, mock service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, False, dependency_installer, @@ -174,6 +178,7 @@ def test_terminate( ): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -194,6 +199,7 @@ def test_terminate( def test_terminate_process_not_started(self, mock_process_started, mock_process_terminate): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -208,6 +214,7 @@ def test_terminate_process_not_started(self, mock_process_started, mock_process_ def test_endpoint_port(self): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -220,6 +227,7 @@ def test_endpoint_port(self): def test_url_security_enabled(self): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -231,6 +239,7 @@ def test_url_security_enabled(self): def test_url_security_disabled(self): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, False, self.dependency_installer, @@ -244,6 +253,7 @@ def test_url_security_disabled(self): def test_get_service_response(self, mock_url, mock_requests_get): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -267,6 +277,7 @@ def test_get_service_response(self, mock_url, mock_requests_get): def test_wait_for_service_succeed_on_first_attemp(self, mock_process_stderr_data, mock_process_stdout_data, mock_service_alive, mock_time_sleep): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -293,6 +304,7 @@ def test_wait_for_service_always_fail_without_exception( ): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -323,6 +335,7 @@ def test_wait_for_service_always_fail_with_exception( service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -355,6 +368,7 @@ def test_wait_for_service_suceed_on_third_attempt( ): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -372,6 +386,7 @@ def test_wait_for_service_suceed_on_third_attempt( def test_service_alive_green_available(self, mock_get_service_response): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -391,6 +406,7 @@ def test_service_alive_green_available(self, mock_get_service_response): def test_service_alive_yellow_available(self, mock_get_service_response): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -410,6 +426,7 @@ def test_service_alive_yellow_available(self, mock_get_service_response): def test_service_alive_red_unavailable(self, mock_get_service_response): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -429,6 +446,7 @@ def test_service_alive_red_unavailable(self, mock_get_service_response): def test_service_alive_unavailable(self, mock_get_service_response): service = ServiceOpenSearch( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, 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 6a48cb6632..e8ce017ff1 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 @@ -15,6 +15,7 @@ class ServiceOpenSearchDashboardsTests(unittest.TestCase): def setUp(self): self.version = "1.1.0" + self.distribution = "tar" self.work_dir = "test_work_dir" self.additional_config = {"script.context.field.max_compilations_rate": "1000/1m"} self.dependency_installer = "" @@ -30,6 +31,7 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, mock_dependency_installer, @@ -49,7 +51,7 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro service.start() mock_dependency_installer.download_dist.called_once_with(self.work_dir) - mock_tarfile_open.assert_called_once_with(bundle_full_name, "r") + mock_tarfile_open.assert_called_once_with(bundle_full_name, "r:gz") mock_bundle_tar.extractall.assert_called_once_with(self.work_dir) mock_file.assert_called_once_with(os.path.join(self.work_dir, "opensearch-dashboards-1.1.0", "config", "opensearch_dashboards.yml"), "a") @@ -77,6 +79,7 @@ def test_start_without_security(self, mock_tarfile_open, mock_dump, mock_file, m service = ServiceOpenSearchDashboards( self.version, + self.distribution, {}, False, mock_dependency_installer, @@ -109,7 +112,7 @@ def test_start_without_security(self, mock_tarfile_open, mock_dump, mock_file, m ) mock_check_call.assert_called_once_with( - "./opensearch-dashboards-plugin remove securityDashboards", + "./opensearch-dashboards-plugin remove --allow-root securityDashboards", cwd=os.path.join("test_work_dir", "opensearch-dashboards-1.1.0", "bin"), shell=True ) @@ -133,6 +136,7 @@ def test_start_without_security_and_not_installed(self, mock_tarfile_open, mock_ service = ServiceOpenSearchDashboards( self.version, + self.distribution, {}, False, mock_dependency_installer, @@ -175,6 +179,7 @@ def test_start_without_security_and_not_installed(self, mock_tarfile_open, mock_ def test_endpoint_port_url(self): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -190,6 +195,7 @@ def test_endpoint_port_url(self): def test_get_service_response_with_security(self, mock_url, mock_requests_get): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -209,6 +215,7 @@ def test_get_service_response_with_security(self, mock_url, mock_requests_get): def test_get_service_response_without_security(self, mock_url, mock_requests_get): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, False, self.dependency_installer, @@ -227,6 +234,7 @@ def test_get_service_response_without_security(self, mock_url, mock_requests_get def test_service_alive_green_available(self, mock_get_service_response): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -246,6 +254,7 @@ def test_service_alive_green_available(self, mock_get_service_response): def test_service_alive_yellow_available(self, mock_get_service_response): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -265,6 +274,7 @@ def test_service_alive_yellow_available(self, mock_get_service_response): def test_service_alive_red_unavailable(self, mock_get_service_response): service = ServiceOpenSearchDashboards( self.version, + self.distribution, self.additional_config, True, self.dependency_installer,