Skip to content

Commit 229d62f

Browse files
authored
[pipeline] optimize the way to set cert for test-proxy (Azure#28596)
* fix * update * update * ssl cert * clean test env * fix * update * pylint
1 parent 980148d commit 229d62f

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

scripts/auto_release/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,17 @@ def run_test_proc(self):
483483
log(f'{test_mode} run done, do not find failure !!!')
484484
self.test_result = succeeded_result
485485

486+
@staticmethod
487+
def clean_test_env():
488+
for item in ("SSL_CERT_DIR", "REQUESTS_CA_BUNDLE"):
489+
if os.getenv(item):
490+
os.environ.pop(item)
491+
486492
def run_test(self):
487493
self.prepare_test_env()
488494
self.run_test_proc()
495+
self.clean_test_env()
496+
489497

490498
def create_pr_proc(self):
491499
api = GhApi(owner='Azure', repo='azure-sdk-for-python', token=self.bot_token)

scripts/auto_release/util.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
import os
12
from pathlib import Path
2-
3-
4-
def _find_certificate():
5-
devcert_path = Path('eng/common/testproxy/dotnet-devcert.crt')
6-
with open(devcert_path, 'r') as fr:
7-
return fr.read()
3+
from subprocess import getoutput
84

95

106
def add_certificate():
11-
certification = _find_certificate()
12-
cacert_path = Path('../venv-sdk/lib/python3.8/site-packages/certifi/cacert.pem')
13-
with open(cacert_path, 'a+') as f:
14-
f.seek(0, 0)
15-
f.write(certification)
7+
# Set the following certificate paths:
8+
# SSL_CERT_DIR=C:\<YOUR DIRECTORY>\azure-sdk-for-python\.certificate
9+
# REQUESTS_CA_BUNDLE=C:\<YOUR DIRECTORY>\azure-sdk-for-python\.certificate\dotnet-devcert.pem
10+
result = getoutput(f"python {Path('scripts/devops_tasks/trust_proxy_cert.py')}").split("\n")
11+
for item in result[1:]:
12+
name, value = item.strip().split("=", 1)
13+
os.environ[name] = value

scripts/release_sdk_status/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ def run_test(sdk_name, service_name, sdk_folder):
282282
return test_result
283283

284284

285+
def clean_test_env():
286+
for item in ("SSL_CERT_DIR", "REQUESTS_CA_BUNDLE"):
287+
if os.getenv(item):
288+
os.environ.pop(item)
289+
290+
285291
def sdk_info_from_pypi(sdk_info: List[Dict[str, str]], cli_dependency):
286292
all_sdk_status = []
287293
add_certificate()
@@ -310,6 +316,7 @@ def sdk_info_from_pypi(sdk_info: List[Dict[str, str]], cli_dependency):
310316
text_to_write += test_result
311317
all_sdk_status.append(text_to_write)
312318

319+
clean_test_env()
313320
my_print(f'total pypi package kinds: {len(all_sdk_status)}')
314321
return all_sdk_status
315322

scripts/release_sdk_status/util.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import os
22
from pathlib import Path
3-
4-
5-
def _find_certificate():
6-
devcert_path = Path(os.getenv('SDK_REPO') + '/eng/common/testproxy/dotnet-devcert.crt')
7-
with open(devcert_path, 'r') as fr:
8-
return fr.read()
3+
from subprocess import getoutput
94

105

116
def add_certificate():
12-
certification = _find_certificate()
13-
cacert_path = Path('../venv-sdk/lib/python3.8/site-packages/certifi/cacert.pem')
14-
with open(cacert_path, 'a+') as f:
15-
f.seek(0, 0)
16-
f.write(certification)
7+
# Set the following certificate paths:
8+
# SSL_CERT_DIR=C:\<YOUR DIRECTORY>\azure-sdk-for-python\.certificate
9+
# REQUESTS_CA_BUNDLE=C:\<YOUR DIRECTORY>\azure-sdk-for-python\.certificate\dotnet-devcert.pem
10+
result = getoutput(f"python {Path('scripts/devops_tasks/trust_proxy_cert.py')}").split("\n")
11+
for item in result[1:]:
12+
name, value = item.strip().split("=", 1)
13+
os.environ[name] = value

0 commit comments

Comments
 (0)