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

test: test fixes & vulnerability scan #1594

Merged
merged 9 commits into from
Dec 4, 2024
Merged
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
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
# <img src="https://raw.githubusercontent.com/Azure/azure-functions-python-worker/dev/docs/Azure.Functions.svg" width = "30" alt="Functions Header Image - Lightning Logo"> Azure Functions Python Worker

| Branch | Status | CodeCov | Unittests | E2E tests |
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| main | [![Build Status](https://azfunc.visualstudio.com/Azure%20Functions/_apis/build/status/Azure.azure-functions-python-worker?branchName=main)](https://azfunc.visualstudio.com/Azure%20Functions/_build/latest?definitionId=57&branchName=main) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/main/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | ![CI Unit tests](https://github.com/Azure/azure-functions-python-worker/workflows/CI%20Unit%20tests/badge.svg?branch=main) | ![CI E2E tests](https://github.com/Azure/azure-functions-python-worker/workflows/CI%20E2E%20tests/badge.svg?branch=main) |
| dev | [![Build Status](https://azfunc.visualstudio.com/Azure%20Functions/_apis/build/status/Azure.azure-functions-python-worker?branchName=dev)](https://azfunc.visualstudio.com/Azure%20Functions/_build/latest?definitionId=57&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | ![CI Unit tests](https://github.com/Azure/azure-functions-python-worker/workflows/CI%20Unit%20tests/badge.svg?branch=dev) | ![CI E2E tests](https://github.com/Azure/azure-functions-python-worker/workflows/CI%20E2E%20tests/badge.svg?branch=dev) |
| Branch | Build Status | CodeCov | Test Status |
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| dev | [![Build Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | [![Test Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) |

Python support for Azure Functions is based on Python 3.6, 3.7, 3.8, 3.9, and 3.10 serverless hosting on Linux and the Functions 2.0, 3.0 and 4.0 runtime.
Python support for Azure Functions is based on Python 3.8, 3.9, 3.10, 3.11, and 3.12 serverless hosting on Linux and the Functions 4.0 runtime.

Here is the current status of Python in Azure Functions:

What are the supported Python versions?

| Azure Functions Runtime | Python 3.6 | Python 3.7 | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 |
|----------------------------------|------------|------------|------------|------------|-------------|-------------|
| Azure Functions 2.0 (deprecated) | ✔ | ✔ | - | - | - | - |
| Azure Functions 3.0 (deprecated) | ✔ | ✔ | ✔ | ✔ | - | - |
| Azure Functions 4.0 | - | - | ✔ | ✔ | ✔ | ✔ |
| Azure Functions Runtime | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 | Python 3.12 |
|----------------------------------|------------|------------|-------------|-------------|-------------|
| Azure Functions 3.0 (deprecated) | ✔ | ✔ | - | - | - |
| Azure Functions 4.0 | ✔ | ✔ | ✔ | ✔ | ✔ |

For information about Azure Functions Runtime, please refer to [Azure Functions runtime versions overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions) page.

### What's available?

- Build, test, debug and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
- Deploy Python Function project onto consumption, dedicated, or elastic premium plan.
- Deploy Python Function project in a custom docker image onto dedicated, or elastic premium plan.
- Triggers / Bindings : HTTP, Blob, Queue, Timer, Cosmos DB, Event Grid, Event Hubs and Service Bus
- Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
- Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
- Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
- Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
- Triggers / Bindings : Custom binding support

What's coming?
### What's new?

- [Durable Functions For Python](https://github.com/Azure/azure-functions-durable-python)
- [SDK Type Bindings for Blob](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-sdk-type-bindings-for-azure-blob-storage-with/ba-p/4146744)
- [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)

### Get Started

Expand Down Expand Up @@ -72,4 +71,4 @@ provided by the bot. You will only need to do this once across all repos using o

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
6 changes: 5 additions & 1 deletion eng/templates/jobs/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ jobs:
python -m pip install .
displayName: 'Build python worker'
# Skip the build stage for SDK and Extensions release branches. This stage will fail because pyproject.toml contains the updated (and unreleased) library version
condition: and(eq(variables.isSdkRelease, false), eq(variables.isExtensionsRelease, false), eq(variables['USETESTPYTHONSDK'], false), eq(variables['USETESTPYTHONEXTENSIONS'], false))
condition: and(eq(variables.isSdkRelease, false), eq(variables.isExtensionsRelease, false), eq(variables['USETESTPYTHONSDK'], false), eq(variables['USETESTPYTHONEXTENSIONS'], false))
- bash: |
pip install pip-audit
pip-audit -r requirements.txt
displayName: 'Run vulnerability scan'
21 changes: 20 additions & 1 deletion eng/templates/official/jobs/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ jobs:
eng/scripts/test-setup.sh
displayName: 'Install test python extension, dependencies and the worker'
condition: or(eq(variables.isExtensionsRelease, true), eq(variables['USETESTPYTHONEXTENSIONS'], true))
- powershell: |
$pipelineVarSet = "$(USETESTPYTHONSDK)"
Write-Host "pipelineVarSet: $pipelineVarSet"
$branch = "$(Build.SourceBranch)"
Write-Host "Branch: $branch"
if($branch.StartsWith("refs/heads/sdk/") -or $pipelineVarSet -eq "true")
{
Write-Host "##vso[task.setvariable variable=skipTest;]true"
}
else
{
Write-Host "##vso[task.setvariable variable=skipTest;]false"
}
displayName: 'Set skipTest variable'
condition: or(eq(variables.isSdkRelease, true), eq(variables['USETESTPYTHONSDK'], true))
- powershell: |
Write-Host "skipTest: $(skipTest)"
displayName: 'Display skipTest variable'
condition: or(eq(variables.isSdkRelease, true), eq(variables['USETESTPYTHONSDK'], true))
- bash: |
python -m pytest -q -n auto --dist loadfile --reruns 4 --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend tests/extension_tests/deferred_bindings_tests tests/extension_tests/http_v2_tests
env:
Expand All @@ -125,5 +144,5 @@ jobs:
AzureWebJobsSqlConnectionString: $(SQL_CONNECTION)
AzureWebJobsEventGridTopicUri: $(EVENTGRID_URI)
AzureWebJobsEventGridConnectionKey: $(EVENTGRID_CONNECTION)
USETESTPYTHONSDK: or(eq(variables.isSdkRelease, true), eq(variables['USETESTPYTHONSDK'], true))
skipTest: $(skipTest)
displayName: "Running $(PYTHON_VERSION) Python E2E Tests"
5 changes: 5 additions & 0 deletions pack/templates/macos_64_env_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ steps:
inputs:
disableAutoCwd: true
scriptPath: 'pack/scripts/mac_arm64_deps.sh'
- bash: |
pip install pip-audit
pip-audit -r requirements.txt
displayName: 'Run vulnerability scan'
- task: CopyFiles@2
inputs:
contents: |
Expand All @@ -35,4 +39,5 @@ steps:
!distutils-precedence.pth
!pkg_resources/**
!*.dist-info/**
!werkzeug/debug/shared/debugger.js
targetFolder: '$(Build.ArtifactStagingDirectory)'
5 changes: 5 additions & 0 deletions pack/templates/nix_env_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ steps:
inputs:
disableAutoCwd: true
scriptPath: 'pack/scripts/nix_deps.sh'
- bash: |
pip install pip-audit
pip-audit -r requirements.txt
displayName: 'Run vulnerability scan'
- task: CopyFiles@2
inputs:
contents: |
Expand All @@ -35,4 +39,5 @@ steps:
!distutils-precedence.pth
!pkg_resources/**
!*.dist-info/**
!werkzeug/debug/shared/debugger.js
targetFolder: '$(Build.ArtifactStagingDirectory)'
5 changes: 5 additions & 0 deletions pack/templates/win_env_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ steps:
- task: PowerShell@2
inputs:
filePath: 'pack\scripts\win_deps.ps1'
- bash: |
pip install pip-audit
pip-audit -r requirements.txt
displayName: 'Run vulnerability scan'
- task: CopyFiles@2
inputs:
contents: |
Expand All @@ -35,4 +39,5 @@ steps:
!distutils-precedence.pth
!pkg_resources\**
!*.dist-info\**
!werkzeug\debug\shared\debugger.js
targetFolder: '$(Build.ArtifactStagingDirectory)'
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ dev = [
"cryptography"
]
test-http-v2 = [
"azurefunctions-extensions-http-fastapi",
"azurefunctions-extensions-http-fastapi==1.0.0b1",
"ujson",
"orjson"
]
test-deferred-bindings = [
"azurefunctions-extensions-bindings-blob"
"azurefunctions-extensions-bindings-blob==1.0.0b2"
]

[build-system]
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Please list runtime dependencies in setup.py 'install_requires' and
# 'extras_require'.
# Required dependencies listed in pyproject.toml
.
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,55 @@ def put_get_multiple_blobs_as_bytes_return_http_response(
mimetype="application/json",
status_code=200
)


@app.function_name(name="blob_trigger_default_source_enum")
@app.blob_trigger(arg_name="file",
path="python-worker-tests/test-blob-trigger.txt",
connection="AzureWebJobsStorage",
source=func.BlobSource.LOGS_AND_CONTAINER_SCAN)
def blob_trigger_default_source_enum(file: func.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
})


@app.function_name(name="blob_trigger_eventgrid_source_enum")
@app.blob_trigger(arg_name="file",
path="python-worker-tests/test-blob-trigger.txt",
connection="AzureWebJobsStorage",
source=func.BlobSource.EVENT_GRID)
def blob_trigger_eventgrid_source_enum(file: func.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
})


@app.function_name(name="blob_trigger_default_source_str")
@app.blob_trigger(arg_name="file",
path="python-worker-tests/test-blob-trigger.txt",
connection="AzureWebJobsStorage",
source="LogsAndContainerScan")
def blob_trigger_default_source_str(file: func.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
})


@app.function_name(name="blob_trigger_eventgrid_source_str")
@app.blob_trigger(arg_name="file",
path="python-worker-tests/test-blob-trigger.txt",
connection="AzureWebJobsStorage",
source="EventGrid")
def blob_trigger_eventgrid_source_str(file: func.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
})
2 changes: 1 addition & 1 deletion tests/endtoend/test_dependency_isolation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_paths_resolution(self):
).lower()
)

@skipIf(is_envvar_true('USETESTPYTHONSDK'),
@skipIf(is_envvar_true('skipTest'),
'Running tests using an editable azure-functions package.')
def test_loading_libraries_from_customers_package(self):
"""Since the Python now loaded the customer's dependencies, the
Expand Down
Loading