Skip to content

Commit 28ce961

Browse files
committed
Added script to run templates
1 parent 8f1134d commit 28ce961

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

tests/templates/deploy_templates.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import re
3+
import subprocess
4+
5+
subscription_id = "0b894477-1614-4c8d-8a9b-a697a24596b8"
6+
resource_group = "AzureFunctionsPythonWorkerCILinuxDevOps"
7+
8+
9+
def deploy_bicep_files():
10+
"""
11+
Deploy selected Bicep files compatible with the specified Python version to the given Azure resource group,
12+
with user-provided parameters for each template.
13+
14+
:param resource_group: The Azure resource group to deploy to.
15+
:param python_version: The Python version to filter Bicep files.
16+
"""
17+
# Get the current working directory
18+
directory = os.getcwd()
19+
20+
python_version = input("Enter the Python version (e.g., 3.8): ")
21+
22+
# Regex pattern to match files compatible with the specified Python version
23+
pattern = ".*\\.bicep$"
24+
25+
# List all Bicep files in the directory compatible with the specified Python version
26+
all_bicep_files = [f for f in os.listdir(directory) if re.search(pattern, f)]
27+
28+
if not all_bicep_files:
29+
print(f"No Bicep files found")
30+
return
31+
32+
# Display the list of files to the user
33+
print("Available Bicep Templates:")
34+
for idx, file in enumerate(all_bicep_files, 1):
35+
print(f"{idx}. {file}")
36+
37+
# Ask user to select files to deploy
38+
selected = input("Enter the numbers of the templates to deploy (comma separated), or type 'all' to deploy all: ")
39+
if selected.lower() == 'all':
40+
bicep_files_to_deploy = all_bicep_files
41+
else:
42+
selected_indices = [int(i) - 1 for i in selected.split(',') if i.isdigit()]
43+
bicep_files_to_deploy = [all_bicep_files[i] for i in selected_indices if 0 <= i < len(all_bicep_files)]
44+
45+
# Deploy the selected Bicep files
46+
for bicep_file in bicep_files_to_deploy:
47+
file_path = os.path.join(directory, bicep_file)
48+
49+
params_string = f"--parameters python_version={python_version.replace('.', '')}"
50+
51+
# Deploy the Bicep file
52+
print(f"Deploying {bicep_file}...")
53+
deploy_command = (f"az deployment group create --subscription {subscription_id} "
54+
f"--resource-group {resource_group} --template-file {file_path} {params_string}")
55+
subprocess.run(deploy_command, shell=True)
56+
57+
58+
deploy_bicep_files()

tests/unittests/test_dispatcher.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ async def test_sync_invocation_request_log_threads(self):
362362
'sync threadpool max workers: 5'
363363
)
364364

365+
@patch.dict('os.environ', {PYTHON_THREADPOOL_THREAD_COUNT: '4'})
365366
async def test_async_invocation_request_log_threads(self):
366-
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})
367+
#os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})
367368

368369
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
369370
async with self._ctrl as host:

0 commit comments

Comments
 (0)