Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource templates for tests #1407

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/templates/cosmosdb.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
param python_version string
param location string = resourceGroup().location

var cosmosdb_name = 'python-worker-${python_version}-cdb'

resource cosmosdb 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: cosmosdb_name
kind: 'GlobalDocumentDB'
location: location
properties: {
consistencyPolicy: { defaultConsistencyLevel: 'Session' }
locations: [
{
locationName: location
failoverPriority: 0
isZoneRedundant: false
}
]
databaseAccountOfferType: 'Standard'
enableAutomaticFailover: false
enableMultipleWriteLocations: false
apiProperties: {}
capabilities: [ { name: 'EnableServerless' } ]
}
}
58 changes: 58 additions & 0 deletions tests/templates/deploy_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import re
import subprocess

subscription_id = "0b894477-1614-4c8d-8a9b-a697a24596b8"
resource_group = "AzureFunctionsPythonWorkerCILinuxDevOps"


def deploy_bicep_files():
"""
Deploy selected Bicep files compatible with the specified Python version to the given Azure resource group,
with user-provided parameters for each template.

:param resource_group: The Azure resource group to deploy to.
:param python_version: The Python version to filter Bicep files.
"""
# Get the current working directory
directory = os.getcwd()

python_version = input("Enter the Python version (e.g., 3.8): ")

# Regex pattern to match files compatible with the specified Python version
pattern = ".*\\.bicep$"

# List all Bicep files in the directory compatible with the specified Python version
all_bicep_files = [f for f in os.listdir(directory) if re.search(pattern, f)]

if not all_bicep_files:
print(f"No Bicep files found")
return

# Display the list of files to the user
print("Available Bicep Templates:")
for idx, file in enumerate(all_bicep_files, 1):
print(f"{idx}. {file}")

# Ask user to select files to deploy
selected = input("Enter the numbers of the templates to deploy (comma separated), or type 'all' to deploy all: ")
if selected.lower() == 'all':
bicep_files_to_deploy = all_bicep_files
else:
selected_indices = [int(i) - 1 for i in selected.split(',') if i.isdigit()]
bicep_files_to_deploy = [all_bicep_files[i] for i in selected_indices if 0 <= i < len(all_bicep_files)]

# Deploy the selected Bicep files
for bicep_file in bicep_files_to_deploy:
file_path = os.path.join(directory, bicep_file)

params_string = f"--parameters python_version={python_version.replace('.', '')}"

# Deploy the Bicep file
print(f"Deploying {bicep_file}...")
deploy_command = (f"az deployment group create --subscription {subscription_id} "
f"--resource-group {resource_group} --template-file {file_path} {params_string}")
subprocess.run(deploy_command, shell=True)


deploy_bicep_files()
13 changes: 13 additions & 0 deletions tests/templates/eventgrid.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param python_version string
param location string = resourceGroup().location

var eventgrid_name = 'python-worker-${python_version}-egt'

resource eventgrid 'Microsoft.EventGrid/topics@2023-12-15-preview' = {
name: eventgrid_name
location: location
sku: {
name: 'Basic'
}
kind: 'Azure'
}
13 changes: 13 additions & 0 deletions tests/templates/eventhub.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param python_version string
param location string = resourceGroup().location

var eventhubname = 'python-worker-${python_version}-ehns'

resource eventhub 'Microsoft.EventHub/namespaces@2022-10-01-preview' = {
name: eventhubname
location: location
sku: {
name: 'Standard'
tier: 'Standard'
}
}
15 changes: 15 additions & 0 deletions tests/templates/servicebus.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
param python_version string
param location string = resourceGroup().location


var serviceBusNamespaceName = 'python-worker-${python_version}-sbns'

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-01-01-preview' = {
name: serviceBusNamespaceName
location: location
sku: {
name: 'Standard'
}
properties: {}
}

25 changes: 25 additions & 0 deletions tests/templates/storage_account.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
param location string = resourceGroup().location
param python_version string

var storage_account_name = 'pythonworker${python_version}sa'

resource storageAccount_input 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storage_account_name
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
}
accessTier: 'Hot'
publicNetworkAccess: 'Enabled'
dnsEndpointType: 'Standard'
allowBlobPublicAccess: true
minimumTlsVersion: 'TLS1_2'
allowSharedKeyAccess: true
}
}