Skip to content

change: clean up git support integ tests #1032

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
Sep 9, 2019
Merged
Changes from 2 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
65 changes: 17 additions & 48 deletions tests/integ/test_git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
Expand All @@ -24,7 +24,6 @@
from sagemaker.pytorch.defaults import PYTORCH_VERSION
from sagemaker.pytorch.estimator import PyTorch
from sagemaker.sklearn.estimator import SKLearn
from sagemaker.mxnet.model import MXNetModel
from sagemaker.sklearn.model import SKLearnModel
from tests.integ import DATA_DIR, PYTHON_VERSION

Expand All @@ -33,29 +32,27 @@
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
BRANCH = "test-branch-git-config"
COMMIT = "ae15c9d7d5b97ea95ea451e4662ee43da3401d73"

PRIVATE_GIT_REPO = "https://github.com/git-support-test/test-git.git"
PRIVATE_BRANCH = "master"
PRIVATE_COMMIT = "a46d6f9add3532ca3e4e231e4108b6bad15b7373"

PRIVATE_GIT_REPO_2FA = "https://github.com/git-support-test-2fa/test-git.git"
PRIVATE_GIT_REPO_2FA_SSH = "[email protected]:git-support-test-2fa/test-git.git"
PRIVATE_BRANCH_2FA = "master"
PRIVATE_COMMIT_2FA = "52381dee030eb332a7e42d9992878d7261eb21d4"

CODECOMMIT_REPO = (
"https://git-codecommit.us-west-2.amazonaws.com/v1/repos/sagemaker-python-sdk-git-testing-repo/"
)
CODECOMMIT_BRANCH = "master"

# Since personal access tokens will delete themselves if they are committed to GitHub repos,
# we cannot hard code them here, but have to encrypt instead
ENCRYPTED_PRIVATE_REPO_TOKEN = "e-4_1-1dc_71-f0e_f7b54a0f3b7db2757163da7b5e8c3"
PRIVATE_REPO_TOKEN = ENCRYPTED_PRIVATE_REPO_TOKEN.replace("-", "").replace("_", "")

# endpoint tests all use the same port, so we use this lock to prevent concurrent execution
LOCK_PATH = os.path.join(tempfile.gettempdir(), "sagemaker_test_git_lock")


@pytest.mark.local_mode
def test_git_support_with_pytorch(sagemaker_local_session):
def test_github(sagemaker_local_session):
script_path = "mnist.py"
data_path = os.path.join(DATA_DIR, "pytorch_mnist")
git_config = {"repo": GIT_REPO, "branch": BRANCH, "commit": COMMIT}
Expand Down Expand Up @@ -85,7 +82,7 @@ def test_git_support_with_pytorch(sagemaker_local_session):

@pytest.mark.local_mode
@pytest.mark.skip("needs a secure authentication approach")
def test_git_support_with_mxnet(sagemaker_local_session):
def test_private_github(sagemaker_local_session):
script_path = "mnist.py"
data_path = os.path.join(DATA_DIR, "mxnet_mnist")
git_config = {
Expand All @@ -94,7 +91,7 @@ def test_git_support_with_mxnet(sagemaker_local_session):
"commit": PRIVATE_COMMIT,
"2FA_enabled": False,
"username": "git-support-test",
"password": "", # TODO: find a more secure approach
"password": "", # TODO: find a secure approach
}
source_dir = "mxnet"
dependencies = ["foo/bar.py"]
Expand Down Expand Up @@ -126,46 +123,33 @@ def test_git_support_with_mxnet(sagemaker_local_session):
with lock.lock(LOCK_PATH):
try:
serving_script_path = "mnist_hosting_with_custom_handlers.py"
client = sagemaker_local_session.sagemaker_client
desc = client.describe_training_job(TrainingJobName=mx.latest_training_job.name)
model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
model = MXNetModel(
model_data,
"SageMakerRole",
entry_point=serving_script_path,
source_dir=source_dir,
dependencies=dependencies,
py_version=PYTHON_VERSION,
sagemaker_session=sagemaker_local_session,
framework_version=MXNet.LATEST_VERSION,
git_config=git_config,
)
predictor = model.deploy(initial_instance_count=1, instance_type="local")
predictor = mx.deploy(1, "local", entry_point=serving_script_path)

data = numpy.zeros(shape=(1, 1, 28, 28))
result = predictor.predict(data)
assert result is not None
finally:
predictor.delete_endpoint()


@pytest.mark.skipif(PYTHON_VERSION != "py3", reason="Scikit-learn image supports only python 3.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this here but commented out?
Otherwise, if the tribal knowledge is lost, the dev that looks into fixing this might be confused, and may not think to look at git logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave a comment in the code. I don't want to leave a commented-out annotation, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me =)

@pytest.mark.local_mode
def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version):
@pytest.mark.skip("needs a secure authentication approach")
def test_private_github_with_2fa(sagemaker_local_session, sklearn_full_version):
script_path = "mnist.py"
data_path = os.path.join(DATA_DIR, "sklearn_mnist")
git_config = {
"repo": PRIVATE_GIT_REPO_2FA,
"branch": PRIVATE_BRANCH_2FA,
"commit": PRIVATE_COMMIT_2FA,
"2FA_enabled": True,
"token": PRIVATE_REPO_TOKEN,
"token": "", # TODO: find a secure approach
}
source_dir = "sklearn"
sklearn = SKLearn(
entry_point=script_path,
role="SageMakerRole",
source_dir=source_dir,
py_version=PYTHON_VERSION,
py_version="py3",
train_instance_count=1,
train_instance_type="local",
sagemaker_session=sagemaker_local_session,
Expand Down Expand Up @@ -202,9 +186,7 @@ def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version)


@pytest.mark.local_mode
def test_git_support_with_sklearn_ssh_passphrase_not_configured(
sagemaker_local_session, sklearn_full_version
):
def test_github_with_ssh_passphrase_not_configured(sagemaker_local_session, sklearn_full_version):
script_path = "mnist.py"
data_path = os.path.join(DATA_DIR, "sklearn_mnist")
git_config = {
Expand All @@ -227,14 +209,15 @@ def test_git_support_with_sklearn_ssh_passphrase_not_configured(
)
train_input = "file://" + os.path.join(data_path, "train")
test_input = "file://" + os.path.join(data_path, "test")

with pytest.raises(subprocess.CalledProcessError) as error:
sklearn.fit({"train": train_input, "test": test_input})
assert "returned non-zero exit status" in str(error)


@pytest.mark.local_mode
@pytest.mark.skip("needs a secure authentication approach")
def test_git_support_codecommit_with_mxnet(sagemaker_local_session):
def test_codecommit(sagemaker_local_session):
script_path = "mnist.py"
data_path = os.path.join(DATA_DIR, "mxnet_mnist")
git_config = {
Expand Down Expand Up @@ -272,21 +255,7 @@ def test_git_support_codecommit_with_mxnet(sagemaker_local_session):

with lock.lock(LOCK_PATH):
try:
client = sagemaker_local_session.sagemaker_client
desc = client.describe_training_job(TrainingJobName=mx.latest_training_job.name)
model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
model = MXNetModel(
model_data,
"SageMakerRole",
entry_point=script_path,
source_dir=source_dir,
dependencies=dependencies,
py_version=PYTHON_VERSION,
sagemaker_session=sagemaker_local_session,
framework_version=MXNet.LATEST_VERSION,
git_config=git_config,
)
predictor = model.deploy(1, "local")
predictor = mx.deploy(1, "local")

data = numpy.zeros(shape=(1, 1, 28, 28))
result = predictor.predict(data)
Expand Down