Skip to content

Commit 2f125d9

Browse files
committed
app settings tests, lint
1 parent 6e2758c commit 2f125d9

File tree

6 files changed

+79
-75
lines changed

6 files changed

+79
-75
lines changed

azure_functions_worker_v2/bindings/context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import threading
4-
from typing import Type
54

65
from .retrycontext import RetryContext
76
from .tracecontext import TraceContext

azure_functions_worker_v2/http_v2.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import asyncio
66
import importlib
77
import socket
8-
import sys
98
from typing import Any, Dict
109

1110
from azure_functions_worker_v2.utils.constants import (
12-
BASE_EXT_SUPPORTED_PY_MINOR_VERSION,
1311
X_MS_INVOCATION_ID,
1412
)
1513
from azure_functions_worker_v2.logging import logger
@@ -278,9 +276,6 @@ def ext_base(cls):
278276

279277
@classmethod
280278
def _check_http_v2_enabled(cls):
281-
if sys.version_info.minor < BASE_EXT_SUPPORTED_PY_MINOR_VERSION:
282-
return False
283-
284279
import azurefunctions.extensions.base as ext_base
285280
cls._ext_base = ext_base
286281

azure_functions_worker_v2/loader.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010

1111
from datetime import timedelta
12-
from typing import Any, Dict, Optional, Union
12+
from typing import Dict, Optional, Union
1313

1414

1515
from .functions import Registry
@@ -29,11 +29,6 @@
2929
from .utils.env_state import get_app_setting
3030
from .utils.wrappers import attach_message_to_exception
3131

32-
_AZURE_NAMESPACE = '__app__'
33-
_DEFAULT_SCRIPT_FILENAME = '__init__.py'
34-
_DEFAULT_ENTRY_POINT = 'main'
35-
_submodule_dirsL: list[Any] = []
36-
3732

3833
def convert_to_seconds(timestr: str):
3934
x = time.strptime(timestr, '%H:%M:%S')

azure_functions_worker_v2/utils/app_setting_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
from .constants import (
6-
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
6+
PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY,
77
PYTHON_ENABLE_DEBUG_LOGGING,
88
PYTHON_ENABLE_OPENTELEMETRY,
99
PYTHON_SCRIPT_FILE_NAME,
@@ -16,9 +16,9 @@ def get_python_appsetting_state():
1616
python_specific_settings = \
1717
[PYTHON_THREADPOOL_THREAD_COUNT,
1818
PYTHON_ENABLE_DEBUG_LOGGING,
19-
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
2019
PYTHON_SCRIPT_FILE_NAME,
21-
PYTHON_ENABLE_OPENTELEMETRY]
20+
PYTHON_ENABLE_OPENTELEMETRY,
21+
PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY]
2222

2323
app_setting_states = "".join(
2424
f"{app_setting}: {current_vars[app_setting]} | "
Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,63 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
# TODO: organize this better
4-
53
import sys
64

5+
# Constants for Azure Functions Python Worker
6+
CUSTOMER_PACKAGES_PATH = "/home/site/wwwroot/.python_packages/lib/site" \
7+
"-packages"
8+
HTTP = "http"
9+
HTTP_TRIGGER = "httpTrigger"
10+
METADATA_PROPERTIES_WORKER_INDEXED = "worker_indexed"
11+
MODULE_NOT_FOUND_TS_URL = "https://aka.ms/functions-modulenotfound"
12+
PYTHON_LANGUAGE_RUNTIME = "python"
13+
RETRY_POLICY = "retry_policy"
714
TRUE = "true"
815
TRACEPARENT = "traceparent"
916
TRACESTATE = "tracestate"
17+
X_MS_INVOCATION_ID = "x-ms-invocation-id"
18+
1019

1120
# Capabilities
21+
FUNCTION_DATA_CACHE = "FunctionDataCache"
22+
HTTP_URI = "HttpUri"
1223
RAW_HTTP_BODY_BYTES = "RawHttpBodyBytes"
13-
TYPED_DATA_COLLECTION = "TypedDataCollection"
24+
REQUIRES_ROUTE_PARAMETERS = "RequiresRouteParameters"
1425
RPC_HTTP_BODY_ONLY = "RpcHttpBodyOnly"
1526
RPC_HTTP_TRIGGER_METADATA_REMOVED = "RpcHttpTriggerMetadataRemoved"
16-
WORKER_STATUS = "WorkerStatus"
1727
SHARED_MEMORY_DATA_TRANSFER = "SharedMemoryDataTransfer"
18-
FUNCTION_DATA_CACHE = "FunctionDataCache"
19-
HTTP_URI = "HttpUri"
20-
REQUIRES_ROUTE_PARAMETERS = "RequiresRouteParameters"
28+
TYPED_DATA_COLLECTION = "TypedDataCollection"
2129
# When this capability is enabled, logs are not piped back to the
2230
# host from the worker. Logs will directly go to where the user has
2331
# configured them to go. This is to ensure that the logs are not
2432
# duplicated.
2533
WORKER_OPEN_TELEMETRY_ENABLED = "WorkerOpenTelemetryEnabled"
34+
WORKER_STATUS = "WorkerStatus"
35+
2636

2737
# Platform Environment Variables
2838
AZURE_WEBJOBS_SCRIPT_ROOT = "AzureWebJobsScriptRoot"
2939
CONTAINER_NAME = "CONTAINER_NAME"
30-
# Python Specific Feature Flags and App Settings
31-
PYTHON_THREADPOOL_THREAD_COUNT = "PYTHON_THREADPOOL_THREAD_COUNT"
32-
PYTHON_ENABLE_DEBUG_LOGGING = "PYTHON_ENABLE_DEBUG_LOGGING"
33-
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED = \
34-
"FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED"
35-
"""
36-
Comma-separated list of directories where shared memory maps can be created for
37-
data transfer between host and worker.
38-
"""
39-
UNIX_SHARED_MEMORY_DIRECTORIES = "FUNCTIONS_UNIX_SHARED_MEMORY_DIRECTORIES"
40-
41-
# Setting Defaults
42-
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT = 1
43-
PYTHON_THREADPOOL_THREAD_COUNT_MIN = 1
44-
PYTHON_THREADPOOL_THREAD_COUNT_MAX = sys.maxsize
45-
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37 = 32
46-
47-
# new programming model default script file name
48-
PYTHON_SCRIPT_FILE_NAME = "PYTHON_SCRIPT_FILE_NAME"
49-
PYTHON_SCRIPT_FILE_NAME_DEFAULT = "function_app.py"
50-
51-
# External Site URLs
52-
MODULE_NOT_FOUND_TS_URL = "https://aka.ms/functions-modulenotfound"
53-
54-
PYTHON_LANGUAGE_RUNTIME = "python"
55-
56-
# Settings for V2 programming model
57-
RETRY_POLICY = "retry_policy"
58-
59-
# Paths
60-
CUSTOMER_PACKAGES_PATH = "/home/site/wwwroot/.python_packages/lib/site" \
61-
"-packages"
62-
63-
METADATA_PROPERTIES_WORKER_INDEXED = "worker_indexed"
64-
65-
# Header names
66-
X_MS_INVOCATION_ID = "x-ms-invocation-id"
67-
68-
# Trigger Names
69-
HTTP_TRIGGER = "httpTrigger"
70-
71-
# Output Names
72-
HTTP = "http"
7340

74-
# Base extension supported Python minor version
75-
BASE_EXT_SUPPORTED_PY_MINOR_VERSION = 8
76-
77-
# Appsetting to turn on OpenTelemetry support/features
78-
# A value of "true" enables the setting
79-
PYTHON_ENABLE_OPENTELEMETRY = "PYTHON_ENABLE_OPENTELEMETRY"
8041

42+
# Python Specific Feature Flags and App Settings
43+
# Appsetting to specify AppInsights connection string
44+
APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING"
8145
# Appsetting to turn on ApplicationInsights support/features
8246
# A value of "true" enables the setting
8347
PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY = \
8448
"PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY"
85-
8649
# Appsetting to specify root logger name of logger to collect telemetry for
8750
# Used by Azure monitor distro (Application Insights)
8851
PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME = "PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME"
8952
PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME_DEFAULT = ""
90-
91-
# Appsetting to specify AppInsights connection string
92-
APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING"
53+
PYTHON_ENABLE_DEBUG_LOGGING = "PYTHON_ENABLE_DEBUG_LOGGING"
54+
# Appsetting to turn on OpenTelemetry support/features
55+
# A value of "true" enables the setting
56+
PYTHON_ENABLE_OPENTELEMETRY = "PYTHON_ENABLE_OPENTELEMETRY"
57+
# Allows for non-default script file name
58+
PYTHON_SCRIPT_FILE_NAME = "PYTHON_SCRIPT_FILE_NAME"
59+
PYTHON_SCRIPT_FILE_NAME_DEFAULT = "function_app.py"
60+
PYTHON_THREADPOOL_THREAD_COUNT = "PYTHON_THREADPOOL_THREAD_COUNT"
61+
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT = 1
62+
PYTHON_THREADPOOL_THREAD_COUNT_MAX = sys.maxsize
63+
PYTHON_THREADPOOL_THREAD_COUNT_MIN = 1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import os
4+
5+
from azure_functions_worker_v2.utils.app_setting_manager import get_python_appsetting_state
6+
from azure_functions_worker_v2.utils.constants import (
7+
PYTHON_ENABLE_DEBUG_LOGGING,
8+
PYTHON_THREADPOOL_THREAD_COUNT,
9+
)
10+
from tests.utils import testutils
11+
from unittest.mock import patch
12+
13+
14+
class TestDefaultAppSettingsLogs(testutils.AsyncTestCase):
15+
"""Tests for default app settings logs."""
16+
17+
def test_get_python_appsetting_state(self):
18+
app_setting_state = get_python_appsetting_state()
19+
expected_string = ""
20+
self.assertEquals(expected_string, app_setting_state)
21+
22+
23+
class TestNonDefaultAppSettingsLogs(testutils.AsyncTestCase):
24+
"""Tests for non-default app settings logs."""
25+
26+
@classmethod
27+
def setUpClass(cls):
28+
os_environ = os.environ.copy()
29+
os_environ[PYTHON_THREADPOOL_THREAD_COUNT] = '20'
30+
os_environ[PYTHON_ENABLE_DEBUG_LOGGING] = '1'
31+
cls._patch_environ = patch.dict('os.environ', os_environ)
32+
cls._patch_environ.start()
33+
super().setUpClass()
34+
35+
@classmethod
36+
def tearDownClass(cls):
37+
super().tearDownClass()
38+
cls._patch_environ.stop()
39+
40+
def test_get_python_appsetting_state(self):
41+
app_setting_state = get_python_appsetting_state()
42+
self.assertIn("PYTHON_THREADPOOL_THREAD_COUNT: 20 | ",
43+
app_setting_state)
44+
self.assertIn("PYTHON_ENABLE_DEBUG_LOGGING: 1 | ", app_setting_state)

0 commit comments

Comments
 (0)