Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm committed Apr 30, 2024
1 parent c752c52 commit 3fd1b7d
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 163 deletions.
8 changes: 5 additions & 3 deletions src/run_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys

from system import console
from system.temporary_directory import TemporaryDirectory
from validation_workflow.validation_args import ValidationArgs
from validation_workflow.validation_test_runner import ValidationTestRunner # type: ignore

Expand All @@ -19,9 +20,10 @@ def main() -> int:
console.configure(level=args.logging_level)
logging.getLogger("urllib3").setLevel(logging.WARNING)

test_result = ValidationTestRunner.dispatch(args, args.distribution).run()
logging.info(f'final test_result = {test_result}')
return 0 if test_result else 1 # type: ignore
with TemporaryDirectory() as work_dir:
test_result = ValidationTestRunner.dispatch(args, args.distribution, work_dir).run()
logging.info(f'final test_result = {test_result}')
return 0 if test_result else 1 # type: ignore


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions src/validation_workflow/deb/validation_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os

from system.execute import execute
from system.temporary_directory import TemporaryDirectory
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
from validation_workflow.download_utils import DownloadUtils
Expand All @@ -17,8 +18,8 @@


class ValidateDeb(Validation, DownloadUtils):
def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)

def installation(self) -> bool:
try:
Expand Down Expand Up @@ -48,6 +49,7 @@ def validation(self) -> bool:
logging.info(f'All tests Pass : {counter}')
return True
else:
self.cleanup()
raise Exception(f'Not all tests Pass : {counter}')
else:
raise Exception("Cluster is not ready for API test")
Expand Down
5 changes: 3 additions & 2 deletions src/validation_workflow/docker/validation_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from subprocess import PIPE
from typing import Any

from system.temporary_directory import TemporaryDirectory
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
from validation_workflow.docker.inspect_docker_image import InspectDockerImage
Expand All @@ -21,8 +22,8 @@

class ValidateDocker(Validation):

def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)

def download_artifacts(self) -> bool:
try:
Expand Down
6 changes: 4 additions & 2 deletions src/validation_workflow/rpm/validation_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os

from system.execute import execute
from system.temporary_directory import TemporaryDirectory
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
from validation_workflow.download_utils import DownloadUtils
Expand All @@ -18,8 +19,8 @@

class ValidateRpm(Validation, DownloadUtils):

def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)

def installation(self) -> bool:
try:
Expand Down Expand Up @@ -54,6 +55,7 @@ def validation(self) -> bool:
logging.info(f'All tests Pass : {counter}')
return True
else:
self.cleanup()
raise Exception(f'Not all tests Pass : {counter}')
else:
raise Exception("Cluster is not ready for API test")
Expand Down
7 changes: 5 additions & 2 deletions src/validation_workflow/tar/validation_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from system.execute import execute
from system.process import Process
from system.temporary_directory import TemporaryDirectory
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
from validation_workflow.download_utils import DownloadUtils
Expand All @@ -19,8 +20,8 @@

class ValidateTar(Validation, DownloadUtils):

def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)
self.os_process = Process()
self.osd_process = Process()

Expand Down Expand Up @@ -51,8 +52,10 @@ def validation(self) -> bool:
logging.info(f'All tests Pass : {counter}')
return True
else:
self.cleanup()
raise Exception(f'Not all tests Pass : {counter}')
else:
self.cleanup()
raise Exception("Cluster is not ready for API test")

def cleanup(self) -> bool:
Expand Down
13 changes: 8 additions & 5 deletions src/validation_workflow/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Validation(ABC):
Abstract class for all types of artifact validation
"""

def __init__(self, args: ValidationArgs) -> None:
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
self.args = args
self.base_url_production = "https://artifacts.opensearch.org/releases/bundle/"
self.base_url_staging = "https://ci.opensearch.org/ci/dbc/distribution-build-"
self.tmp_dir = TemporaryDirectory()
self.tmp_dir = tmp_dir

def check_url(self, url: str) -> bool:
if DownloadUtils().download(url, self.tmp_dir) and DownloadUtils().is_url_valid(url): # type: ignore
Expand All @@ -40,9 +40,9 @@ def check_url(self, url: str) -> bool:
else:
raise Exception(f"Invalid url - {url}")

def copy_artifact(self, filepath: str, tempdir_path: str) -> bool:
def copy_artifact(self, filepath: str, tmp_dir_path: str) -> bool:
if filepath:
shutil.copy2(filepath, tempdir_path)
shutil.copy2(filepath, tmp_dir_path)
return True
else:
raise Exception("Provided path for local artifacts does not exist")
Expand Down Expand Up @@ -105,6 +105,7 @@ def check_cluster_readiness(self) -> bool:
return False

def check_http_request(self) -> bool:
self.succesful_checks = 0
self.test_readiness_urls = {
'https://localhost:9200': 'opensearch cluster API'
}
Expand All @@ -113,7 +114,9 @@ def check_http_request(self) -> bool:
for url, name in self.test_readiness_urls.items():
try:
status_code, response_text = ApiTest(url, self.args.version).api_get()
if status_code != 200:
if status_code == 200:
self.succesful_checks += 1
else:
logging.error(f'Error connecting to {name} ({url}): status code {status_code}')
return False
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as e:
Expand Down
5 changes: 3 additions & 2 deletions src/validation_workflow/validation_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# compatible open source license.
# type: ignore

from system.temporary_directory import TemporaryDirectory
from validation_workflow.deb.validation_deb import ValidateDeb
from validation_workflow.docker.validation_docker import ValidateDocker
from validation_workflow.rpm.validation_rpm import ValidateRpm
Expand All @@ -27,5 +28,5 @@ class ValidationTestRunner:
}

@classmethod
def dispatch(cls, args: ValidationArgs, dist: str) -> Validation:
return cls.RUNNERS[dist](args)
def dispatch(cls, args: ValidationArgs, dist: str, work_dir: TemporaryDirectory) -> Validation:
return cls.RUNNERS[dist](args, work_dir)
6 changes: 4 additions & 2 deletions src/validation_workflow/yum/validation_yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os

from system.execute import execute
from system.temporary_directory import TemporaryDirectory
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
from validation_workflow.download_utils import DownloadUtils
Expand All @@ -18,8 +19,8 @@

class ValidateYum(Validation, DownloadUtils):

def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)

def installation(self) -> bool:
try:
Expand Down Expand Up @@ -52,6 +53,7 @@ def validation(self) -> bool:
logging.info(f'All tests Pass : {counter}')
return True
else:
self.cleanup()
raise Exception(f'Not all tests Pass : {counter}')
else:
raise Exception("Cluster is not ready for API test")
Expand Down
7 changes: 5 additions & 2 deletions src/validation_workflow/zip/validation_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os

from system.process import Process
from system.temporary_directory import TemporaryDirectory
from system.zip_file import ZipFile
from test_workflow.integ_test.utils import get_password
from validation_workflow.api_test_cases import ApiTestCases
Expand All @@ -18,8 +19,8 @@


class ValidateZip(Validation, DownloadUtils):
def __init__(self, args: ValidationArgs) -> None:
super().__init__(args)
def __init__(self, args: ValidationArgs, tmp_dir: TemporaryDirectory) -> None:
super().__init__(args, tmp_dir)
self.os_process = Process()
self.osd_process = Process()

Expand Down Expand Up @@ -51,8 +52,10 @@ def validation(self) -> bool:
logging.info(f'All tests Pass : {counter}')
return True
else:
self.cleanup()
raise Exception(f'Not all tests Pass : {counter}')
else:
self.cleanup()
raise Exception("Cluster is not ready for API test")

def cleanup(self) -> bool:
Expand Down
Loading

0 comments on commit 3fd1b7d

Please sign in to comment.