From 83672cbaaee04dd73afc4a4f9ec02b3ac62aeefb Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 15 Mar 2024 15:38:25 -0400 Subject: [PATCH] Support new deb/rpm permissions changes in #4043 on integTest (#4534) Signed-off-by: Peter Zhu --- src/test_workflow/integ_test/distribution.py | 7 +++++++ src/test_workflow/integ_test/distribution_deb.py | 8 +++++++- src/test_workflow/integ_test/distribution_rpm.py | 8 +++++++- src/test_workflow/integ_test/distribution_tar.py | 4 ++++ src/test_workflow/integ_test/distribution_zip.py | 4 ++++ .../integ_test/test_distribution_deb.py | 7 ++++++- .../integ_test/test_distribution_rpm.py | 7 ++++++- .../integ_test/test_distribution_tar.py | 4 ++++ .../integ_test/test_distribution_zip.py | 5 +++++ 9 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/test_workflow/integ_test/distribution.py b/src/test_workflow/integ_test/distribution.py index d535edb6e3..93fbb35efa 100644 --- a/src/test_workflow/integ_test/distribution.py +++ b/src/test_workflow/integ_test/distribution.py @@ -41,6 +41,13 @@ def config_path(self) -> str: """ pass + @property + def log_dir(self) -> str: + """ + Return the log directory for the distribution + """ + pass + @abstractmethod def install(self, bundle_name: str) -> None: """ diff --git a/src/test_workflow/integ_test/distribution_deb.py b/src/test_workflow/integ_test/distribution_deb.py index 125219d5ec..dbaf0dec24 100644 --- a/src/test_workflow/integ_test/distribution_deb.py +++ b/src/test_workflow/integ_test/distribution_deb.py @@ -25,6 +25,10 @@ def install_dir(self) -> str: def config_path(self) -> str: return os.path.join(os.sep, "etc", self.filename, self.config_filename) + @property + def log_dir(self) -> str: + return os.path.join(os.sep, "var", "log", self.filename) + def install(self, bundle_name: str) -> None: logging.info(f"Installing {bundle_name} in {self.install_dir}") logging.info("deb installation requires sudo, script will exit if current user does not have sudo access") @@ -42,7 +46,9 @@ def install(self, bundle_name: str) -> None: '--install', bundle_name, '&&', - f'sudo chmod 0666 {self.config_path}' + f'sudo chmod 0666 {self.config_path}', + '&&', + f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}' ] ) subprocess.check_call(deb_install_cmd, cwd=self.work_dir, shell=True) diff --git a/src/test_workflow/integ_test/distribution_rpm.py b/src/test_workflow/integ_test/distribution_rpm.py index 8cd5c84572..9b8a6b4bc9 100644 --- a/src/test_workflow/integ_test/distribution_rpm.py +++ b/src/test_workflow/integ_test/distribution_rpm.py @@ -25,6 +25,10 @@ def install_dir(self) -> str: def config_path(self) -> str: return os.path.join(os.sep, "etc", self.filename, self.config_filename) + @property + def log_dir(self) -> str: + return os.path.join(os.sep, "var", "log", 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") @@ -44,7 +48,9 @@ def install(self, bundle_name: str) -> None: '-y', bundle_name, '&&', - f'sudo chmod 0666 {self.config_path}' + f'sudo chmod 0666 {self.config_path}', + '&&', + f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}' ] ) subprocess.check_call(rpm_install_cmd, cwd=self.work_dir, shell=True) diff --git a/src/test_workflow/integ_test/distribution_tar.py b/src/test_workflow/integ_test/distribution_tar.py index 4c8ed65336..e99ee34e40 100644 --- a/src/test_workflow/integ_test/distribution_tar.py +++ b/src/test_workflow/integ_test/distribution_tar.py @@ -25,6 +25,10 @@ def install_dir(self) -> str: def config_path(self) -> str: return os.path.join(self.install_dir, "config", self.config_filename) + @property + def log_dir(self) -> str: + return os.path.join(self.install_dir, "logs") + 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: diff --git a/src/test_workflow/integ_test/distribution_zip.py b/src/test_workflow/integ_test/distribution_zip.py index 2e56184934..12991891a4 100644 --- a/src/test_workflow/integ_test/distribution_zip.py +++ b/src/test_workflow/integ_test/distribution_zip.py @@ -25,6 +25,10 @@ def install_dir(self) -> str: def config_path(self) -> str: return os.path.join(self.install_dir, "config", self.config_filename) + @property + def log_dir(self) -> str: + return os.path.join(self.install_dir, "logs") + def install(self, bundle_name: str) -> None: logging.info(f"Installing {bundle_name} in {self.install_dir}") with ZipFile(bundle_name, "r") as zip: diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py index 67e31311f4..ffced7adbe 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py @@ -32,6 +32,10 @@ def test_config_path(self) -> None: self.assertEqual(self.distribution_deb.config_path, os.path.join(os.sep, "etc", "opensearch", "opensearch.yml")) self.assertEqual(self.distribution_deb_dashboards.config_path, os.path.join(os.sep, "etc", "opensearch-dashboards", "opensearch_dashboards.yml")) + def test_log_dir(self) -> None: + self.assertEqual(self.distribution_deb.log_dir, os.path.join(os.sep, "var", "log", "opensearch")) + self.assertEqual(self.distribution_deb_dashboards.log_dir, os.path.join(os.sep, "var", "log", "opensearch-dashboards")) + @patch("subprocess.check_call") def test_install(self, check_call_mock: Mock) -> None: self.distribution_deb.install("opensearch.deb") @@ -43,7 +47,8 @@ def test_install(self, check_call_mock: Mock) -> None: "sudo dpkg --purge opensearch && " "sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! " "dpkg --install opensearch.deb && " - f"sudo chmod 0666 {self.distribution_deb.config_path}" + f"sudo chmod 0666 {self.distribution_deb.config_path} && " + f"sudo chmod 0755 {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.log_dir}" ), args_list[0][0][0], ) diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py index 79c90d64c6..f60fed1034 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py @@ -32,6 +32,10 @@ def test_config_path(self) -> None: self.assertEqual(self.distribution_rpm.config_path, os.path.join(os.sep, "etc", "opensearch", "opensearch.yml")) self.assertEqual(self.distribution_rpm_dashboards.config_path, os.path.join(os.sep, "etc", "opensearch-dashboards", "opensearch_dashboards.yml")) + def test_log_dir(self) -> None: + self.assertEqual(self.distribution_rpm.log_dir, os.path.join(os.sep, "var", "log", "opensearch")) + self.assertEqual(self.distribution_rpm_dashboards.log_dir, os.path.join(os.sep, "var", "log", "opensearch-dashboards")) + @patch("subprocess.check_call") def test_install(self, check_call_mock: Mock) -> None: self.distribution_rpm.install("opensearch.rpm") @@ -43,7 +47,8 @@ def test_install(self, check_call_mock: Mock) -> None: "sudo yum remove -y opensearch && " "sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! " "yum install -y opensearch.rpm && " - f"sudo chmod 0666 {self.distribution_rpm.config_path}" + f"sudo chmod 0666 {self.distribution_rpm.config_path} && " + f"sudo chmod 0755 {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.log_dir}" ), 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 index 0b52fdc65a..766dc11e6c 100644 --- 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 @@ -34,6 +34,10 @@ def test_config_path(self) -> None: self.assertEqual(self.distribution_tar.config_path, os.path.join(self.work_dir, "opensearch-1.3.0", "config", "opensearch.yml")) self.assertEqual(self.distribution_tar_dashboards.config_path, os.path.join(self.work_dir, "opensearch-dashboards-1.3.0", "config", "opensearch_dashboards.yml")) + def test_log_dir(self) -> None: + self.assertEqual(self.distribution_tar.log_dir, os.path.join(self.work_dir, "opensearch-1.3.0", "logs")) + self.assertEqual(self.distribution_tar_dashboards.log_dir, os.path.join(self.work_dir, "opensearch-dashboards-1.3.0", "logs")) + def test_install(self) -> None: with patch("tarfile.open") as mock_tarfile_open: mock_tarfile_extractall = MagicMock() 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 index f05edb9458..e5d7a7845d 100644 --- 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 @@ -31,11 +31,16 @@ def test_distribution_zip_vars(self) -> None: def test_install_dir(self) -> None: self.assertEqual(self.distribution_zip.install_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}")) + self.assertEqual(self.distribution_zip_dashboards.install_dir, os.path.join(self.work_dir, f"{self.product_dashboards}-{self.version}")) def test_config_path(self) -> None: self.assertEqual(self.distribution_zip.config_path, os.path.join(self.work_dir, f"{self.product}-{self.version}", "config", "opensearch.yml")) self.assertEqual(self.distribution_zip_dashboards.config_path, os.path.join(self.work_dir, f"{self.product_dashboards}-{self.version}", "config", "opensearch_dashboards.yml")) + def test_log_dir(self) -> None: + self.assertEqual(self.distribution_zip.log_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "logs")) + self.assertEqual(self.distribution_zip_dashboards.log_dir, os.path.join(self.work_dir, f"{self.product_dashboards}-{self.version}", "logs")) + def test_install(self) -> None: with patch("test_workflow.integ_test.distribution_zip.ZipFile") as mock_zipfile_open: mock_zipfile_extractall = MagicMock()