Commit Graph

1 Commits

Author SHA1 Message Date
Rahul Bodduna e7e8f2eaf5
Check sns topic permission at start of buildafi and warn user (#754)
Rather than exiting with a unhandled exception when SNS-related permissions failures happen at the end of buildafi, check whether the topic exists (or can be created) early in buildafi and warn the user that the script will be unable to send email (and log the details of the exception) but continue to finish buildafi because failure in sending the notification probably should not be a fatal error for the manager.

This PR also introduces pytest driven unit tests for the firesim manager. The tests make use of moto to mock the backend of boto and prevent tests from actually calling out to AWS API's. They also utilize unittest.mock and botocore.stub.Stubber to inject desired testing stimulus to the code under test.

Adding two tests for the new awstools.get_snsname_arn() function.

To run them:
* make sure you have the new deps in machine-launch-script.sh
* cd deploy
* pytest

Useful primers on pytest & testing AWS:
* https://tensoriot.medium.com/unit-testing-with-pytest-and-moto-e94fc2eefe7a
* https://github.com/boto/boto3/issues/2485

Useful primer on unittest.mock (fka py-mock, not to be confused with pymock):
* https://www.fugue.co/blog/2016-02-11-python-mocking-101

'mock' became part of the stdlib in python 3.3 and was backported to 2.7
as 'py-mock'.  Of course, python being python, there is also a pymock
and that's totally different.

Detailed walkthrough of credential protection while using moto:
* https://blog.codecentric.de/en/2020/01/testing-aws-python-code-with-moto/


* [ci] Add manager pytests

* [ci] Provide aws credentials for pytest

* [ci] Remove AWS creds registration, andt push  use conftest to provide a region


Co-authored-by: Tim Snyder <snyder.tim@gmail.com>
Co-authored-by: Tim Snyder <timothy.snyder@sifive.com>
Co-authored-by: David Biancolin <david.biancolin@gmail.com>
2021-05-12 18:05:42 -05:00