|
| 1 | +# Copyright OpenSearch Contributors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# The OpenSearch Contributors require contributions made to |
| 5 | +# this file be licensed under the Apache-2.0 license or a |
| 6 | +# compatible open source license. |
| 7 | + |
| 8 | +import logging |
| 9 | +import os |
| 10 | +import time |
| 11 | + |
| 12 | +from system.execute import execute |
| 13 | +from system.process import Process |
| 14 | +from system.zip_file import ZipFile |
| 15 | +from test_workflow.integ_test.utils import get_password |
| 16 | +from validation_workflow.api_test_cases import ApiTestCases |
| 17 | +from validation_workflow.download_utils import DownloadUtils |
| 18 | +from validation_workflow.validation import Validation |
| 19 | +from validation_workflow.validation_args import ValidationArgs |
| 20 | + |
| 21 | + |
| 22 | +class ValidateZip(Validation, DownloadUtils): |
| 23 | + def __init__(self, args: ValidationArgs) -> None: |
| 24 | + super().__init__(args) |
| 25 | + self.os_process = Process() |
| 26 | + self.osd_process = Process() |
| 27 | + |
| 28 | + def installation(self) -> bool: |
| 29 | + try: |
| 30 | + for project in self.args.projects: |
| 31 | + with ZipFile(os.path.join(self.tmp_dir.path, os.path.basename(self.args.file_path.get(project))), "r") as zip: |
| 32 | + zip.extractall(self.tmp_dir.path) |
| 33 | + except: |
| 34 | + raise Exception("Failed to install Opensearch") |
| 35 | + return True |
| 36 | + |
| 37 | + def start_cluster(self) -> bool: |
| 38 | + try: |
| 39 | + execute(f"set OPENSEARCH_INITIAL_ADMIN_PASSWORD={get_password(str(self.args.version))}", ".", True) |
| 40 | + self.os_process.start(".\\opensearch-windows-install.bat", os.path.join(self.tmp_dir.path, f"opensearch-{self.args.version}"), False) |
| 41 | + time.sleep(85) |
| 42 | + if "opensearch-dashboards" in self.args.projects: |
| 43 | + self.osd_process.start(".\\bin\\opensearch-dashboards.bat", os.path.join(self.tmp_dir.path, f"opensearch-dashboards-{self.args.version}"), False) |
| 44 | + time.sleep(20) |
| 45 | + logging.info("Starting cluster") |
| 46 | + |
| 47 | + except: |
| 48 | + raise Exception('Failed to Start Cluster') |
| 49 | + return True |
| 50 | + |
| 51 | + def validation(self) -> bool: |
| 52 | + test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(self.tmp_dir.path, "opensearch")) if not self.args.force_https else True) # noqa: E501 |
| 53 | + if test_result: |
| 54 | + logging.info(f'All tests Pass : {counter}') |
| 55 | + else: |
| 56 | + raise Exception(f'Not all tests Pass : {counter}') |
| 57 | + return True |
| 58 | + |
| 59 | + def cleanup(self) -> bool: |
| 60 | + try: |
| 61 | + self.os_process.terminate() |
| 62 | + if ("opensearch-dashboards" in self.args.projects): |
| 63 | + self.osd_process.terminate() |
| 64 | + except: |
| 65 | + raise Exception('Failed to terminate the processes that started OpenSearch and OpenSearch-Dashboards') |
| 66 | + return True |
0 commit comments