Skip to content

Commit

Permalink
Support new deb/rpm permissions changes in opensearch-project#4043 on…
Browse files Browse the repository at this point in the history
… integTest (opensearch-project#4534)

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored and Divyaasm committed Mar 21, 2024
1 parent 46ef70c commit 83672cb
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/test_workflow/integ_test/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
8 changes: 7 additions & 1 deletion src/test_workflow/integ_test/distribution_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/test_workflow/integ_test/distribution_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/test_workflow/integ_test/distribution_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/test_workflow/integ_test/distribution_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 83672cb

Please sign in to comment.