From de354e320ef4562de15859d8f47c227ab70aa107 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 19 Apr 2022 03:12:43 +0000 Subject: [PATCH 1/4] Add rpm support for integTest framework Signed-off-by: Peter Zhu --- src/system/process.py | 12 ++++- src/test_workflow/README.md | 2 + .../integ_test/local_test_cluster.py | 2 + ...ocal_test_cluster_opensearch_dashboards.py | 8 ++-- src/test_workflow/integ_test/service.py | 21 ++++++++- .../integ_test/service_opensearch.py | 44 ++++++++++++++---- .../service_opensearch_dashboards.py | 46 +++++++++++++++---- tests/tests_system/test_process.py | 31 +++++++++++-- .../integ_test/test_local_test_cluster.py | 4 ++ ...ocal_test_cluster_opensearch_dashboards.py | 8 ++++ .../integ_test/test_service_opensearch.py | 36 +++++++++++++++ .../test_service_opensearch_dashboards.py | 22 ++++++++- 12 files changed, 205 insertions(+), 31 deletions(-) diff --git a/src/system/process.py b/src/system/process.py index 49ba7d0975..286b7d8d56 100644 --- a/src/system/process.py +++ b/src/system/process.py @@ -12,12 +12,14 @@ class Process: - def __init__(self) -> None: + def __init__(self, filename: str, distribution: str) -> None: self.process: subprocess.Popen[bytes] = None self.stdout: Any = None self.stderr: Any = None self.__stdout_data__: str = None self.__stderr_data__: str = None + self.filename = filename + self.distribution = distribution def start(self, command: str, cwd: str) -> None: if self.started: @@ -38,7 +40,7 @@ def terminate(self) -> int: if not self.started: raise ProcessNotStartedError() - parent = psutil.Process(self.process.pid) + parent = psutil.Process(self.pid) logging.debug("Checking for child processes") child_processes = parent.children(recursive=True) for child in child_processes: @@ -65,6 +67,10 @@ def terminate(self) -> int: self.return_code = self.process.returncode self.process = None + if self.distribution == "rpm": + logging.info("Clean up process related files for packages") + subprocess.check_call(f"yum remove -y '{self.filename}*'", shell=True) + return self.return_code @property @@ -73,6 +79,8 @@ def started(self) -> bool: @property def pid(self) -> int: + if self.distribution == "rpm": + return int(subprocess.check_output(f"sleep 1 && systemctl show --property MainPID {self.filename}", encoding='UTF-8', shell=True).split("=")[1]) if self.started else None return self.process.pid if self.started else None @property diff --git a/src/test_workflow/README.md b/src/test_workflow/README.md index 340af02799..9617af1d53 100644 --- a/src/test_workflow/README.md +++ b/src/test_workflow/README.md @@ -69,6 +69,8 @@ To run OpenSearch Dashboards integration tests. opensearch-dashboards=https://ci.opensearch.org/ci/dbc/bundle-build-dashboards/1.2.0/869/linux/x64 ``` +:warning: RPM Test requires user running the `./test.sh` command with root user or sudo permission, as rpm requires root to install and start the service. + ### Backwards Compatibility Tests Runs backward compatibility invoking `run_bwc_test.py` in each component from a distribution manifest. diff --git a/src/test_workflow/integ_test/local_test_cluster.py b/src/test_workflow/integ_test/local_test_cluster.py index 35b7306798..8ef08db331 100644 --- a/src/test_workflow/integ_test/local_test_cluster.py +++ b/src/test_workflow/integ_test/local_test_cluster.py @@ -39,7 +39,9 @@ def __init__( self.dependency_installer = dependency_installer self.service_opensearch = ServiceOpenSearch( + self.manifest.build.filename, self.manifest.build.version, + self.manifest.build.distribution if self.manifest.build.distribution else 'tar', 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..6e15566799 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 @@ -44,16 +44,18 @@ def __init__( self.dependency_installer_opensearch_dashboards = dependency_installer_opensearch_dashboards self.service_opensearch = ServiceOpenSearch( + self.manifest_opensearch.build.filename, 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.filename, + 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..ba7678f2e9 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,14 +20,30 @@ 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, filename, version, distribution, security_enabled, additional_config, dependency_installer): + self.filename = filename 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 - self.process_handler = Process() + self.process_handler = Process(self.filename, self.distribution) + self.install_dir_map = { + "tar": os.path.join(self.work_dir, f"{self.filename}-{self.version}"), + "rpm": os.path.join(os.sep, "usr", "share", self.filename) + } + self.config_file_map = { + "tar": os.path.join(self.install_dir_map[self.distribution], "config", f"{self.filename.replace('-', '_')}.yml"), + "rpm": os.path.join(os.sep, "etc", self.filename, f"{self.filename.replace('-', '_')}.yml") + } + self.start_cmd_map = { + "tar-opensearch": "./opensearch-tar-install.sh", + "tar-opensearch-dashboards": "./opensearch-dashboards", + "rpm-opensearch": "systemctl start opensearch", + "rpm-opensearch-dashboards": "systemctl start opensearch-dashboards" + } self.install_dir = "" @abc.abstractmethod diff --git a/src/test_workflow/integ_test/service_opensearch.py b/src/test_workflow/integ_test/service_opensearch.py index 4f3ec7386c..710156c41b 100644 --- a/src/test_workflow/integ_test/service_opensearch.py +++ b/src/test_workflow/integ_test/service_opensearch.py @@ -6,6 +6,7 @@ import logging import os +import subprocess import tarfile import requests @@ -17,22 +18,27 @@ class ServiceOpenSearch(Service): def __init__( self, + filename, 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, filename, version, distribution, security_enabled, additional_config, dependency_installer) self.dependency_installer = dependency_installer + self.filename = filename + self.distribution = distribution - self.install_dir = os.path.join(self.work_dir, f"opensearch-{self.version}") + logging.info(f'{self.filename} distribution: {self.distribution}') + self.install_dir = self.install_dir_map[self.distribution] def start(self): self.__download() - self.opensearch_yml_dir = os.path.join(self.install_dir, "config", "opensearch.yml") + self.opensearch_yml_dir = self.config_file_map[self.distribution] 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,7 +47,7 @@ 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.start_cmd_map[f"{self.distribution}-{self.filename}"], self.install_dir) logging.info(f"Started OpenSearch with parent PID {self.process_handler.pid}") def __download(self): @@ -50,11 +56,31 @@ def __download(self): 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}") + logging.info(f"Installing {bundle_name} in {self.install_dir}") + + if self.distribution == "tar": + with tarfile.open(bundle_name, 'r') as bundle_tar: + bundle_tar.extractall(self.work_dir) + elif self.distribution == "rpm": + 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) + else: + raise(f'{self.distribution} is not supported in integ-test yet') + + logging.info(f"Installed {bundle_name}") 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..cbcb14bd69 100644 --- a/src/test_workflow/integ_test/service_opensearch_dashboards.py +++ b/src/test_workflow/integ_test/service_opensearch_dashboards.py @@ -18,20 +18,26 @@ class ServiceOpenSearchDashboards(Service): def __init__( self, + filename, 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, filename, version, distribution, security_enabled, additional_config, dependency_installer) + self.filename = filename + self.distribution = distribution + + logging.info(f'{self.filename} distribution: {self.distribution}') + self.install_dir = self.install_dir_map[self.distribution] def start(self): logging.info(f"Starting OpenSearch Dashboards service from {self.work_dir}") self.__download() - self.opensearch_dashboards_yml_dir = os.path.join(self.install_dir, "config", "opensearch_dashboards.yml") + self.opensearch_dashboards_yml_dir = self.config_file_map[self.distribution] self.executable_dir = os.path.join(self.install_dir, "bin") if not self.security_enabled: @@ -42,7 +48,7 @@ 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.start_cmd_map[f"{self.distribution}-{self.filename}"], self.executable_dir) logging.info(f"Started OpenSearch Dashboards with parent PID {self.process_handler.pid}") def __set_logging_dest(self): @@ -53,7 +59,7 @@ 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() @@ -63,11 +69,31 @@ def __download(self): 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}") + logging.info(f"Installing {bundle_name} in {self.install_dir}") + + if self.distribution == "tar": + with tarfile.open(bundle_name, 'r') as bundle_tar: + bundle_tar.extractall(self.work_dir) + elif self.distribution == "rpm": + 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) + else: + raise(f'{self.distribution} is not supported in integ-test yet') + + logging.info(f"Installed {bundle_name}") def url(self, path=""): return f'http://{self.endpoint()}:{self.port()}{path}' diff --git a/tests/tests_system/test_process.py b/tests/tests_system/test_process.py index ab9b32a12f..90d5c5a330 100644 --- a/tests/tests_system/test_process.py +++ b/tests/tests_system/test_process.py @@ -14,7 +14,7 @@ class TestProcess(unittest.TestCase): def test(self) -> None: - process_handler = Process() + process_handler = Process("opensearch", "tar") process_handler.start("./tests/tests_system/data/wait_for_input.sh", ".") @@ -32,14 +32,37 @@ def test(self) -> None: self.assertFalse(process_handler.started) self.assertIsNone(process_handler.pid) + @patch('psutil.Process') + @patch('subprocess.check_output', return_value="MainPID=123") + def test_repm_pid(self, mock_subprocess_check_call: MagicMock, mock_psutil_process: MagicMock) -> None: + + process_handler = Process("opensearch", "rpm") + + process_handler.start("./tests/tests_system/data/wait_for_input.sh", ".") + print(process_handler.pid) + + self.assertTrue(process_handler.started) + self.assertIsNotNone(process_handler.pid) + self.assertIsNotNone(process_handler.stdout_data) + self.assertIsNotNone(process_handler.stderr_data) + + return_code = process_handler.terminate() + + self.assertIsNone(return_code) + self.assertIsNotNone(process_handler.stdout_data) + self.assertIsNotNone(process_handler.stderr_data) + + self.assertFalse(process_handler.started) + self.assertIsNone(process_handler.pid) + @patch.object(tempfile, 'NamedTemporaryFile') def test_file_open_mode(self, mock_tempfile: MagicMock) -> None: - process_handler = Process() + process_handler = Process("opensearch", "tar") process_handler.start("./tests/tests_system/data/wait_for_input.sh", ".") mock_tempfile.assert_has_calls([call(mode="r+"), call(mode="r+")]) def test_start_twice(self) -> None: - process_handler = Process() + process_handler = Process("opensearch", "tar") process_handler.start("ls", ".") with self.assertRaises(ProcessStartedError) as ctx: @@ -48,7 +71,7 @@ def test_start_twice(self) -> None: self.assertTrue(str(ctx.exception).startswith("Process already started, pid: ")) def test_terminate_unstarted_process(self) -> None: - process_handler = Process() + process_handler = Process("opensearch", "tar") with self.assertRaises(ProcessNotStartedError) as ctx: process_handler.terminate() 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..18767f278e 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 @@ -17,7 +17,9 @@ class LocalTestClusterTests(unittest.TestCase): def setUp(self): mock_manifest = MagicMock() + mock_manifest.build.filename = "opensearch" mock_manifest.build.version = "1.1.0" + mock_manifest.build.distribution = "tar" self.manifest = mock_manifest self.work_dir = "test_work_dir" @@ -53,7 +55,9 @@ def test_start(self, mock_service): cluster.start() mock_service.assert_called_once_with( + "opensearch", "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..7a558429cc 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 @@ -17,11 +17,15 @@ class LocalTestClusterOpenSearchDashboardsTests(unittest.TestCase): def setUp(self): mock_bundle_manifest_opensearch = MagicMock() + mock_bundle_manifest_opensearch.build.filename = "opensearch" 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.filename = "opensearch-dashboards" 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() @@ -69,7 +73,9 @@ def test_start(self, mock_service_opensearch_dashboards, mock_service_opensearch cluster.start() mock_service_opensearch.assert_called_once_with( + "opensearch", "1.1.0", + "tar", {}, self.security_enabled, self.dependency_installer_opensearch, @@ -80,7 +86,9 @@ def test_start(self, mock_service_opensearch_dashboards, mock_service_opensearch mock_service_opensearch_object.wait_for_service.assert_called_once() mock_service_opensearch_dashboards.assert_called_once_with( + "opensearch-dashboards", "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..75bba91fe0 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 @@ -16,7 +16,9 @@ class ServiceOpenSearchTests(unittest.TestCase): def setUp(self): + self.filename = "opensearch" 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 = "" @@ -32,7 +34,9 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro dependency_installer = MagicMock() service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, dependency_installer, @@ -75,7 +79,9 @@ def test_start_security_disabled(self, mock_tarfile_open, mock_dump, mock_file, dependency_installer = MagicMock() service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, False, dependency_installer, @@ -124,7 +130,9 @@ def test_start_security_disabled_and_not_installed(self, mock_tarfile_open, mock dependency_installer = MagicMock() service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, False, dependency_installer, @@ -173,7 +181,9 @@ def test_terminate( mock_process_terminate ): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -193,7 +203,9 @@ def test_terminate( @patch('test_workflow.integ_test.service.Process.started', new_callable=PropertyMock, return_value=False) def test_terminate_process_not_started(self, mock_process_started, mock_process_terminate): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -207,7 +219,9 @@ def test_terminate_process_not_started(self, mock_process_started, mock_process_ def test_endpoint_port(self): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -219,7 +233,9 @@ def test_endpoint_port(self): def test_url_security_enabled(self): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -230,7 +246,9 @@ def test_url_security_enabled(self): def test_url_security_disabled(self): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, False, self.dependency_installer, @@ -243,7 +261,9 @@ def test_url_security_disabled(self): @patch.object(ServiceOpenSearch, "url") def test_get_service_response(self, mock_url, mock_requests_get): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -266,7 +286,9 @@ def test_get_service_response(self, mock_url, mock_requests_get): @patch('test_workflow.integ_test.service.Process.stderr_data', new_callable=PropertyMock, return_value="test stderr_data") 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.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -292,7 +314,9 @@ def test_wait_for_service_always_fail_without_exception( mock_time_sleep ): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -322,7 +346,9 @@ def test_wait_for_service_always_fail_with_exception( ): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -354,7 +380,9 @@ def test_wait_for_service_suceed_on_third_attempt( mock_time_sleep ): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -371,7 +399,9 @@ def test_wait_for_service_suceed_on_third_attempt( @patch.object(ServiceOpenSearch, "get_service_response") def test_service_alive_green_available(self, mock_get_service_response): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -390,7 +420,9 @@ def test_service_alive_green_available(self, mock_get_service_response): @patch.object(ServiceOpenSearch, "get_service_response") def test_service_alive_yellow_available(self, mock_get_service_response): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -409,7 +441,9 @@ def test_service_alive_yellow_available(self, mock_get_service_response): @patch.object(ServiceOpenSearch, "get_service_response") def test_service_alive_red_unavailable(self, mock_get_service_response): service = ServiceOpenSearch( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -428,7 +462,9 @@ def test_service_alive_red_unavailable(self, mock_get_service_response): @patch.object(ServiceOpenSearch, "get_service_response") def test_service_alive_unavailable(self, mock_get_service_response): service = ServiceOpenSearch( + self.filename, 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..02a6dcdfa2 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 @@ -14,7 +14,9 @@ class ServiceOpenSearchDashboardsTests(unittest.TestCase): def setUp(self): + self.filename = "opensearch-dashboards" 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 = "" @@ -29,7 +31,9 @@ def test_start(self, mock_tarfile_open, mock_dump, mock_file, mock_pid, mock_pro mock_dependency_installer = MagicMock() service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, mock_dependency_installer, @@ -76,7 +80,9 @@ def test_start_without_security(self, mock_tarfile_open, mock_dump, mock_file, m mock_dependency_installer = MagicMock() service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, {}, False, mock_dependency_installer, @@ -109,7 +115,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 ) @@ -132,7 +138,9 @@ def test_start_without_security_and_not_installed(self, mock_tarfile_open, mock_ mock_dependency_installer = MagicMock() service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, {}, False, mock_dependency_installer, @@ -174,7 +182,9 @@ def test_start_without_security_and_not_installed(self, mock_tarfile_open, mock_ def test_endpoint_port_url(self): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -189,7 +199,9 @@ def test_endpoint_port_url(self): @patch.object(ServiceOpenSearchDashboards, "url") def test_get_service_response_with_security(self, mock_url, mock_requests_get): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -208,7 +220,9 @@ def test_get_service_response_with_security(self, mock_url, mock_requests_get): @patch.object(ServiceOpenSearchDashboards, "url") def test_get_service_response_without_security(self, mock_url, mock_requests_get): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, False, self.dependency_installer, @@ -226,7 +240,9 @@ def test_get_service_response_without_security(self, mock_url, mock_requests_get @patch.object(ServiceOpenSearchDashboards, "get_service_response") def test_service_alive_green_available(self, mock_get_service_response): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -245,7 +261,9 @@ def test_service_alive_green_available(self, mock_get_service_response): @patch.object(ServiceOpenSearchDashboards, "get_service_response") def test_service_alive_yellow_available(self, mock_get_service_response): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, @@ -264,7 +282,9 @@ def test_service_alive_yellow_available(self, mock_get_service_response): @patch.object(ServiceOpenSearchDashboards, "get_service_response") def test_service_alive_red_unavailable(self, mock_get_service_response): service = ServiceOpenSearchDashboards( + self.filename, self.version, + self.distribution, self.additional_config, True, self.dependency_installer, From 2df5c08d364468bd959373b89e6a03ed887363e2 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 19 Apr 2022 03:22:33 +0000 Subject: [PATCH 2/4] Update readme Signed-off-by: Peter Zhu --- src/test_workflow/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_workflow/README.md b/src/test_workflow/README.md index 9617af1d53..8223d1da9b 100644 --- a/src/test_workflow/README.md +++ b/src/test_workflow/README.md @@ -69,7 +69,7 @@ To run OpenSearch Dashboards integration tests. opensearch-dashboards=https://ci.opensearch.org/ci/dbc/bundle-build-dashboards/1.2.0/869/linux/x64 ``` -:warning: RPM Test requires user running the `./test.sh` command with root user or sudo permission, as rpm requires root to install and start the service. +:warning: RPM Test requires user to run the `./test.sh` command with sudo permission, as rpm requires root to install and start the service. ### Backwards Compatibility Tests From a3bc958b89a1d8dc4747af1cd49d6ef9106052a6 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 19 Apr 2022 03:27:19 +0000 Subject: [PATCH 3/4] Update readme Signed-off-by: Peter Zhu --- src/test_workflow/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test_workflow/README.md b/src/test_workflow/README.md index 8223d1da9b..36e807f847 100644 --- a/src/test_workflow/README.md +++ b/src/test_workflow/README.md @@ -69,6 +69,12 @@ To run OpenSearch Dashboards integration tests. opensearch-dashboards=https://ci.opensearch.org/ci/dbc/bundle-build-dashboards/1.2.0/869/linux/x64 ``` +To run OpenSearch Dashboards integration tests with local artifacts on different distributions +```bash +./test.sh integ-test manifests/2.0.0/opensearch-dashboards-2.0.0-test.yml --paths opensearch=tar opensearch-dashboards=tar +./test.sh integ-test manifests/2.0.0/opensearch-dashboards-2.0.0-test.yml --paths opensearch=rpm opensearch-dashboards=rpm +``` + :warning: RPM Test requires user to run the `./test.sh` command with sudo permission, as rpm requires root to install and start the service. ### Backwards Compatibility Tests From 6ae389615dcb194cfe02033944e72e3e1a00ab09 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 19 Apr 2022 03:41:24 +0000 Subject: [PATCH 4/4] Improve test cases Signed-off-by: Peter Zhu --- tests/tests_system/test_process.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_system/test_process.py b/tests/tests_system/test_process.py index 90d5c5a330..d57086efbe 100644 --- a/tests/tests_system/test_process.py +++ b/tests/tests_system/test_process.py @@ -34,12 +34,12 @@ def test(self) -> None: @patch('psutil.Process') @patch('subprocess.check_output', return_value="MainPID=123") - def test_repm_pid(self, mock_subprocess_check_call: MagicMock, mock_psutil_process: MagicMock) -> None: + @patch('subprocess.check_call', return_code=0) + def test_repm_pid(self, mock_subprocess_check_call: MagicMock, mock_subprocess_check_output: MagicMock, mock_psutil_process: MagicMock) -> None: process_handler = Process("opensearch", "rpm") process_handler.start("./tests/tests_system/data/wait_for_input.sh", ".") - print(process_handler.pid) self.assertTrue(process_handler.started) self.assertIsNotNone(process_handler.pid)