Skip to content

Commit

Permalink
Add uninstall function for tar integTest between plugins (#2020)
Browse files Browse the repository at this point in the history
* Add uninstall function for tar integTest between plugins

Signed-off-by: Peter Zhu <[email protected]>

* Fix isort

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored Apr 21, 2022
1 parent 30aedfb commit 464b769
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/test_workflow/integ_test/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def start_cmd(self) -> str:
"""
pass

@abstractmethod
def uninstall(self) -> None:
"""
Allow distribution that is not 'tar' to do proper cleanup
Allow distribution to do proper cleanup
"""
pass
5 changes: 5 additions & 0 deletions src/test_workflow/integ_test/distribution_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
import subprocess
import tarfile

from test_workflow.integ_test.distribution import Distribution
Expand Down Expand Up @@ -35,3 +36,7 @@ def start_cmd(self) -> str:
"opensearch-dashboards": "./opensearch-dashboards",
}
return start_cmd_map[self.filename]

def uninstall(self) -> None:
logging.info(f"Cleanup {self.work_dir}/* content after the test")
subprocess.check_call(f"rm -rf {self.work_dir}/*", shell=True)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os
import unittest
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock, Mock, patch

from test_workflow.integ_test.distribution_tar import DistributionTar

Expand Down Expand Up @@ -43,3 +43,11 @@ def test_install(self) -> None:
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")

@patch("subprocess.check_call")
def test_uninstall(self, check_call_mock: Mock) -> None:
self.distribution_tar.uninstall()
args_list = check_call_mock.call_args_list

self.assertEqual(check_call_mock.call_count, 1)
self.assertEqual(f"rm -rf {self.work_dir}/*", args_list[0][0][0])

0 comments on commit 464b769

Please sign in to comment.