Skip to content

Commit 097a50d

Browse files
committed
Add requested changes
Signed-off-by: Divya Madala <divyaasm@amazon.com>
1 parent 3261601 commit 097a50d

8 files changed

+78
-74
lines changed

src/validation_workflow/deb/validation_deb.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,29 @@ def installation(self) -> bool:
2929
execute(f'sudo {set_password} dpkg -i {os.path.basename(self.args.file_path.get(project))}', str(self.tmp_dir.path))
3030
time.sleep(80)
3131
except:
32-
raise Exception("Failed to install Opensearch")
32+
raise Exception("Failed to install OpenSearch/OpenSearch-Dashboards")
3333
return True
3434

3535
def start_cluster(self) -> bool:
3636
try:
3737
for project in self.args.projects:
3838
execute(f'sudo systemctl enable {project}', ".")
3939
execute(f'sudo systemctl start {project}', ".")
40-
time.sleep(20)
4140
execute(f'sudo systemctl status {project}', ".")
4241
except:
4342
raise Exception('Failed to Start Cluster')
4443
return True
4544

4645
def validation(self) -> bool:
47-
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
48-
if (test_result):
49-
logging.info(f'All tests Pass : {counter}')
50-
return True
46+
if self.check_cluster_readiness():
47+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
48+
if (test_result):
49+
logging.info(f'All tests Pass : {counter}')
50+
return True
51+
else:
52+
raise Exception(f'Not all tests Pass : {counter}')
5153
else:
52-
raise Exception(f'Not all tests Pass : {counter}')
54+
raise Exception("Cluster is not ready for API test")
5355

5456
def cleanup(self) -> bool:
5557
try:

src/validation_workflow/docker/validation_docker.py

+1-35
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
import os
1010
import shutil
1111
import subprocess
12-
import time
1312
from subprocess import PIPE
1413
from typing import Any
1514

16-
import requests
17-
1815
from test_workflow.integ_test.utils import get_password
19-
from validation_workflow.api_request import ApiTest
2016
from validation_workflow.api_test_cases import ApiTestCases
2117
from validation_workflow.docker.inspect_docker_image import InspectDockerImage
2218
from validation_workflow.validation import Validation
@@ -79,7 +75,7 @@ def validation(self) -> bool:
7975
self.args.version
8076
)
8177
if return_code:
82-
logging.info('Checking if cluster is ready for API test in every 10 seconds\n\n')
78+
logging.info('Checking if cluster is ready for API test in every 5 seconds\n\n')
8379

8480
if self.check_cluster_readiness():
8581
# STEP 4 . OS, OSD API validation
@@ -129,36 +125,6 @@ def cleanup_process(self) -> bool:
129125

130126
return('returncode=0' in (str(result)))
131127

132-
def check_http_request(self) -> bool:
133-
self.test_readiness_urls = {
134-
'https://localhost:9200': 'opensearch cluster API'
135-
}
136-
if 'opensearch-dashboards' in self.args.projects:
137-
self.test_readiness_urls['http://localhost:5601/api/status'] = 'opensearch-dashboards API'
138-
for url, name in self.test_readiness_urls.items():
139-
try:
140-
status_code, response_text = ApiTest(url, self.args.version).api_get()
141-
if status_code != 200:
142-
logging.error(f'Error connecting to {name} ({url}): status code {status_code}')
143-
return False
144-
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as e:
145-
logging.error(f'Error connecting to {name} ({url}): {e}')
146-
return False
147-
return True
148-
149-
def check_cluster_readiness(self) -> bool:
150-
max_retry = 20
151-
retry_count = 0
152-
while retry_count < max_retry:
153-
logging.info(f'sleeping 10sec for retry {retry_count + 1}/{max_retry}')
154-
time.sleep(10)
155-
if self.check_http_request():
156-
logging.info('\n\ncluster is now ready for API test\n\n')
157-
return True
158-
retry_count += 1
159-
logging.error(f"Maximum number of retries ({max_retry}) reached. Cluster is not ready for API test.")
160-
return False
161-
162128
def get_artifact_image_name(self, artifact: str, using_staging_artifact_only: str) -> Any:
163129
self.image_names = {
164130
'dockerhub': {

src/validation_workflow/rpm/validation_rpm.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import logging
99
import os
10-
import time
1110

1211
from system.execute import execute
1312
from test_workflow.integ_test.utils import get_password
@@ -37,7 +36,6 @@ def start_cluster(self) -> bool:
3736
try:
3837
for project in self.args.projects:
3938
execute(f'sudo systemctl start {project}', ".")
40-
time.sleep(20)
4139
(stdout, stderr, status) = execute(f'sudo systemctl status {project}', ".")
4240
if(status == 0):
4341
logging.info(stdout)
@@ -49,12 +47,15 @@ def start_cluster(self) -> bool:
4947
return True
5048

5149
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(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
53-
if (test_result):
54-
logging.info(f'All tests Pass : {counter}')
55-
return True
50+
if self.check_cluster_readiness():
51+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
52+
if (test_result):
53+
logging.info(f'All tests Pass : {counter}')
54+
return True
55+
else:
56+
raise Exception(f'Not all tests Pass : {counter}')
5657
else:
57-
raise Exception(f'Not all tests Pass : {counter}')
58+
raise Exception("Cluster is not ready for API test")
5859

5960
def cleanup(self) -> bool:
6061
try:

src/validation_workflow/tar/validation_tar.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import logging
99
import os
10-
import time
1110

1211
from system.execute import execute
1312
from system.process import Process
@@ -37,22 +36,23 @@ def installation(self) -> bool:
3736
def start_cluster(self) -> bool:
3837
try:
3938
self.os_process.start(f'export OPENSEARCH_INITIAL_ADMIN_PASSWORD={get_password(str(self.args.version))} && ./opensearch-tar-install.sh', os.path.join(self.tmp_dir.path, "opensearch"))
40-
time.sleep(85)
4139
if ("opensearch-dashboards" in self.args.projects):
4240
self.osd_process.start(os.path.join(str(self.tmp_dir.path), "opensearch-dashboards", "bin", "opensearch-dashboards"), ".")
43-
time.sleep(20)
4441
logging.info('Started cluster')
4542
except:
4643
raise Exception('Failed to Start Cluster')
4744
return True
4845

4946
def validation(self) -> bool:
50-
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
51-
if (test_result):
52-
logging.info(f'All tests Pass : {counter}')
47+
if self.check_cluster_readiness():
48+
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
49+
if (test_result):
50+
logging.info(f'All tests Pass : {counter}')
51+
return True
52+
else:
53+
raise Exception(f'Not all tests Pass : {counter}')
5354
else:
54-
raise Exception(f'Not all tests Pass : {counter}')
55-
return True
55+
raise Exception("Cluster is not ready for API test")
5656

5757
def cleanup(self) -> bool:
5858
try:

src/validation_workflow/validation.py

+34
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
import os
1111
import re
1212
import shutil
13+
import time
1314
from abc import ABC, abstractmethod
1415
from typing import Any
1516

17+
import requests
18+
1619
from system.temporary_directory import TemporaryDirectory
20+
from validation_workflow.api_request import ApiTest
1721
from validation_workflow.download_utils import DownloadUtils
1822
from validation_workflow.validation_args import ValidationArgs
1923

@@ -80,6 +84,36 @@ def get_filepath(self, project: str) -> str:
8084
return f"{self.base_url_production}{project}/{self.args.version[0:1]}.x/{project}-{self.args.version[0:1]}.x.repo"
8185
return f"{self.base_url_production}{project}/{self.args.version}/{project}-{self.args.version}-{self.args.platform}-{self.args.arch}.{file_name_suffix}"
8286

87+
def check_cluster_readiness(self) -> bool:
88+
max_retry = 20
89+
retry_count = 0
90+
while retry_count < max_retry:
91+
logging.info(f'sleeping 5sec for retry {retry_count + 1}/{max_retry}')
92+
time.sleep(5)
93+
if self.check_http_request():
94+
logging.info('\n\ncluster is now ready for API test\n\n')
95+
return True
96+
retry_count += 1
97+
logging.error(f"Maximum number of retries ({max_retry}) reached. Cluster is not ready for API test.")
98+
return False
99+
100+
def check_http_request(self) -> bool:
101+
self.test_readiness_urls = {
102+
'https://localhost:9200': 'opensearch cluster API'
103+
}
104+
if 'opensearch-dashboards' in self.args.projects:
105+
self.test_readiness_urls['http://localhost:5601/api/status'] = 'opensearch-dashboards API'
106+
for url, name in self.test_readiness_urls.items():
107+
try:
108+
status_code, response_text = ApiTest(url, self.args.version).api_get()
109+
if status_code != 200:
110+
logging.error(f'Error connecting to {name} ({url}): status code {status_code}')
111+
return False
112+
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as e:
113+
logging.error(f'Error connecting to {name} ({url}): {e}')
114+
return False
115+
return True
116+
83117
@abstractmethod
84118
def installation(self) -> bool:
85119
pass

src/validation_workflow/validation_args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __init__(self) -> None:
144144

145145
if args.distribution == "docker":
146146
if args.osd_build_number != "latest" and "opensearch-dashboards" not in args.projects:
147-
raise Exception("Provide opensearch-dashboards in projects argument to validate OSD")
147+
raise Exception("Provide opensearch-dashboards in projects argument to validate OpenSearch-Dashboards")
148148
if not(args.validate_digest_only or args.using_staging_artifact_only):
149149
raise Exception("Provide either of --validate-digest-only and --using-staging-artifact-only for Docker Validation")
150150

src/validation_workflow/yum/validation_yum.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import logging
99
import os
10-
import time
1110

1211
from system.execute import execute
1312
from test_workflow.integ_test.utils import get_password
@@ -40,19 +39,21 @@ def start_cluster(self) -> bool:
4039
try:
4140
for project in self.args.projects:
4241
execute(f'sudo systemctl start {project}', ".")
43-
time.sleep(20)
4442
execute(f'sudo systemctl status {project}', ".")
4543
except:
4644
raise Exception('Failed to Start Cluster')
4745
return True
4846

4947
def validation(self) -> bool:
50-
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
51-
if (test_result):
52-
logging.info(f'All tests Pass : {counter}')
53-
return True
48+
if self.check_cluster_readiness():
49+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects, self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if not self.args.force_https else True) # noqa: E501
50+
if (test_result):
51+
logging.info(f'All tests Pass : {counter}')
52+
return True
53+
else:
54+
raise Exception(f'Not all tests Pass : {counter}')
5455
else:
55-
raise Exception(f'Not all tests Pass : {counter}')
56+
raise Exception("Cluster is not ready for API test")
5657

5758
def cleanup(self) -> bool:
5859
try:

src/validation_workflow/zip/validation_zip.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import logging
99
import os
10-
import time
1110

1211
from system.process import Process
1312
from system.zip_file import ZipFile
@@ -30,28 +29,29 @@ def installation(self) -> bool:
3029
with ZipFile(os.path.join(self.tmp_dir.path, os.path.basename(self.args.file_path.get(project))), "r") as zip:
3130
zip.extractall(self.tmp_dir.path)
3231
except:
33-
raise Exception("Failed to install Opensearch")
32+
raise Exception("Failed to install OpenSearch/OpenSearch-Dashboards")
3433
return True
3534

3635
def start_cluster(self) -> bool:
3736
try:
3837
self.os_process.start(f"env OPENSEARCH_INITIAL_ADMIN_PASSWORD={get_password(str(self.args.version))} .\\opensearch-windows-install.bat", os.path.join(self.tmp_dir.path, f"opensearch-{self.args.version}"), False) # noqa: E501
39-
time.sleep(85)
4038
if "opensearch-dashboards" in self.args.projects:
4139
self.osd_process.start(".\\bin\\opensearch-dashboards.bat", os.path.join(self.tmp_dir.path, f"opensearch-dashboards-{self.args.version}"), False)
42-
time.sleep(20)
4340
logging.info("Starting cluster")
4441
except:
4542
raise Exception('Failed to Start Cluster')
4643
return True
4744

4845
def validation(self) -> bool:
49-
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
50-
if test_result:
51-
logging.info(f'All tests Pass : {counter}')
46+
if self.check_cluster_readiness():
47+
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
48+
if (test_result):
49+
logging.info(f'All tests Pass : {counter}')
50+
return True
51+
else:
52+
raise Exception(f'Not all tests Pass : {counter}')
5253
else:
53-
raise Exception(f'Not all tests Pass : {counter}')
54-
return True
54+
raise Exception("Cluster is not ready for API test")
5555

5656
def cleanup(self) -> bool:
5757
try:

0 commit comments

Comments
 (0)