Skip to content

Commit

Permalink
test: Mount base extension to fix consumption test failures (#1470)
Browse files Browse the repository at this point in the history
* Mount base extension to fix consumption test failures

* style

* feedback
  • Loading branch information
YunchuWang authored Apr 10, 2024
1 parent cb9de58 commit 0f8c67d
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit 0f8c67d

Please sign in to comment.