Skip to content
Browse files

Add tests for sagemaker and lambda deployments (#357)

* move archive related funcs out of deployment dir

* add tests for sagemaker deployment

* add test for sagemaker apply operation

* correct typo

* add lambda tests

* update sagemaker tests for get arn roles and cleanup unit tests

* update test for ensure docker exists

* use load module to test handler generator

* make sure handle correct subprocess error for py2.7


* dont expose FileNotFoundError for py2.7

* add test for aws lambda apply

* make sure use string for localpath

* add testing for serverless utils

* update deployment utils test

* add moto and create sagemaker moto mock

* add moto mock for sagemaker

* use correct wrapper

* add test for apply create model failed

* remove extra test

* fix sagemaker error message issue

* Update

* add test for describe lambda

* make sure include region

* include region for aws ecr client

* fix test for python2

* update base on comments

* add comment for moving import to inside func

* fix tests

* fix

* update base on commit and formatting

* remove unused check
  • Loading branch information...
yubozhao authored and parano committed Nov 8, 2019
1 parent 263daa7 commit 851bac47f89033939f51d89dd476b2d0951b92bb
@@ -20,7 +20,6 @@
import stat
import logging

from bentoml.deployment.utils import add_local_bentoml_package_to_repo
from bentoml.exceptions import BentoMLException
from bentoml.archive.py_module_utils import copy_used_py_modules
from bentoml.archive.templates import (
@@ -31,6 +30,7 @@
from bentoml.archive.utils import add_local_bentoml_package_to_repo
from bentoml.utils import _is_bentoml_in_develop_mode
from bentoml.utils.usage_stats import track_save
from bentoml.archive.config import BentoArchiveConfig
@@ -0,0 +1,60 @@
# Copyright 2019 Atalaya Tech, Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at


# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import shutil
import importlib
from setuptools import sandbox

def _find_bentoml_module_location():
module_location, = importlib.util.find_spec(
except AttributeError:
# python 2.7 doesn't have importlib.util, will fall back to imp instead
import imp

_, module_location, _ = imp.find_module('bentoml')
return module_location

def add_local_bentoml_package_to_repo(archive_path):
module_location = _find_bentoml_module_location()
bentoml_setup_py = os.path.abspath(os.path.join(module_location, '..', ''))

assert os.path.isfile(bentoml_setup_py), '"" for Bentoml module not found'

# Create tmp directory inside bentoml module for storing the bundled
# targz file. Since dist-dir can only be inside of the module directory
bundle_dir_name = '__bento_dev_tmp'
source_dir = os.path.abspath(os.path.join(module_location, '..', bundle_dir_name))
if os.path.isdir(source_dir):
shutil.rmtree(source_dir, ignore_errors=True)

bentoml_setup_py, ['sdist', '--format', 'gztar', '--dist-dir', bundle_dir_name]

# copy the generated targz to archive directory and remove it from
# bentoml module directory
dest_dir = os.path.join(archive_path, 'bundled_pip_dependencies')
shutil.copytree(source_dir, dest_dir)

0 comments on commit 851bac4

Please sign in to comment.
You can’t perform that action at this time.