sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

fix: local mode deletion of temp files on job end

Open jmahlik opened this issue 2 years ago • 4 comments

Issue #, if available: closes #2527

This is a clone of https://github.com/aws/sagemaker-python-sdk/pull/2644 but has allow commits from maintainers on so should be easier to merge.

Description of changes:

Add try except around file cleanup in sagemaker.local.utils.copy_directory_structure. This was causing local mode to fail when docker (running as root) writes files to a mounted dir and the user does not have permission to remove the files.

The same pattern is followed here.

Testing done:

Add test for failed removal, behaves as expected.

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • [x] I have read the CONTRIBUTING doc
  • [x] I certify that the changes I am introducing will be backword compatible, and I have discussed concerns about this, if any, with the Python SDK team
  • [x] I used the commit message format described in CONTRIBUTING
  • [x] I have passed the region in to all S3 and STS clients that I've initialized as part of this change.
  • [x] I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • [x] I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • [x] I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes
  • [x] I have checked that my tests are not configured for a specific region or account (if appropriate)
  • [x] I have used unique_name_from_base to create resource names in integ tests (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

jmahlik avatar Mar 22 '22 03:03 jmahlik

Codecov Report

Merging #3017 (aa5d3b2) into master (11ff7c0) will decrease coverage by 0.81%. The diff coverage is 80.00%.

@@            Coverage Diff             @@
##           master    #3017      +/-   ##
==========================================
- Coverage   89.55%   88.75%   -0.81%     
==========================================
  Files         960      226     -734     
  Lines       88796    21967   -66829     
==========================================
- Hits        79523    19497   -60026     
+ Misses       9273     2470    -6803     
Impacted Files Coverage Δ
src/sagemaker/local/utils.py 93.33% <80.00%> (ø)
...thon3.8/site-packages/sagemaker/hyperparameters.py
...n3.7/site-packages/sagemaker/lineage/_api_types.py
...n3.9/site-packages/sagemaker/sklearn/processing.py
...agemaker/cli/compatibility/v2/modifiers/airflow.py
...hon3.9/site-packages/sagemaker/xgboost/__init__.py
...3.9/site-packages/sagemaker/wrangler/processing.py
.../lib/python3.10/site-packages/sagemaker/clarify.py
...s/sagemaker/workflow/pipeline_experiment_config.py
...te-packages/sagemaker/workflow/step_collections.py
... and 1177 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Mar 22 '22 04:03 codecov-commenter

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 2ea19d8f27e33d4aaeb2dc4e97a7daff30e7fa19
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Mar 22 '22 04:03 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 2ea19d8f27e33d4aaeb2dc4e97a7daff30e7fa19
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Mar 22 '22 05:03 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-slow-tests
  • Commit ID: 2ea19d8f27e33d4aaeb2dc4e97a7daff30e7fa19
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Mar 22 '22 06:03 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 2ea19d8f27e33d4aaeb2dc4e97a7daff30e7fa19
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Oct 26 '22 23:10 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 2ea19d8f27e33d4aaeb2dc4e97a7daff30e7fa19
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Oct 26 '22 23:10 sagemaker-bot

@jmahlik Thanks for your contribution. Can you please update your PR and resolve conflicts.

My hard disk failed recently so I have to set up a new vm. It might take a bit. Open to you editing or cherry picking this in the meantime if you'd like? It should be open. Been trying to get this merged since September 2021.

jmahlik avatar Dec 06 '22 14:12 jmahlik

@jmahlik Thanks for your contribution. Can you please update your PR and resolve conflicts.

@navinsoni rebased

jmahlik avatar Dec 14 '22 04:12 jmahlik

@jmahlik I have approved the PR. I will merge it as soon as all tests pass.

navinsoni avatar Dec 15 '22 21:12 navinsoni

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 21:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 21:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-pr
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 21:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 22:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-slow-tests
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 22:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 66fdd51444cf4d366e6b4dc16a7999ba1737a0bb
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 15 '22 22:12 sagemaker-bot

@jmahlik Can you please fix unit-tests. it's failing for flake8 and black. You can test it locally by running tox -e flake8,pylint,docstyle,black-check,twine

navinsoni avatar Dec 15 '22 22:12 navinsoni

Yes will do. I ran black and it tried to re-format the entire repo so something must be off locally.

jmahlik avatar Dec 15 '22 23:12 jmahlik

Ok should be fixed now. I forgot to push this.

diff --git a/tests/unit/sagemaker/local/test_local_utils.py b/tests/unit/sagemaker/local/test_local_utils.py
index ab8d556d..59caa5f0 100644
--- a/tests/unit/sagemaker/local/test_local_utils.py
+++ b/tests/unit/sagemaker/local/test_local_utils.py
@@ -165,6 +165,7 @@ def test_get_using_dot_notation_key_error():

 def test_get_using_dot_notation_index_error():
     with pytest.raises(ValueError):
+        sagemaker.local.utils.get_using_dot_notation({"foo": ["bar"]}, "foo[1]")

jmahlik avatar Dec 15 '22 23:12 jmahlik

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 16 '22 01:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 16 '22 01:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-pr
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 16 '22 01:12 sagemaker-bot

Docs looks like it fails fetching jumpstart tables from s3

jmahlik avatar Dec 16 '22 01:12 jmahlik

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 16 '22 02:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-slow-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 16 '22 03:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-slow-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 19 '22 19:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 6a3cea9e116546399bd5c68a037fc919d44e3c91
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Dec 19 '22 19:12 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: aa5d3b26be55a81438724f0e8bac3706650bbe2d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Jan 05 '23 23:01 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: aa5d3b26be55a81438724f0e8bac3706650bbe2d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Jan 05 '23 23:01 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-pr
  • Commit ID: aa5d3b26be55a81438724f0e8bac3706650bbe2d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Jan 05 '23 23:01 sagemaker-bot

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: aa5d3b26be55a81438724f0e8bac3706650bbe2d
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

sagemaker-bot avatar Jan 05 '23 23:01 sagemaker-bot