Skip to content

Commit

Permalink
[API] Ensure project on function deployment (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Aug 25, 2021
1 parent 5e1834f commit 33f59bb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions mlrun/api/api/endpoints/functions.py
Expand Up @@ -165,6 +165,12 @@ async def build_function(

logger.info(f"build_function:\n{data}")
function = data.get("function")
await run_in_threadpool(
mlrun.api.utils.singletons.project_member.get_project_member().ensure_project,
db_session,
function.get("metadata", {}).get("project", mlrun.mlconf.default_project),
auth_info=auth_verifier.auth_info,
)
await run_in_threadpool(
mlrun.api.utils.clients.opa.Client().query_project_resource_permissions,
mlrun.api.schemas.AuthorizationResourceTypes.function,
Expand Down
11 changes: 8 additions & 3 deletions tests/system/base.py
Expand Up @@ -46,9 +46,10 @@ def setup_method(self, method):
# it in mlconf.
mlconf.dbpath = self._test_env["MLRUN_DBPATH"]

set_environment(
artifact_path="/User/data", project=self.project_name,
)
if not self._skip_set_environment():
set_environment(
artifact_path="/User/data", project=self.project_name,
)

self.custom_setup()

Expand Down Expand Up @@ -85,6 +86,10 @@ def custom_setup(self):
def custom_teardown(self):
pass

@staticmethod
def _skip_set_environment():
return False

@classmethod
def skip_test_if_env_not_configured(cls, test):
mandatory_env_vars = (
Expand Down
2 changes: 1 addition & 1 deletion tests/system/projects/test_project.py
Expand Up @@ -33,7 +33,7 @@ def pipe_test():
# Marked as enterprise because of v3io mount and pipelines
@TestMLRunSystem.skip_test_if_env_not_configured
@pytest.mark.enterprise
class TestFeatureStore(TestMLRunSystem):
class TestProject(TestMLRunSystem):
def custom_setup(self):
pass

Expand Down
Empty file.
9 changes: 9 additions & 0 deletions tests/system/runtimes/assets/nuclio_function.py
@@ -0,0 +1,9 @@
def handler(context, event):
context.logger.info("Hello world")

return context.Response(
body="Hello, from nuclio :]",
headers={},
content_type="text/plain",
status_code=200,
)
27 changes: 27 additions & 0 deletions tests/system/runtimes/test_nuclio.py
@@ -0,0 +1,27 @@
import mlrun
import tests.system.base


@tests.system.base.TestMLRunSystem.skip_test_if_env_not_configured
class TestNuclioRuntime(tests.system.base.TestMLRunSystem):

project_name = "does-not-exist-3"

@staticmethod
def _skip_set_environment():
# Skip to make sure project ensured in Nuclio function deployment flow
return True

def test_deploy_function_without_project(self):
code_path = str(self.assets_path / "nuclio_function.py")

self._logger.debug("Creating nuclio function")
function = mlrun.code_to_function(
name="simple-function",
kind="nuclio",
project=self.project_name,
filename=code_path,
)

self._logger.debug("Deploying nuclio function")
function.deploy()

0 comments on commit 33f59bb

Please sign in to comment.