9
9
import os
10
10
import shutil
11
11
import subprocess
12
- import time
13
12
from subprocess import PIPE
14
13
from typing import Any
15
14
16
- import requests
17
-
18
- from system .temporary_directory import TemporaryDirectory
19
- from validation_workflow .api_request import ApiTest
15
+ from test_workflow .integ_test .utils import get_password
20
16
from validation_workflow .api_test_cases import ApiTestCases
21
17
from validation_workflow .docker .inspect_docker_image import InspectDockerImage
22
18
from validation_workflow .validation import Validation
@@ -61,8 +57,7 @@ def start_cluster(self) -> bool:
61
57
def validation (self ) -> bool :
62
58
# STEP 2 . inspect image digest between opensearchproject(downloaded/local) and opensearchstaging(dockerHub)
63
59
if not self .args .using_staging_artifact_only :
64
- self .image_names_list = [self .args .OS_image , self .args .OSD_image ]
65
- self .image_names_list = [x for x in self .image_names_list if (os .path .basename (x ) in self .args .projects )]
60
+ self .image_names_list = ['opensearchproject/' + project for project in self .args .projects ]
66
61
self .image_digests = list (map (lambda x : self .inspect_docker_image (x [0 ], x [1 ]), zip (self .image_ids .values (), self .image_names_list ))) # type: ignore
67
62
if all (self .image_digests ):
68
63
logging .info ('Image digest is validated.\n \n ' )
@@ -79,7 +74,7 @@ def validation(self) -> bool:
79
74
self .args .version
80
75
)
81
76
if return_code :
82
- logging .info ('Checking if cluster is ready for API test in every 10 seconds\n \n ' )
77
+ logging .info ('Checking if cluster is ready for API test in every 5 seconds\n \n ' )
83
78
84
79
if self .check_cluster_readiness ():
85
80
# STEP 4 . OS, OSD API validation
@@ -94,8 +89,8 @@ def validation(self) -> bool:
94
89
raise Exception (f'Not all tests Pass : { _counter } ' )
95
90
else :
96
91
raise Exception ("Cluster is not ready for API test." )
97
- else :
98
- raise Exception ('The container failed to start. Exiting the validation.' )
92
+ else :
93
+ raise Exception ('The container failed to start. Exiting the validation.' )
99
94
100
95
return True
101
96
@@ -129,36 +124,6 @@ def cleanup_process(self) -> bool:
129
124
130
125
return ('returncode=0' in (str (result )))
131
126
132
- def check_http_request (self ) -> bool :
133
- self .test_readiness_urls = {
134
- 'https://localhost:9200/' : 'opensearch cluster API' ,
135
- 'http://localhost:5601/api/status' : 'opensearch-dashboards API' ,
136
- }
137
-
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 \n cluster 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
-
162
127
def get_artifact_image_name (self , artifact : str , using_staging_artifact_only : str ) -> Any :
163
128
self .image_names = {
164
129
'dockerhub' : {
@@ -241,7 +206,6 @@ def run_container(self, image_ids: dict, version: str) -> Any:
241
206
'2' : 'docker-compose-2.x.yml'
242
207
}
243
208
244
- self .tmp_dir = TemporaryDirectory ()
245
209
self .target_yml_file = os .path .join (self .tmp_dir .name , 'docker-compose.yml' )
246
210
247
211
self .major_version_number = version [0 ]
@@ -252,8 +216,9 @@ def run_container(self, image_ids: dict, version: str) -> Any:
252
216
self .replacements = [(f'opensearchproject/{ key } :{ self .major_version_number } ' , value ) for key , value in image_ids .items ()]
253
217
254
218
list (map (lambda r : self .inplace_change (self .target_yml_file , r [0 ], r [1 ]), self .replacements ))
255
-
219
+ os . environ [ "OPENSEARCH_INITIAL_ADMIN_PASSWORD" ] = get_password ( str ( version ))
256
220
# spin up containers
257
- self .docker_compose_up = f'docker-compose -f { self .target_yml_file } up -d'
221
+ services = "opensearch-node1 opensearch-node2" if "opensearch-dashboards" not in self .args .projects else ""
222
+ self .docker_compose_up = f'docker-compose -f { self .target_yml_file } up -d { services } '
258
223
result = subprocess .run (self .docker_compose_up , shell = True , stdout = PIPE , stderr = PIPE , universal_newlines = True )
259
224
return ('returncode=0' in (str (result )), self .target_yml_file )
0 commit comments