Skip to content

Commit 697732b

Browse files
authored
change: clean up git support integ tests (#1032)
1 parent 0e341ee commit 697732b

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

tests/integ/test_git.py

+20-49
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -24,7 +24,6 @@
2424
from sagemaker.pytorch.defaults import PYTORCH_VERSION
2525
from sagemaker.pytorch.estimator import PyTorch
2626
from sagemaker.sklearn.estimator import SKLearn
27-
from sagemaker.mxnet.model import MXNetModel
2827
from sagemaker.sklearn.model import SKLearnModel
2928
from tests.integ import DATA_DIR, PYTHON_VERSION
3029

@@ -33,29 +32,27 @@
3332
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
3433
BRANCH = "test-branch-git-config"
3534
COMMIT = "ae15c9d7d5b97ea95ea451e4662ee43da3401d73"
35+
3636
PRIVATE_GIT_REPO = "https://github.com/git-support-test/test-git.git"
3737
PRIVATE_BRANCH = "master"
3838
PRIVATE_COMMIT = "a46d6f9add3532ca3e4e231e4108b6bad15b7373"
39+
3940
PRIVATE_GIT_REPO_2FA = "https://github.com/git-support-test-2fa/test-git.git"
4041
PRIVATE_GIT_REPO_2FA_SSH = "[email protected]:git-support-test-2fa/test-git.git"
4142
PRIVATE_BRANCH_2FA = "master"
4243
PRIVATE_COMMIT_2FA = "52381dee030eb332a7e42d9992878d7261eb21d4"
44+
4345
CODECOMMIT_REPO = (
4446
"https://git-codecommit.us-west-2.amazonaws.com/v1/repos/sagemaker-python-sdk-git-testing-repo/"
4547
)
4648
CODECOMMIT_BRANCH = "master"
4749

48-
# Since personal access tokens will delete themselves if they are committed to GitHub repos,
49-
# we cannot hard code them here, but have to encrypt instead
50-
ENCRYPTED_PRIVATE_REPO_TOKEN = "e-4_1-1dc_71-f0e_f7b54a0f3b7db2757163da7b5e8c3"
51-
PRIVATE_REPO_TOKEN = ENCRYPTED_PRIVATE_REPO_TOKEN.replace("-", "").replace("_", "")
52-
5350
# endpoint tests all use the same port, so we use this lock to prevent concurrent execution
5451
LOCK_PATH = os.path.join(tempfile.gettempdir(), "sagemaker_test_git_lock")
5552

5653

5754
@pytest.mark.local_mode
58-
def test_git_support_with_pytorch(sagemaker_local_session):
55+
def test_github(sagemaker_local_session):
5956
script_path = "mnist.py"
6057
data_path = os.path.join(DATA_DIR, "pytorch_mnist")
6158
git_config = {"repo": GIT_REPO, "branch": BRANCH, "commit": COMMIT}
@@ -85,7 +82,7 @@ def test_git_support_with_pytorch(sagemaker_local_session):
8582

8683
@pytest.mark.local_mode
8784
@pytest.mark.skip("needs a secure authentication approach")
88-
def test_git_support_with_mxnet(sagemaker_local_session):
85+
def test_private_github(sagemaker_local_session):
8986
script_path = "mnist.py"
9087
data_path = os.path.join(DATA_DIR, "mxnet_mnist")
9188
git_config = {
@@ -94,7 +91,7 @@ def test_git_support_with_mxnet(sagemaker_local_session):
9491
"commit": PRIVATE_COMMIT,
9592
"2FA_enabled": False,
9693
"username": "git-support-test",
97-
"password": "", # TODO: find a more secure approach
94+
"password": "", # TODO: find a secure approach
9895
}
9996
source_dir = "mxnet"
10097
dependencies = ["foo/bar.py"]
@@ -126,46 +123,34 @@ def test_git_support_with_mxnet(sagemaker_local_session):
126123
with lock.lock(LOCK_PATH):
127124
try:
128125
serving_script_path = "mnist_hosting_with_custom_handlers.py"
129-
client = sagemaker_local_session.sagemaker_client
130-
desc = client.describe_training_job(TrainingJobName=mx.latest_training_job.name)
131-
model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
132-
model = MXNetModel(
133-
model_data,
134-
"SageMakerRole",
135-
entry_point=serving_script_path,
136-
source_dir=source_dir,
137-
dependencies=dependencies,
138-
py_version=PYTHON_VERSION,
139-
sagemaker_session=sagemaker_local_session,
140-
framework_version=MXNet.LATEST_VERSION,
141-
git_config=git_config,
142-
)
143-
predictor = model.deploy(initial_instance_count=1, instance_type="local")
126+
predictor = mx.deploy(1, "local", entry_point=serving_script_path)
127+
144128
data = numpy.zeros(shape=(1, 1, 28, 28))
145129
result = predictor.predict(data)
146130
assert result is not None
147131
finally:
148132
predictor.delete_endpoint()
149133

150134

151-
@pytest.mark.skipif(PYTHON_VERSION != "py3", reason="Scikit-learn image supports only python 3.")
152135
@pytest.mark.local_mode
153-
def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version):
136+
@pytest.mark.skip("needs a secure authentication approach")
137+
def test_private_github_with_2fa(sagemaker_local_session, sklearn_full_version):
154138
script_path = "mnist.py"
155139
data_path = os.path.join(DATA_DIR, "sklearn_mnist")
156140
git_config = {
157141
"repo": PRIVATE_GIT_REPO_2FA,
158142
"branch": PRIVATE_BRANCH_2FA,
159143
"commit": PRIVATE_COMMIT_2FA,
160144
"2FA_enabled": True,
161-
"token": PRIVATE_REPO_TOKEN,
145+
"token": "", # TODO: find a secure approach
162146
}
163147
source_dir = "sklearn"
148+
164149
sklearn = SKLearn(
165150
entry_point=script_path,
166151
role="SageMakerRole",
167152
source_dir=source_dir,
168-
py_version=PYTHON_VERSION,
153+
py_version="py3", # Scikit-learn supports only Python 3
169154
train_instance_count=1,
170155
train_instance_type="local",
171156
sagemaker_session=sagemaker_local_session,
@@ -202,9 +187,7 @@ def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version)
202187

203188

204189
@pytest.mark.local_mode
205-
def test_git_support_with_sklearn_ssh_passphrase_not_configured(
206-
sagemaker_local_session, sklearn_full_version
207-
):
190+
def test_github_with_ssh_passphrase_not_configured(sagemaker_local_session, sklearn_full_version):
208191
script_path = "mnist.py"
209192
data_path = os.path.join(DATA_DIR, "sklearn_mnist")
210193
git_config = {
@@ -213,11 +196,12 @@ def test_git_support_with_sklearn_ssh_passphrase_not_configured(
213196
"commit": PRIVATE_COMMIT_2FA,
214197
}
215198
source_dir = "sklearn"
199+
216200
sklearn = SKLearn(
217201
entry_point=script_path,
218202
role="SageMakerRole",
219203
source_dir=source_dir,
220-
py_version=PYTHON_VERSION,
204+
py_version="py3", # Scikit-learn supports only Python 3
221205
train_instance_count=1,
222206
train_instance_type="local",
223207
sagemaker_session=sagemaker_local_session,
@@ -227,14 +211,15 @@ def test_git_support_with_sklearn_ssh_passphrase_not_configured(
227211
)
228212
train_input = "file://" + os.path.join(data_path, "train")
229213
test_input = "file://" + os.path.join(data_path, "test")
214+
230215
with pytest.raises(subprocess.CalledProcessError) as error:
231216
sklearn.fit({"train": train_input, "test": test_input})
232217
assert "returned non-zero exit status" in str(error)
233218

234219

235220
@pytest.mark.local_mode
236221
@pytest.mark.skip("needs a secure authentication approach")
237-
def test_git_support_codecommit_with_mxnet(sagemaker_local_session):
222+
def test_codecommit(sagemaker_local_session):
238223
script_path = "mnist.py"
239224
data_path = os.path.join(DATA_DIR, "mxnet_mnist")
240225
git_config = {
@@ -272,21 +257,7 @@ def test_git_support_codecommit_with_mxnet(sagemaker_local_session):
272257

273258
with lock.lock(LOCK_PATH):
274259
try:
275-
client = sagemaker_local_session.sagemaker_client
276-
desc = client.describe_training_job(TrainingJobName=mx.latest_training_job.name)
277-
model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
278-
model = MXNetModel(
279-
model_data,
280-
"SageMakerRole",
281-
entry_point=script_path,
282-
source_dir=source_dir,
283-
dependencies=dependencies,
284-
py_version=PYTHON_VERSION,
285-
sagemaker_session=sagemaker_local_session,
286-
framework_version=MXNet.LATEST_VERSION,
287-
git_config=git_config,
288-
)
289-
predictor = model.deploy(1, "local")
260+
predictor = mx.deploy(1, "local")
290261

291262
data = numpy.zeros(shape=(1, 1, 28, 28))
292263
result = predictor.predict(data)

0 commit comments

Comments
 (0)