Skip to content
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

Catch config upload validation errors #2211

Merged
merged 13 commits into from
Oct 8, 2024

Conversation

craddm
Copy link
Contributor

@craddm craddm commented Sep 30, 2024

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).

🚦 Depends on

⤴️ Summary

Catches an exception when trying to upload an invalid config file and exits cleanly. Also improves the related error message to make it clearer what the validation error is.

Original error message:
image

Catches the error cleanly and yields a clearer error message
image

🌂 Related issues

Closes #2210

🔬 Tests

Tested locally

@craddm craddm requested a review from a team as a code owner September 30, 2024 10:22
@craddm craddm changed the title Catch config upload validation errors [WIP] Catch config upload validation errors Sep 30, 2024
Copy link

github-actions bot commented Sep 30, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/commands
  config.py
Project Total  

This report was generated by python-coverage-comment-action

@JimMadge JimMadge changed the title [WIP] Catch config upload validation errors Catch config upload validation errors Sep 30, 2024
Copy link
Member

@JimMadge JimMadge left a comment

Choose a reason for hiding this comment

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

Looks good. I think the output here is clearer than before.

@craddm we could also add a couple of tests here

  1. To ensure a config problem give the human-friendly error
  2. To check the format of the exception in yaml_serialisable_model.py

tests/conftest.py Outdated Show resolved Hide resolved
@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

Looks like a test is trying to use az CLI. Maybe a missing mock fixture.

@craddm
Copy link
Contributor Author

craddm commented Oct 8, 2024

Looks like a test is trying to use az CLI. Maybe a missing mock fixture.

Yes - odd as it was working before we changed things today, and the only thing we changed which touches this test is how the yaml with the missing field is made.

@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

Might be due to a change on develop that was merged in?

@craddm
Copy link
Contributor Author

craddm commented Oct 8, 2024

Might be due to a change on develop that was merged in?

Nope - just tested it out. It works fine if I revert the change in how sre_config_yaml_missing_field is made. Can't understand why!

@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

Hmm 🤔 something about how the sre_config_yaml fixture is constructed?

@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

Or, the change from missing value to missing field has changed what is happening underneath?

@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

In any case, you should be able to follow the traceback (or code) to find out what is happening.

@craddm
Copy link
Contributor Author

craddm commented Oct 8, 2024

We just weren't doing it correctly, so the yaml wasn't actually invalid and the upload function was progressing to the point where it needed to be logged in. The validation errors happen before that point, so it isn't necessary to do extra mocks to cope with logins etc.

@JimMadge
Copy link
Member

JimMadge commented Oct 8, 2024

Oh, that is brilliant. We were too good at not writing bad YAML 😆.

@JimMadge JimMadge merged commit 567d30e into alan-turing-institute:develop Oct 8, 2024
10 of 11 checks passed
@craddm craddm deleted the config-upload-errors branch October 8, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traceback from validation error when uploading an SRE config
2 participants