Skip to content

Commit 3261601

Browse files
committedFeb 15, 2024
Add changes to docker
Signed-off-by: Divya Madala <divyaasm@amazon.com>
1 parent ae7fa5a commit 3261601

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed
 

‎src/validation_workflow/docker/inspect_docker_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, image_id: str, image_name: str, prod_image_tag: str) -> None:
2727
self.image_id = image_id
2828
self.image_name = image_name
2929
self.prod_image_tag = prod_image_tag
30-
self.image_tag = ValidationArgs().stg_tag('opensearch_dashboards').replace(" ", "") if ("dashboards" in self.image_name) else ValidationArgs().stg_tag('opensearch').replace(" ", "")
30+
self.image_tag = ValidationArgs().stg_tag('opensearch-dashboards').replace(" ", "") if ("dashboards" in self.image_name) else ValidationArgs().stg_tag('opensearch').replace(" ", "")
3131
self.auth_token_url = "https://auth.docker.io/token?"
3232
self.auth_service_scope = "service=registry.docker.io&scope=repository:"
3333
self.registry_url = "https://index.docker.io/v2/"

‎src/validation_workflow/docker/validation_docker.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import requests
1717

18+
from test_workflow.integ_test.utils import get_password
1819
from validation_workflow.api_request import ApiTest
1920
from validation_workflow.api_test_cases import ApiTestCases
2021
from validation_workflow.docker.inspect_docker_image import InspectDockerImage
@@ -60,7 +61,7 @@ def start_cluster(self) -> bool:
6061
def validation(self) -> bool:
6162
# STEP 2 . inspect image digest between opensearchproject(downloaded/local) and opensearchstaging(dockerHub)
6263
if not self.args.using_staging_artifact_only:
63-
self.image_names_list = [self.args.OS_image, self.args.OSD_image]
64+
self.image_names_list = ['opensearchproject/' + project for project in self.args.projects]
6465
self.image_names_list = [x for x in self.image_names_list if (os.path.basename(x) in self.args.projects)]
6566
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
6667
if all(self.image_digests):
@@ -93,8 +94,8 @@ def validation(self) -> bool:
9394
raise Exception(f'Not all tests Pass : {_counter}')
9495
else:
9596
raise Exception("Cluster is not ready for API test.")
96-
else:
97-
raise Exception('The container failed to start. Exiting the validation.')
97+
else:
98+
raise Exception('The container failed to start. Exiting the validation.')
9899

99100
return True
100101

@@ -130,10 +131,10 @@ def cleanup_process(self) -> bool:
130131

131132
def check_http_request(self) -> bool:
132133
self.test_readiness_urls = {
133-
'https://localhost:9200/': 'opensearch cluster API',
134-
'http://localhost:5601/api/status': 'opensearch-dashboards API',
134+
'https://localhost:9200': 'opensearch cluster API'
135135
}
136-
136+
if 'opensearch-dashboards' in self.args.projects:
137+
self.test_readiness_urls['http://localhost:5601/api/status'] = 'opensearch-dashboards API'
137138
for url, name in self.test_readiness_urls.items():
138139
try:
139140
status_code, response_text = ApiTest(url, self.args.version).api_get()
@@ -200,8 +201,7 @@ def inplace_change(self, filename: str, old_string: str, new_string: str) -> Non
200201
with open(filename) as f:
201202
s = f.read()
202203
if old_string not in s:
203-
logging.info
204-
('"{old_string}" not found in {filename}.'.format(**locals()))
204+
logging.info('"{old_string}" not found in {filename}.'.format(**locals()))
205205
return
206206
with open(filename, 'w') as f:
207207
logging.info('Changing "{old_string}" to "{new_string}" in {filename}'.format(**locals()))
@@ -250,8 +250,9 @@ def run_container(self, image_ids: dict, version: str) -> Any:
250250
self.replacements = [(f'opensearchproject/{key}:{self.major_version_number}', value) for key, value in image_ids.items()]
251251

252252
list(map(lambda r: self.inplace_change(self.target_yml_file, r[0], r[1]), self.replacements))
253-
253+
os.environ["OPENSEARCH_INITIAL_ADMIN_PASSWORD"] = get_password(str(version))
254254
# spin up containers
255-
self.docker_compose_up = f'docker-compose -f {self.target_yml_file} up -d'
255+
services = "opensearch-node1 opensearch-node2" if "opensearch-dashboards" not in self.args.projects else ""
256+
self.docker_compose_up = f'docker-compose -f {self.target_yml_file} up -d {services}'
256257
result = subprocess.run(self.docker_compose_up, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
257258
return ('returncode=0' in (str(result)), self.target_yml_file)

‎src/validation_workflow/validation_args.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ def __init__(self) -> None:
123123
"--validate-digest-only",
124124
action="store_true",
125125
default=False,
126-
help="(optional) Validate digest only; will not run docker to test API")
126+
help="(optional) Validate digest only; will not run docker to test API",
127+
dest="validate_digest_only")
127128
group.add_argument(
128129
"--using-staging-artifact-only",
129130
action="store_true",
130131
default=False,
131-
help="(optional) Use only staging artifact to run docker and API test, will not validate digest")
132+
help="(optional) Use only staging artifact to run docker and API test, will not validate digest",
133+
dest="using_staging_artifact_only")
132134

133135
args = parser.parse_args()
134136

@@ -140,6 +142,12 @@ def __init__(self) -> None:
140142
args.distribution = self.get_distribution_type(args.file_path)
141143
args.projects = args.file_path.keys()
142144

145+
if args.distribution == "docker":
146+
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")
148+
if not(args.validate_digest_only or args.using_staging_artifact_only):
149+
raise Exception("Provide either of --validate-digest-only and --using-staging-artifact-only for Docker Validation")
150+
143151
self.version = args.version
144152
self.file_path = args.file_path
145153
self.artifact_type = args.artifact_type
@@ -149,8 +157,6 @@ def __init__(self) -> None:
149157
self.platform = args.platform
150158
self.projects = args.projects
151159
self.arch = args.arch
152-
self.OS_image = 'opensearchproject/opensearch'
153-
self.OSD_image = 'opensearchproject/opensearch-dashboards'
154160
self.build_number = {"opensearch": args.os_build_number, "opensearch-dashboards": args.osd_build_number}
155161
self.os_build_number = args.os_build_number
156162
self.osd_build_number = args.osd_build_number
@@ -178,8 +184,8 @@ def stg_tag(self, image_type: str) -> str:
178184
None,
179185
[
180186
self.version,
181-
"." + self.os_build_number if (self.os_build_number != "") and (image_type == "opensearch") else None,
182-
"." + self.osd_build_number if (self.osd_build_number != "") and (image_type == "opensearch_dashboards") else None,
187+
"." + self.os_build_number if (self.os_build_number != "latest") and (image_type == "opensearch") else None,
188+
"." + self.osd_build_number if (self.osd_build_number != "latest") and (image_type == "opensearch-dashboards") else None,
183189
],
184190
)
185191
)

‎tests/tests_validation_workflow/test_inspect_docker_image.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ def setUp(self) -> None:
2323
self.prod_image_tag = "1.2.3"
2424
self.os_build_number = "1000"
2525
self.osd_build_number = "2000"
26+
self.projects = ["opensearch", "opensearch-dashboards"]
2627
self.version = "2.4.0"
2728
with patch("validation_workflow.docker.inspect_docker_image.ValidationArgs", MagicMock()) as mock_args:
2829
mock_args.stg_tag.return_value = "stg_tag"
2930
self.inspector = InspectDockerImage(self.image_id, self.image_name, self.prod_image_tag)
3031

3132
def test_validation_args_stg_arg(self) -> None:
32-
result = ValidationArgs.stg_tag(self, 'opensearch_dashboards').replace(" ", "") # type: ignore
33+
result = ValidationArgs.stg_tag(self, 'opensearch-dashboards').replace(" ", "") # type: ignore
3334
self.assertEqual(result, "2.4.0.2000")
3435
result = ValidationArgs.stg_tag(self, 'opensearch').replace(" ", "") # type: ignore
3536
self.assertEqual(result, "2.4.0.1000")

‎tests/tests_validation_workflow/test_validation_args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_without_arguments(self) -> None:
3434
def test_rpm_distribution(self) -> None:
3535
self.assertEqual(ValidationArgs().distribution, "rpm")
3636

37-
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker"])
37+
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker", "--projects", "opensearch", "--using-staging-artifact-only"])
3838
def test_docker_distribution(self) -> None:
3939
self.assertEqual(ValidationArgs().distribution, "docker")
4040
self.assertNotEqual(ValidationArgs().distribution, "yum")

0 commit comments

Comments
 (0)