Skip to content

Commit

Permalink
Add cleanup for the data dir after integtests (#4798)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored Jun 23, 2024
1 parent df6ba59 commit 63db27c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/test_workflow/integ_test/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def config_path(self) -> str:
pass

@property
@abstractmethod
def data_dir(self) -> str:
"""
Return the data directory for the distribution
"""
pass

@property
@abstractmethod
def log_dir(self) -> str:
"""
Return the log directory for the distribution
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 data_dir(self) -> str:
return os.path.join(os.sep, "var", "lib", self.filename)

@property
def log_dir(self) -> str:
return os.path.join(os.sep, "var", "log", self.filename)
Expand All @@ -39,6 +43,8 @@ def install(self, bundle_name: str) -> None:
'--purge',
self.filename,
'&&',
f'sudo rm -rf {os.path.dirname(self.config_path)} {self.data_dir} {self.log_dir}',
'&&',
'sudo',
'env',
'OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!',
Expand All @@ -64,4 +70,4 @@ def start_cmd(self) -> str:

def uninstall(self) -> None:
logging.info(f"Uninstall {self.filename} package after the test")
subprocess.check_call(f"sudo dpkg --purge {self.filename} && sudo rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True)
subprocess.check_call(f"sudo dpkg --purge {self.filename} && sudo rm -rf {os.path.dirname(self.config_path)} {self.data_dir} {self.log_dir}", shell=True)
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 data_dir(self) -> str:
return os.path.join(os.sep, "var", "lib", self.filename)

@property
def log_dir(self) -> str:
return os.path.join(os.sep, "var", "log", self.filename)
Expand All @@ -40,6 +44,8 @@ def install(self, bundle_name: str) -> None:
'-y',
self.filename,
'&&',
f'sudo rm -rf {os.path.dirname(self.config_path)} {self.data_dir} {self.log_dir}',
'&&',
'sudo',
'env',
'OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!',
Expand All @@ -66,4 +72,4 @@ def start_cmd(self) -> str:

def uninstall(self) -> None:
logging.info(f"Uninstall {self.filename} package after the test")
subprocess.check_call(f"sudo yum remove -y {self.filename} && sudo rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True)
subprocess.check_call(f"sudo yum remove -y {self.filename} && sudo rm -rf {os.path.dirname(self.config_path)} {self.data_dir} {self.log_dir}", shell=True)
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 data_dir(self) -> str:
return os.path.join(self.install_dir, "data")

@property
def log_dir(self) -> str:
return os.path.join(self.install_dir, "logs")
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 data_dir(self) -> str:
return os.path.join(self.install_dir, "data")

@property
def log_dir(self) -> str:
return os.path.join(self.install_dir, "logs")
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_data_dir(self) -> None:
self.assertEqual(self.distribution_deb.data_dir, os.path.join(os.sep, "var", "lib", "opensearch"))
self.assertEqual(self.distribution_deb_dashboards.data_dir, os.path.join(os.sep, "var", "lib", "opensearch-dashboards"))

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"))
Expand All @@ -45,6 +49,7 @@ def test_install(self, check_call_mock: Mock) -> None:
self.assertEqual(
(
"sudo dpkg --purge opensearch && "
f"sudo rm -rf {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.data_dir} {self.distribution_deb.log_dir} && "
"sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! "
"dpkg --install opensearch.deb && "
f"sudo chmod 0666 {self.distribution_deb.config_path} {os.path.dirname(self.distribution_deb.config_path)}/jvm.options && "
Expand All @@ -64,6 +69,7 @@ def test_install_opensearch_dashboards(self, check_call_mock: Mock) -> None:
self.assertEqual(
(
"sudo dpkg --purge opensearch-dashboards && "
f"sudo rm -rf {os.path.dirname(self.distribution_deb_dashboards.config_path)} {self.distribution_deb_dashboards.data_dir} {self.distribution_deb_dashboards.log_dir} && "
"sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! "
"dpkg --install opensearch-dashboards.deb && "
f"sudo chmod 0666 {self.distribution_deb_dashboards.config_path} && "
Expand All @@ -84,4 +90,10 @@ def test_uninstall(self, check_call_mock: Mock) -> None:
args_list = check_call_mock.call_args_list

self.assertEqual(check_call_mock.call_count, 1)
self.assertEqual(f"sudo dpkg --purge opensearch && sudo rm -rf {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.log_dir}", args_list[0][0][0])
self.assertEqual(
(
"sudo dpkg --purge opensearch && "
f"sudo rm -rf {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.data_dir} {self.distribution_deb.log_dir}"
),
args_list[0][0][0],
)
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_data_dir(self) -> None:
self.assertEqual(self.distribution_rpm.data_dir, os.path.join(os.sep, "var", "lib", "opensearch"))
self.assertEqual(self.distribution_rpm_dashboards.data_dir, os.path.join(os.sep, "var", "lib", "opensearch-dashboards"))

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"))
Expand All @@ -45,6 +49,7 @@ def test_install(self, check_call_mock: Mock) -> None:
self.assertEqual(
(
"sudo yum remove -y opensearch && "
f"sudo rm -rf {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.data_dir} {self.distribution_rpm.log_dir} && "
"sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! "
"yum install -y opensearch.rpm && "
f"sudo chmod 0666 {self.distribution_rpm.config_path} {os.path.dirname(self.distribution_rpm.config_path)}/jvm.options && "
Expand All @@ -64,6 +69,7 @@ def test_install_opensearch_dashboards(self, check_call_mock: Mock) -> None:
self.assertEqual(
(
"sudo yum remove -y opensearch-dashboards && "
f"sudo rm -rf {os.path.dirname(self.distribution_rpm_dashboards.config_path)} {self.distribution_rpm_dashboards.data_dir} {self.distribution_rpm_dashboards.log_dir} && "
"sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! "
"yum install -y opensearch-dashboards.rpm && "
f"sudo chmod 0666 {self.distribution_rpm_dashboards.config_path} && "
Expand All @@ -84,4 +90,10 @@ def test_uninstall(self, check_call_mock: Mock) -> None:
args_list = check_call_mock.call_args_list

self.assertEqual(check_call_mock.call_count, 1)
self.assertEqual(f"sudo yum remove -y opensearch && sudo rm -rf {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.log_dir}", args_list[0][0][0])
self.assertEqual(
(
"sudo yum remove -y opensearch && "
f"sudo rm -rf {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.data_dir} {self.distribution_rpm.log_dir}"
),
args_list[0][0][0],
)
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_data_dir(self) -> None:
self.assertEqual(self.distribution_tar.data_dir, os.path.join(self.work_dir, "opensearch-1.3.0", "data"))
self.assertEqual(self.distribution_tar_dashboards.data_dir, os.path.join(self.work_dir, "opensearch-dashboards-1.3.0", "data"))

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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ 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_data_dir(self) -> None:
self.assertEqual(self.distribution_zip.data_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "data"))
self.assertEqual(self.distribution_zip_dashboards.data_dir, os.path.join(self.work_dir, f"{self.product_dashboards}-{self.version}", "data"))

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"))
Expand Down

0 comments on commit 63db27c

Please sign in to comment.