Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 def test_find_build_script_does_not_exist(self, *mocks):
     with self.assertRaisesRegex(
             ScriptFinder.ScriptNotFoundError,
             "Could not find build.sh script. Looked in .*",
     ):
         ScriptFinder.find_build_script("OpenSearch", "anything",
                                        self.component_without_scripts)
Ejemplo n.º 3
0
 def test_find_bwc_test_script_does_not_exist(self,
                                              *mocks: MagicMock) -> None:
     with self.assertRaisesRegex(
             ScriptFinder.ScriptNotFoundError,
             "Could not find bwctest.sh script. Looked in .*",
     ):
         ScriptFinder.find_bwc_test_script("anything",
                                           self.component_without_scripts)
Ejemplo n.º 4
0
    def build(self, build_recorder: BuildRecorder) -> None:

        # List of components whose build scripts support `-d` parameter
        # Bundled plugins do not need `-d` as they are java based zips
        DISTRIBUTION_SUPPORTED_COMPONENTS = [
            "OpenSearch", "OpenSearch-Dashboards"
        ]

        build_script = ScriptFinder.find_build_script(
            self.target.name, self.component.name,
            self.git_repo.working_directory)

        build_command = " ".join(
            filter(None, [
                "bash",
                build_script,
                f"-v {self.target.version}",
                f"-q {self.target.qualifier}"
                if self.target.qualifier else None,
                f"-p {self.target.platform}",
                f"-a {self.target.architecture}",
                f"-d {self.target.distribution}" if self.component.name
                in DISTRIBUTION_SUPPORTED_COMPONENTS else None,
                f"-s {str(self.target.snapshot).lower()}",
                f"-o {self.output_path}",
            ]))

        self.git_repo.execute(build_command)
        build_recorder.record_component(self.component.name, self.git_repo)
Ejemplo n.º 5
0
    def execute_integtest_sh(self, endpoint: str, port: int, security: bool,
                             test_config: str) -> int:
        script = ScriptFinder.find_integ_test_script(
            self.component.name, self.repo.working_directory)
        if os.path.exists(script):
            cmd = f"{script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}"
            self.repo_work_dir = os.path.join(
                self.repo.dir, self.test_config.working_directory
            ) if self.test_config.working_directory is not None else self.repo.dir
            (status, stdout, stderr) = execute(cmd, self.repo_work_dir, True,
                                               False)

            test_result_data = TestResultData(self.component.name, test_config,
                                              status, stdout, stderr,
                                              self.test_artifact_files)
            self.save_logs.save_test_result_data(test_result_data)
            if stderr:
                logging.info("Integration test run failed for component " +
                             self.component.name)
                logging.info(stderr)
            return status
        else:
            logging.info(
                f"{script} does not exist. Skipping integ tests for {self.component.name}"
            )
            return 0
Ejemplo n.º 6
0
 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.",
     )
Ejemplo n.º 7
0
 def test_find_build_script_component_script(self):
     self.assertEqual(
         os.path.join(self.component_with_scripts, "build.sh"),
         ScriptFinder.find_build_script("OpenSearch", "foobar",
                                        self.component_with_scripts),
         msg="A component with a script resolves to the script at the root.",
     )
Ejemplo n.º 8
0
    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 execute_bwctest_sh(self, config: str) -> int:
        security = self.is_security_enabled(config)
        script = ScriptFinder.find_bwc_test_script(self.component.name,
                                                   self.repo.working_directory)
        if os.path.exists(script):
            cmd = self.get_cmd(script, security, self.manifest.build.location)
            self.repo_work_dir = os.path.join(
                self.repo.dir, self.test_config.working_directory
            ) if self.test_config.working_directory is not None else self.repo.dir
            (status, stdout, stderr) = execute(cmd, self.repo_work_dir, True,
                                               False)

            test_result_data = TestResultData(self.component.name, config,
                                              status, stdout, stderr,
                                              self.test_artifact_files)
            self.save_logs.save_test_result_data(test_result_data)
            if stderr:
                logging.info("BWC test run failed for component " +
                             self.component.name)
                logging.info(stderr)
            return status
        else:
            logging.info(
                f"{script} does not exist. Skipping integ tests for {self.component.name}"
            )
            return 0
    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,
                ),
            ])
Ejemplo n.º 11
0
 def test_find_integ_test_script_default(self):
     self.assertEqual(
         os.path.join(ScriptFinder.default_scripts_path, "integtest.sh"),
         ScriptFinder.find_integ_test_script(
             "invalid", self.component_without_scripts),
         msg="A component without an override resolves to a default.",
     )
Ejemplo n.º 12
0
 def test_find_build_script_component_override(self):
     self.assertEqual(
         os.path.join(ScriptFinder.component_scripts_path, "OpenSearch",
                      "build.sh"),
         ScriptFinder.find_build_script("OpenSearch", "OpenSearch",
                                        self.component_without_scripts),
         msg="A component without scripts resolves to a component override.",
     )
Ejemplo n.º 13
0
 def test_find_build_script_opensearch_dashboards_default(self):
     self.assertEqual(
         os.path.join(ScriptFinder.default_scripts_path,
                      "opensearch-dashboards", "build.sh"),
         ScriptFinder.find_build_script("OpenSearch-Dashboards", "invalid",
                                        self.component_without_scripts),
         msg="A component without an override resolves to a default.",
     )
Ejemplo n.º 14
0
 def test_find_bwc_test_script_component_script(self):
     self.assertEqual(
         os.path.join(ScriptFinder.component_scripts_path, "OpenSearch",
                      "bwctest.sh"),
         ScriptFinder.find_bwc_test_script("OpenSearch",
                                           self.component_with_scripts),
         msg="A component with a script resolves to the script at the root.",
     )
Ejemplo n.º 15
0
 def test_find_bwc_test_script_component_script_in_folder(self):
     self.assertEqual(
         os.path.join(self.component_with_scripts_folder, "scripts",
                      "bwctest.sh"),
         ScriptFinder.find_bwc_test_script(
             "foobar", self.component_with_scripts_folder),
         msg="A component with a scripts folder resolves to an override.",
     )
Ejemplo n.º 16
0
 def test_find_build_script_component_script_in_folder_with_default(self):
     self.assertEqual(
         os.path.join(ScriptFinder.component_scripts_path, "OpenSearch",
                      "build.sh"),
         ScriptFinder.find_build_script("OpenSearch", "OpenSearch",
                                        self.component_with_scripts_folder),
         msg="A component with a scripts folder resolves to the override.",
     )
Ejemplo n.º 17
0
 def test_find_build_script_component_script_in_folder(self):
     self.assertEqual(
         os.path.join(self.component_with_scripts_folder, "scripts",
                      "build.sh"),
         ScriptFinder.find_build_script("OpenSearch", "foobar",
                                        self.component_with_scripts_folder),
         msg=
         "A component with a scripts folder resolves to a script in that folder.",
     )
Ejemplo n.º 18
0
 def test_find_bwc_test_script_component_script_in_folder_with_default(
         self):
     self.assertEqual(
         os.path.join(ScriptFinder.component_scripts_path, "OpenSearch",
                      "bwctest.sh"),
         ScriptFinder.find_bwc_test_script(
             "OpenSearch", self.component_with_scripts_folder),
         msg=
         "A component with a scripts folder resolves to a script in that folder.",
     )
Ejemplo n.º 19
0
 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)
Ejemplo n.º 20
0
 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)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
    def build(self, build_recorder: BuildRecorder) -> None:
        build_script = ScriptFinder.find_build_script(
            self.target.name, self.component.name,
            self.git_repo.working_directory)

        build_command = " ".join([
            "bash",
            build_script,
            "-v",
            self.target.version,
            "-p",
            self.target.platform,
            "-a",
            self.target.architecture,
            "-s",
            str(self.target.snapshot).lower(),
            "-o",
            self.output_path,
        ])

        self.git_repo.execute(build_command)
        build_recorder.record_component(self.component.name, self.git_repo)
Ejemplo n.º 25
0
 def run_tests(self, work_dir, component_name):
     script = ScriptFinder.find_bwc_test_script(component_name, work_dir)
     (status, stdout, stderr) = execute(script, work_dir, True, False)
     return (status, stdout, stderr)
Ejemplo n.º 26
0
 def test_find_install_script_default(self) -> None:
     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.",
     )