Skip to content

Commit 07582b0

Browse files
committed
Add requested changes
Signed-off-by: Divya Madala <divyaasm@amazon.com>
1 parent 7694e8e commit 07582b0

15 files changed

+59
-58
lines changed

src/validation_workflow/deb/validation_deb.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def start_cluster(self) -> bool:
4242

4343
def validation(self) -> bool:
4444
if self.check_cluster_readiness():
45-
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
45+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects,
46+
self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if self.args.allow_http else True)
4647
if (test_result):
4748
logging.info(f'All tests Pass : {counter}')
4849
return True

src/validation_workflow/rpm/validation_rpm.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def start_cluster(self) -> bool:
4848

4949
def validation(self) -> bool:
5050
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
51+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects,
52+
self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if self.args.allow_http else True)
5253
if (test_result):
5354
logging.info(f'All tests Pass : {counter}')
5455
return True

src/validation_workflow/tar/validation_tar.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def start_cluster(self) -> bool:
4545

4646
def validation(self) -> bool:
4747
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
48+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects,
49+
self.check_for_security_plugin(os.path.join(self.tmp_dir.path, "opensearch")) if self.args.allow_http else True)
4950
if (test_result):
5051
logging.info(f'All tests Pass : {counter}')
5152
return True

src/validation_workflow/validation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def check_cluster_readiness(self) -> bool:
9595
max_retry = 20
9696
retry_count = 0
9797
while retry_count < max_retry:
98-
logging.info(f'sleeping 5sec for retry {retry_count + 1}/{max_retry}')
98+
logging.info(f'Sleeping 5sec for retry {retry_count + 1}/{max_retry}')
9999
time.sleep(5)
100100
if self.check_http_request():
101-
logging.info('\n\ncluster is now ready for API test\n\n')
101+
logging.info('\n\nCluster is now ready for API test\n\n')
102102
return True
103103
retry_count += 1
104104
logging.error(f"Maximum number of retries ({max_retry}) reached. Cluster is not ready for API test.")

src/validation_workflow/validation_args.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ def __init__(self) -> None:
113113
)
114114
parser.add_argument(
115115
"-f",
116-
"--force-https",
117-
action="store_false",
118-
default=True,
119-
help="If False, use http/https to connect based on the existence of security plugin, else always use https, default to True"
116+
"--allow-http",
117+
action="store_true",
118+
default=False,
119+
help="If True, use http/https to connect based on the existence of security plugin, else always use https, default to False"
120120
)
121121
group = parser.add_mutually_exclusive_group()
122122
group.add_argument(
@@ -146,14 +146,14 @@ def __init__(self) -> None:
146146

147147
if args.distribution == "docker":
148148
if args.osd_build_number != "latest" and "opensearch-dashboards" not in args.projects:
149-
raise Exception("Provide opensearch-dashboards in projects argument to validate OpenSearch-Dashboards")
150-
if not(args.validate_digest_only or args.using_staging_artifact_only):
149+
raise Exception("osd_build_number argument cannot be provided without specifying opensearch-dashboards in --projects")
150+
if not(args.validate_digest_only) and not(args.using_staging_artifact_only):
151151
raise Exception("Provide either of --validate-digest-only and --using-staging-artifact-only for Docker Validation")
152152

153153
self.version = args.version
154154
self.file_path = args.file_path
155155
self.artifact_type = args.artifact_type
156-
self.force_https = args.force_https
156+
self.allow_http = args.allow_http
157157
self.logging_level = args.logging_level
158158
self.distribution = args.distribution
159159
self.platform = args.platform

src/validation_workflow/yum/validation_yum.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def start_cluster(self) -> bool:
4646

4747
def validation(self) -> bool:
4848
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
49+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects,
50+
self.check_for_security_plugin(os.path.join(os.sep, "usr", "share", "opensearch")) if self.args.allow_http else True)
5051
if (test_result):
5152
logging.info(f'All tests Pass : {counter}')
5253
return True

src/validation_workflow/zip/validation_zip.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def installation(self) -> bool:
3434

3535
def start_cluster(self) -> bool:
3636
try:
37-
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
37+
self.os_process.start(f"env OPENSEARCH_INITIAL_ADMIN_PASSWORD={get_password(str(self.args.version))} .\\opensearch-windows-install.bat",
38+
os.path.join(self.tmp_dir.path, f"opensearch-{self.args.version}"), False)
3839
if "opensearch-dashboards" in self.args.projects:
3940
self.osd_process.start(".\\bin\\opensearch-dashboards.bat", os.path.join(self.tmp_dir.path, f"opensearch-dashboards-{self.args.version}"), False)
4041
logging.info("Starting cluster")
@@ -44,7 +45,8 @@ def start_cluster(self) -> bool:
4445

4546
def validation(self) -> bool:
4647
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+
test_result, counter = ApiTestCases().test_apis(self.args.version, self.args.projects,
49+
self.check_for_security_plugin(os.path.join(self.tmp_dir.path, "opensearch")) if self.args.allow_http else True)
4850
if (test_result):
4951
logging.info(f'All tests Pass : {counter}')
5052
return True

tests/tests_validation_workflow/test_validation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_check_for_security_plugin(self, mock_validation_args: Mock, mock_path_e
8181
def test_check_cluster_readiness_error(self, mock_validation_args: Mock, mock_check_http: Mock, mock_sleep: Mock) -> None:
8282
mock_validation_args.return_value.version = '1.0.0.1000'
8383
mock_validation_args.return_value.validate_digest_only = False
84-
mock_validation_args.return_value.force_https = False
84+
mock_validation_args.return_value.allow_http = False
8585
mock_validation_args.return_value.projects = ["opensearch"]
8686
mock_check_http.return_value = False
8787

@@ -96,7 +96,7 @@ def test_check_cluster_readiness_error(self, mock_validation_args: Mock, mock_ch
9696
def test_check_http_request(self, mock_api_get: Mock, mock_validation_args: Mock, mock_sleep: Mock) -> None:
9797
mock_validation_args.return_value.version = '1.3.13'
9898
mock_validation_args.return_value.validate_digest_only = False
99-
mock_validation_args.return_value.force_https = False
99+
mock_validation_args.return_value.allow_http = False
100100
mock_validation_args.return_value.projects = ["opensearch", "opensearch-dashboards"]
101101
mock_api_get.return_value = (200, "text")
102102

@@ -111,7 +111,7 @@ def test_check_http_request(self, mock_api_get: Mock, mock_validation_args: Mock
111111
def test_check_http_request_error(self, mock_api_get: Mock, mock_validation_args: Mock, mock_sleep: Mock) -> None:
112112
mock_validation_args.return_value.version = '1.3.14'
113113
mock_validation_args.return_value.validate_digest_only = False
114-
mock_validation_args.return_value.force_https = False
114+
mock_validation_args.return_value.allow_http = False
115115
mock_validation_args.return_value.projects = ["opensearch"]
116116
mock_api_get.return_value = (400, "text")
117117

@@ -126,7 +126,7 @@ def test_check_http_request_error(self, mock_api_get: Mock, mock_validation_args
126126
def test_check_http_request_connection_error(self, mock_api_get: Mock, mock_validation_args: Mock, mock_sleep: Mock) -> None:
127127
mock_validation_args.return_value.version = '2.3.0'
128128
mock_validation_args.return_value.validate_digest_only = False
129-
mock_validation_args.return_value.force_https = False
129+
mock_validation_args.return_value.allow_http = False
130130
mock_validation_args.return_value.projects = ["opensearch"]
131131
mock_api_get.side_effect = requests.exceptions.ConnectionError
132132

tests/tests_validation_workflow/test_validation_args.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,33 @@ def test_file_path(self) -> None:
6767
def test_artifact_type(self) -> None:
6868
self.assertNotEqual(ValidationArgs().artifact_type, "production")
6969

70-
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "1.3.6", "--distribution", "rpm", "--artifact-type", "staging", "--os-build-number", "1234", "--osd-build-number", "2312", "--force-https"]) # noqa: E501
71-
def test_force_https(self) -> None:
72-
self.assertEqual(ValidationArgs().force_https, False)
70+
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "1.3.6", "--distribution", "rpm", "--artifact-type", "staging",
71+
"--os-build-number", "1234", "--osd-build-number", "2312", "--allow-http"])
72+
def test_allow_http(self) -> None:
73+
self.assertEqual(ValidationArgs().allow_http, True)
7374

7475
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "1.3.6", "--distribution", "rpm", "--artifact-type", "staging", "--os-build-number", "1234", "--osd-build-number", "2312"])
75-
def test_without_force_https(self) -> None:
76-
self.assertEqual(ValidationArgs().force_https, True)
76+
def test_do_not_allow_http(self) -> None:
77+
self.assertEqual(ValidationArgs().allow_http, False)
7778

7879
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "1.3.0", "--projects", "opensearch"])
7980
def test_set_projects(self) -> None:
8081
self.assertEqual(ValidationArgs().projects, ["opensearch"])
8182

82-
@patch('sys.argv', [VALIDATION_PY, "--file-path", "opensearch=https://opensearch.org/releases/opensearch/2.8.0/opensearch-2.8.0-linux-x64.rpm", "opensearch-dashboard=https://opensearch.org/releases/opensearch/2.8.0/opensearch-dashboards-2.8.0-linux-x64.rpm"]) # noqa: E501
83+
@patch('sys.argv', [VALIDATION_PY, "--file-path", "opensearch=https://opensearch.org/releases/opensearch/2.8.0/opensearch-2.8.0-linux-x64.rpm",
84+
"opensearch-dashboard=https://opensearch.org/releases/opensearch/2.8.0/opensearch-dashboards-2.8.0-linux-x64.rpm"])
8385
def test_dashboards_exception(self) -> None:
8486
with self.assertRaises(Exception) as ctx:
8587
self.assertEqual(ValidationArgs().distribution, "rpm")
8688
self.assertEqual(str(ctx.exception), "Missing OpenSearch artifact details! Please provide the valid product names among opensearch and opensearch-dashboards")
8789

88-
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker", "--os-build-number", "1234", "--osd-build-number", "8393", "--projects", "opensearch", "--using-staging-artifact-only"]) # noqa: E501
90+
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker", "--os-build-number", "1234",
91+
"--osd-build-number", "8393", "--projects", "opensearch", "--using-staging-artifact-only"])
8992
def test_docker_exception(self) -> None:
9093
with self.assertRaises(Exception) as ctx:
9194
self.assertEqual(ValidationArgs().projects, ["opensearch"])
9295
self.assertEqual(ValidationArgs().osd_build_number, "1234")
93-
self.assertEqual(str(ctx.exception), "Provide opensearch-dashboards in projects argument to validate OpenSearch-Dashboards")
96+
self.assertEqual(str(ctx.exception), "osd_build_number argument cannot be provided without specifying opensearch-dashboards in --projects")
9497

9598
@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker", "--os-build-number", "1234", "--projects", "opensearch"])
9699
def test_docker_arguments_exception(self) -> None:

tests/tests_validation_workflow/test_validation_deb.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ def setUp(self) -> None:
1919
self.mock_args.projects = ["opensearch"]
2020
self.mock_args.file_path = {"opensearch": "/src/opensearch/opensearch-1.3.12.staging.deb"}
2121
self.mock_args.platform = "linux"
22-
self.mock_args.force_https_check = True
23-
self.mock_args.force_https = True
2422
self.call_methods = ValidateDeb(self.mock_args)
2523

2624
@patch("validation_workflow.deb.validation_deb.execute")
@@ -94,10 +92,9 @@ def test_validation(self, mock_check_cluster: Mock, mock_test_apis: Mock) -> Non
9492
@patch('validation_workflow.validation.Validation.check_for_security_plugin')
9593
@patch('validation_workflow.validation.Validation.check_cluster_readiness')
9694
@patch('validation_workflow.tar.validation_tar.ValidationArgs')
97-
def test_validation_without_force_https_check(self, mock_validation_args: Mock, mock_check_cluster: Mock, mock_security: Mock, mock_system: Mock,
98-
mock_basename: Mock, mock_test_apis: Mock) -> None:
95+
def test_validation_with_allow_http(self, mock_validation_args: Mock, mock_check_cluster: Mock, mock_security: Mock, mock_system: Mock, mock_basename: Mock, mock_test_apis: Mock) -> None:
9996
mock_validation_args.return_value.version = '2.3.0'
100-
mock_validation_args.return_value.force_https = False
97+
mock_validation_args.return_value.allow_http = True
10198
validate_deb = ValidateDeb(mock_validation_args.return_value)
10299
mock_check_cluster.return_value = True
103100
mock_basename.side_effect = lambda path: "mocked_filename"

tests/tests_validation_workflow/test_validation_docker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_staging(self, mock_digest: Mock, mock_container: Mock, mock_test: Mock,
4949
# Set up mock objects
5050
mock_validation_args.return_value.version = '1.0.0.1000'
5151
mock_validation_args.return_value.validate_digest_only = False
52-
mock_validation_args.return_value.force_https = False
52+
mock_validation_args.return_value.allow_http = False
5353
mock_validation_args.return_value.projects = ["opensearch"]
5454
mock_docker_image.return_value = MagicMock()
5555
mock_container.return_value = (True, 'test_file.yml')
@@ -79,7 +79,7 @@ def test_staging_cluster_not_ready(self, mock_container: Mock, mock_validation_a
7979
mock_cluster_readiness: Mock) -> None:
8080
mock_validation_args.return_value.version = '1.0.0.1000'
8181
mock_validation_args.return_value.validate_digest_only = False
82-
mock_validation_args.return_value.force_https = False
82+
mock_validation_args.return_value.allow_http = False
8383
mock_validation_args.return_value.projects = ["opensearch"]
8484
mock_cluster_readiness.return_value = False
8585
mock_container.return_value = (True, 'test_file.yml')
@@ -98,7 +98,7 @@ def test_staging_cluster_not_ready(self, mock_container: Mock, mock_validation_a
9898
def test_container_startup_exception(self, mock_container: Mock, mock_validation_args: Mock) -> None:
9999
mock_validation_args.return_value.version = '1.0.0.1000'
100100
mock_validation_args.return_value.validate_digest_only = False
101-
mock_validation_args.return_value.force_https = False
101+
mock_validation_args.return_value.allow_http = False
102102
mock_validation_args.return_value.projects = ["opensearch"]
103103
mock_container.return_value = (False, 'test_file.yml')
104104

tests/tests_validation_workflow/test_validation_rpm.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ def test_exceptions(self, mock_validation_args: Mock) -> None:
8484
mock_validation_args.return_value.projects = ["opensearch", "opensearch-dashboards"]
8585
validate_rpm = ValidateRpm(mock_validation_args.return_value)
8686
validate_rpm.cleanup()
87-
self.assertIn("Exception occurred either while attempting to stop cluster or removing OpenSearch/OpenSearch-Dashboards.", str(e3.exception)) # noqa: E501
87+
self.assertIn("Exception occurred either while attempting to stop cluster or removing OpenSearch/OpenSearch-Dashboards.",
88+
str(e3.exception))
8889

8990
@patch('validation_workflow.rpm.validation_rpm.ValidationArgs')
9091
@patch("validation_workflow.rpm.validation_rpm.execute")
9192
def test_installation(self, mock_system: Mock, mock_validation_args: Mock) -> None:
9293
mock_validation_args.return_value.version = '2.3.0'
9394
mock_validation_args.return_value.arch = 'x64'
9495
mock_validation_args.return_value.platform = 'linux'
95-
mock_validation_args.return_value.force_https = True
96+
mock_validation_args.return_value.allow_http = True
9697
mock_validation_args.return_value.projects = ["opensearch"]
9798

9899
validate_rpm = ValidateRpm(mock_validation_args.return_value)
@@ -132,11 +133,9 @@ def test_validation(self, mock_check_cluster: Mock, mock_test_apis: Mock, mock_v
132133
@patch('validation_workflow.rpm.validation_rpm.execute')
133134
@patch('validation_workflow.validation.Validation.check_for_security_plugin')
134135
@patch('validation_workflow.validation.Validation.check_cluster_readiness')
135-
def test_validation_without_force_https_check(self, mock_check_cluster: Mock, mock_security: Mock,
136-
mock_system: Mock, mock_basename: Mock, mock_test_apis: Mock,
137-
mock_validation_args: Mock) -> None:
136+
def test_validation_with_allow_http_check(self, mock_check_cluster: Mock, mock_security: Mock, mock_system: Mock, mock_basename: Mock, mock_test_apis: Mock, mock_validation_args: Mock) -> None:
138137
mock_validation_args.return_value.version = '2.3.0'
139-
mock_validation_args.return_value.force_https = False
138+
mock_validation_args.return_value.allow_http = True
140139
validate_rpm = ValidateRpm(mock_validation_args.return_value)
141140
mock_check_cluster.return_value = True
142141
mock_basename.side_effect = lambda path: "mocked_filename"

0 commit comments

Comments
 (0)