From bba030d5884cd5ecc99cc2e5a2ab2abc89caba1c Mon Sep 17 00:00:00 2001 From: peterstone2017 <12449837+YunchuWang@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:52:20 -0700 Subject: [PATCH 1/3] Mount base extension to fix consumption test failures --- tests/utils/testutils_lc.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/utils/testutils_lc.py b/tests/utils/testutils_lc.py index 10c5079a9..19c81f15d 100644 --- a/tests/utils/testutils_lc.py +++ b/tests/utils/testutils_lc.py @@ -32,7 +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: """A controller for spawning mesh Docker container and apply multiple @@ -151,6 +152,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(folder) + + return folder + def spawn_container(self, image: str, env: Dict[str, str] = {}) -> int: @@ -163,11 +173,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/azure/functions/extension/base" + ) + + base_ext_local_path = ( + f'{ext_folder}\\azure-functions-python' + f'-extensions-dev\\azure-functions-extension-base' + f'\\azure\\functions\\extension\\base' + ) run_cmd = [] run_cmd.extend([self._docker_cmd, "run", "-p", "0:80", "-d"]) run_cmd.extend(["--name", self._uuid, "--privileged"]) @@ -177,6 +200,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}"]) From e8373511dbb8e61fb55a6e54ae8db88101bcb7d3 Mon Sep 17 00:00:00 2001 From: peterstone2017 <12449837+YunchuWang@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:58:40 -0700 Subject: [PATCH 2/3] style --- tests/utils/testutils_lc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/utils/testutils_lc.py b/tests/utils/testutils_lc.py index 19c81f15d..84311a6c1 100644 --- a/tests/utils/testutils_lc.py +++ b/tests/utils/testutils_lc.py @@ -35,6 +35,7 @@ _EXTENSION_BASE_ZIP = 'https://github.com/Azure/azure-functions-python-' \ 'extensions/archive/refs/heads/dev.zip' + class LinuxConsumptionWebHostController: """A controller for spawning mesh Docker container and apply multiple test cases on it. From a9d9309eec5208a2fbad49aa5f3aea46fcd3cedc Mon Sep 17 00:00:00 2001 From: wangbill <12449837+YunchuWang@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:56:04 +0000 Subject: [PATCH 3/3] feedback --- tests/utils/testutils_lc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/utils/testutils_lc.py b/tests/utils/testutils_lc.py index 84311a6c1..0dfd473fb 100644 --- a/tests/utils/testutils_lc.py +++ b/tests/utils/testutils_lc.py @@ -158,7 +158,7 @@ def _download_extensions() -> str: folder = tempfile.gettempdir() with urlopen(_EXTENSION_BASE_ZIP) as zipresp: with ZipFile(BytesIO(zipresp.read())) as zfile: - zfile.extractall(folder) + zfile.extractall(tempfile.gettempdir()) return folder @@ -184,13 +184,13 @@ def spawn_container(self, base_ext_container_path = ( f"/azure-functions-host/workers/python/{self._py_version}/" - "LINUX/X64/azure/functions/extension/base" + "LINUX/X64/azurefunctions/extensions/base" ) base_ext_local_path = ( - f'{ext_folder}\\azure-functions-python' - f'-extensions-dev\\azure-functions-extension-base' - f'\\azure\\functions\\extension\\base' + 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"])