Skip to content

Fixing dependency isolation tests for linux consumption #1005

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 3 commits into from
Apr 19, 2022
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
18 changes: 18 additions & 0 deletions azure_functions_worker/testutils_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,26 @@ def _find_latest_mesh_image(cls,
f' Status {response.status_code}')

tag_list = response.json().get('tags', [])
# Removing images with a -upgrade. Upgrade images were temporary
# images used to onboard customers from a previous version. These
# images are no longer used.
tag_list = [x.strip("-upgrade") for x in tag_list]
version = list(filter(regex.match, tag_list))[-1]

image_tag = f'{_MESH_IMAGE_REPO}:{version}'
cls._mesh_images[host_major] = image_tag
return image_tag

def _delete_init_file_from_azure_dir(self):
init_file_path = f"/azure-functions-host/workers/python/" \
f"{self._py_version}/LINUX/X64/azure/__init__.py"
run_rm_cmd = [self._docker_cmd, "exec", self._uuid]
run_rm_cmd.extend(["rm", init_file_path])

subprocess.run(args=run_rm_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

@staticmethod
def _download_azure_functions() -> str:
with urlopen(_FUNC_GITHUB_ZIP) as zipresp:
Expand Down Expand Up @@ -181,11 +195,15 @@ def spawn_container(self,
run_process = subprocess.run(args=run_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

if run_process.returncode != 0:
raise RuntimeError('Failed to spawn docker container for'
f' {image} with uuid {self._uuid}.'
f' stderr: {run_process.stderr}')

# Remove once worker version 4.0.0 is released
self._delete_init_file_from_azure_dir()

# Wait for three seconds for the port to expose
time.sleep(3)

Expand Down
3 changes: 3 additions & 0 deletions tests/endtoend/test_dependency_isolation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT License.
import os
import importlib.util
from unittest import skip
from unittest.case import skipIf
from unittest.mock import patch

Expand Down Expand Up @@ -128,6 +129,7 @@ def test_loading_libraries_from_customers_package(self):
)


@skip("Skipping dependency isolation test for dedicated. Needs investigation")
class TestOlderVersionOfAzFuncDependencyIsolationOnDedicated(
testutils.WebHostTestCase):
"""Test the dependency manager E2E scenario via Http Trigger.
Expand Down Expand Up @@ -176,6 +178,7 @@ def test_loading_libraries_from_customers_package(self):
self.expected_azfunc_version, libraries['func.version'])


@skip("Skipping dependency isolation test for dedicated. Needs investigation")
class TestNewerVersionOfAzFuncDependencyIsolationOnDedicated(
testutils.WebHostTestCase):
"""Test the dependency manager E2E scenario via Http Trigger.
Expand Down
21 changes: 12 additions & 9 deletions tests/endtoend/test_linux_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import sys
from unittest import TestCase, skipIf

from requests import Request

from azure_functions_worker.testutils_lc import (
LinuxConsumptionWebHostController
)
from azure_functions_worker.utils.common import is_python_version
from requests import Request

_DEFAULT_HOST_VERSION = "3"

Expand Down Expand Up @@ -112,14 +113,15 @@ def test_new_protobuf(self):
})
req = Request('GET', f'{ctrl.url}/api/HttpTrigger')
resp = ctrl.send_request(req)
self.assertEqual(resp.status_code, 200)

content = resp.json()

# Worker always picks up the SDK version bundled with the image
# Version of the packages are inconsistent due to isolation's bug
self.assertIn('azure.functions', content)
self.assertIn('google.protobuf', content)
self.assertIn('grpc', content)
self.assertEqual(resp.status_code, 200)
self.assertEqual(content['azure.functions'], '1.7.0')
self.assertEqual(content['google.protobuf'], '3.15.8')
self.assertEqual(content['grpc'], '1.33.2')

def test_old_protobuf(self):
"""A function app with the following requirements.txt:
Expand All @@ -138,14 +140,15 @@ def test_old_protobuf(self):
})
req = Request('GET', f'{ctrl.url}/api/HttpTrigger')
resp = ctrl.send_request(req)
self.assertEqual(resp.status_code, 200)

content = resp.json()

# Worker always picks up the SDK version bundled with the image
# Version of the packages are inconsistent due to isolation's bug
self.assertIn('azure.functions', content)
self.assertIn('google.protobuf', content)
self.assertIn('grpc', content)
self.assertEqual(resp.status_code, 200)
self.assertIn(content['azure.functions'], '1.5.0')
self.assertIn(content['google.protobuf'], '3.8.0')
self.assertIn(content['grpc'], '1.27.1')

def test_debug_logging_disabled(self):
"""An HttpTrigger function app with 'azure-functions' library
Expand Down