-
Notifications
You must be signed in to change notification settings - Fork 31
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
Ideas for skipping cleanup on error? #41
Comments
For now, since we always run apply/destroy in our current usage, I'm gonna use |
I was going to suggest that. If you get a better idea let's see if it can be implemented. |
I'm not super familiar with the |
We wrap the setup apply and destroy in a fixture: @pytest.fixture(scope='module')
def output(scenarios_dir, tf_vars, scenario):
print(f'Setup starting for {scenario}')
tf = tftest.TerraformTest(scenario, scenarios_dir)
tf.setup()
try:
tf.apply(tf_vars=tf_vars)
print(f'setup complete for {scenario}')
yield tf.output()
tf.destroy(**{'auto_approve': True}, tf_vars=tf_vars)
except Exception as exc:
print(f'Issue during apply, attempting to clean up {exc}')
tf.destroy(**{'auto_approve': True}, tf_vars=tf_vars) It isn't perfect, but effectively puts a retry on destroy if a transient error occurs. |
Ach, completely forgot to answer this, sorry! @grahamhar I'm struggling to understand your solution (my fault ofc): IMHO a simple way of avoiding the above is of course to pass |
@ludoo Sorry I probably should have provided more explanation, let me provide a few examples of how I think the approach I suggested helps.
I agree it is probably a good idea to set cleanup_on_exit to False. |
@grahamhar With that config, what does pytest report if the apply succeeds, the first destroy fails, and the second destroy succeeds? Is it still a test pass (I would think so...)? |
Yes you get a test pass which in our use case is what we want. If that is not what you want add a pytest.fail to the except block |
Just ran an apply/destroy cycle through tftest, where on destroy I ran into a timing error when waiting for a resource to change to the expected state:
Ok, not great, but no big deal, just go into the test directory and re-run destroy... Except, the tfstate file is gone, so can't do that!
The text was updated successfully, but these errors were encountered: