Skip to content

test: Mount base extension to fix consumption test failures #1470

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

Merged
merged 4 commits into from
Apr 10, 2024
Merged
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
26 changes: 26 additions & 0 deletions tests/utils/testutils_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"/archive/refs/heads/dev.zip"
_FUNC_FILE_NAME = "azure-functions-python-library-dev"
_CUSTOM_IMAGE = "CUSTOM_IMAGE"
_EXTENSION_BASE_ZIP = 'https://github.com/Azure/azure-functions-python-' \
'extensions/archive/refs/heads/dev.zip'


class LinuxConsumptionWebHostController:
Expand Down Expand Up @@ -151,6 +153,15 @@ def _download_azure_functions() -> str:
with ZipFile(BytesIO(zipresp.read())) as zfile:
zfile.extractall(tempfile.gettempdir())

@staticmethod
def _download_extensions() -> str:
folder = tempfile.gettempdir()
with urlopen(_EXTENSION_BASE_ZIP) as zipresp:
with ZipFile(BytesIO(zipresp.read())) as zfile:
zfile.extractall(tempfile.gettempdir())

return folder

def spawn_container(self,
image: str,
env: Dict[str, str] = {}) -> int:
Expand All @@ -163,11 +174,24 @@ def spawn_container(self,
# TODO: Mount library in docker container
# self._download_azure_functions()

# Download python extension base package
ext_folder = self._download_extensions()

container_worker_path = (
f"/azure-functions-host/workers/python/{self._py_version}/"
"LINUX/X64/azure_functions_worker"
)

base_ext_container_path = (
f"/azure-functions-host/workers/python/{self._py_version}/"
"LINUX/X64/azurefunctions/extensions/base"
)

base_ext_local_path = (
f'{ext_folder}/azure-functions-python'
'-extensions-dev/azurefunctions-extensions-base'
'/azurefunctions/extensions/base'
)
run_cmd = []
run_cmd.extend([self._docker_cmd, "run", "-p", "0:80", "-d"])
run_cmd.extend(["--name", self._uuid, "--privileged"])
Expand All @@ -177,6 +201,8 @@ def spawn_container(self,
run_cmd.extend(["-e", f"CONTAINER_ENCRYPTION_KEY={_DUMMY_CONT_KEY}"])
run_cmd.extend(["-e", "WEBSITE_PLACEHOLDER_MODE=1"])
run_cmd.extend(["-v", f'{worker_path}:{container_worker_path}'])
run_cmd.extend(["-v",
f'{base_ext_local_path}:{base_ext_container_path}'])

for key, value in env.items():
run_cmd.extend(["-e", f"{key}={value}"])
Expand Down
Loading