def test_find_install_script_does_not_exist(self, *mocks: MagicMock) -> None: with self.assertRaisesRegex( ScriptFinder.ScriptNotFoundError, "Could not find install.sh script. Looked in .*", ): ScriptFinder.find_install_script("anything")
def test_bundle_install_min(self) -> None: manifest_path = os.path.join( os.path.dirname(__file__), "data/opensearch-dashboards-build-1.1.0.yml") artifacts_path = os.path.join(os.path.dirname(__file__), "data/artifacts") bundle = BundleOpenSearchDashboards( BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()) with patch("subprocess.check_call") as mock_check_call: bundle.install_min() self.assertEqual(mock_check_call.call_count, 1) mock_check_call.assert_has_calls([ call( " ".join([ "bash", ScriptFinder.find_install_script( "OpenSearch-Dashboards"), "-v 1.1.0", "-p linux", "-a x64", "-f", artifacts_path, "-o", bundle.min_dist.archive_path, ]), cwd=bundle.min_dist.archive_path, shell=True, ), ])
def test_find_install_script_component_override(self): self.assertEqual( os.path.join(ScriptFinder.component_scripts_path, "performance-analyzer", "install.sh"), ScriptFinder.find_install_script("performance-analyzer"), msg="A component without scripts resolves to a component override.", )
def test_bundle_install_min_patch(self, mock_os_rename: Mock, mock_check_call: Mock) -> None: manifest_path = os.path.join(os.path.dirname(__file__), "data", "opensearch-build-linux-1.1.1.yml") artifacts_path = os.path.join(os.path.dirname(__file__), "data", "artifacts") bundle = BundleOpenSearch(BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()) bundle.install_min() self.assertEqual(mock_check_call.call_count, 1) mock_os_rename.assert_called_with( os.path.join(bundle.tmp_dir.name, "opensearch-1.1.0"), os.path.join(bundle.tmp_dir.name, "opensearch-1.1.1")) mock_check_call.assert_has_calls([ call( " ".join([ "bash", ScriptFinder.find_install_script("OpenSearch"), "-v 1.1.1-SNAPSHOT", "-p linux", "-a x64", "-f", artifacts_path, "-o", bundle.min_dist.archive_path, ]), cwd=bundle.min_dist.archive_path, shell=True, ), ])
def install_plugin(self, plugin: BuildComponent) -> None: install_script = ScriptFinder.find_install_script(plugin.name) install_command = " ".join([ "bash", install_script, f"-v {self.build.version}", f"-p {self.build.platform}", f"-a {self.build.architecture}", f"-f {self.artifacts_dir}", f"-o {self.min_dist.archive_path}", ]) self._execute(install_command)
def install_min(self) -> None: install_script = ScriptFinder.find_install_script(self.min_dist.name) install_command = " ".join( filter(None, [ "bash", install_script, f"-v {self.build.version}", f"-p {self.build.platform}", f"-a {self.build.architecture}", f"-d {self.build.distribution}" if self.build.distribution else None, f"-f {self.artifacts_dir}", f"-o {self.min_dist.archive_path}", ])) self._execute(install_command)
def test_bundle_install_plugin(self, path_isfile: Mock) -> None: manifest_path = os.path.join( os.path.dirname(__file__), "data/opensearch-dashboards-build-1.1.0.yml") artifacts_path = os.path.join(os.path.dirname(__file__), "data", "artifacts") bundle = BundleOpenSearchDashboards( BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()) plugin = bundle.components['alertingDashboards'] with patch("shutil.copyfile") as mock_copyfile: with patch("subprocess.check_call") as mock_check_call: bundle.install_plugin(plugin) self.assertEqual(mock_copyfile.call_count, 1) self.assertEqual(mock_check_call.call_count, 2) install_plugin_bin = os.path.join( bundle.min_dist.archive_path, "bin", "opensearch-dashboards-plugin") mock_check_call.assert_has_calls([ call( f'{install_plugin_bin} --allow-root install file:{os.path.join(bundle.tmp_dir.name, "alertingDashboards-1.1.0.zip")}', cwd=bundle.min_dist.archive_path, shell=True, ), call( " ".join([ "bash", ScriptFinder.find_install_script( "alertingDashboards"), "-v 1.1.0", "-p linux", "-a x64", "-f", artifacts_path, "-o", bundle.min_dist.archive_path, ]), cwd=bundle.min_dist.archive_path, shell=True, ), ]) self.assertEqual(path_isfile.call_count, 2)
def install_plugin(self, plugin: BuildComponent) -> None: install_script = ScriptFinder.find_install_script(plugin.name) install_command = " ".join([ "bash", install_script, "-v", self.build.version, "-p", self.build.platform, "-a", self.build.architecture, "-f", self.artifacts_dir, "-o", self.min_dist.archive_path, ]) self._execute(install_command)
def test_bundle_install_plugin(self, path_isfile: Mock) -> None: manifest_path = os.path.join(os.path.dirname(__file__), "data", "opensearch-build-linux-1.1.0.yml") artifacts_path = os.path.join(os.path.dirname(__file__), "data", "artifacts") bundle = BundleOpenSearch(BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()) plugin = bundle.components['job-scheduler'] with patch("shutil.copyfile") as mock_copyfile: with patch("subprocess.check_call") as mock_check_call: bundle.install_plugin(plugin) self.assertEqual(mock_copyfile.call_count, 1) self.assertEqual(mock_check_call.call_count, 2) script = "opensearch-plugin.bat" if current_platform( ) == "windows" else "opensearch-plugin" install_plugin_bin = os.path.join(bundle.min_dist.archive_path, "bin", script) mock_check_call.assert_has_calls([ call( f'{install_plugin_bin} install --batch file:{os.path.join(bundle.tmp_dir.name, "opensearch-job-scheduler-1.1.0.0.zip")}', cwd=bundle.min_dist.archive_path, shell=True, ), call( " ".join([ "bash", ScriptFinder.find_install_script( "opensearch-job-scheduler"), "-v 1.1.0", "-p linux", "-a x64", "-f", artifacts_path, "-o", bundle.min_dist.archive_path, ]), cwd=bundle.min_dist.archive_path, shell=True, ), ]) self.assertEqual(path_isfile.call_count, 2)
def test_find_install_script_default(self): self.assertEqual( os.path.join(ScriptFinder.default_scripts_path, "install.sh"), ScriptFinder.find_install_script("invalid"), msg="A component without an override resolves to a default.", )