molecule test always destroys the instances even if the test fails

Created on 23 Jan 2018  路  4Comments  路  Source: ansible-community/molecule

Issue Type

  • Bug report

Molecule and Ansible details

ansible 2.4.2.0
molecule 2.7.0
  • Molecule installation method: pip
  • Ansible installation method: pip

Desired Behaviour

If an error occurs during any of the "molecule test" steps, molecule should stop and not destroy the instances, allowing to debug what happened.
This was the behaviour in v1.

Actual Behaviour (Bug report only)

molecule always destroys the instances even if something failed:

    tests/test_default.py ....F                                              [100%]

    =================================== FAILURES ===================================
    ____________ test_fails[ansible://ics-ans-role-oracle-jdk-default] _____________

    host = <testinfra.host.Host object at 0x10abc98d0>

        def test_fails(host):
    >       assert False
    E       assert False

    tests/test_default.py:35: AssertionError
    ===================== 1 failed, 4 passed in 12.96 seconds ======================
An error occured during the test sequence.  Cleaning up.
--> Scenario: 'default'
--> Action: 'destroy'

    PLAY [Destroy] *****************************************************************

    TASK [Destroy molecule instance(s)] ********************************************
    ok: [localhost] => (item=None)

    TASK [Wait for instance(s) deletion to complete] *******************************
    ok: [localhost] => (item=None)

    PLAY RECAP *********************************************************************
    localhost                  : ok=2    changed=2    unreachable=0    failed=0

This was introduced by https://github.com/metacloud/molecule/pull/1086

Most helpful comment

The destroy strategy is designed for CI. You either want to destroy or you don't. Most CI you are not going to login to see what happened.

If you are wanting this behavior for your local development workflow, I would change your development workflow.

You should be running molecule converge as you develop the role, bug fix, or add features. Once you are happy with your role, you can then run molecule test --destroy=never in case you get an error. At this point your role should be complete, and you deliver it to CI.

Having the instances hang around at this point is moot in the eyes of molecule v2.

All 4 comments

This is intended. If you wish for this not to happen run molecule test --destroy=never.

Yes, but that would not give me what I want if no error is raised.
What I'd like (same as in molecule v1) is the same command to:

  • destroy the instances at the end if everything went fine
  • stop and don't destroy the instances if something failed

Is there a way to do that with molecule v2?

The destroy strategy is designed for CI. You either want to destroy or you don't. Most CI you are not going to login to see what happened.

If you are wanting this behavior for your local development workflow, I would change your development workflow.

You should be running molecule converge as you develop the role, bug fix, or add features. Once you are happy with your role, you can then run molecule test --destroy=never in case you get an error. At this point your role should be complete, and you deliver it to CI.

Having the instances hang around at this point is moot in the eyes of molecule v2.

Fair enough. I see your point.
Thanks for the quick feedback.

Was this page helpful?
0 / 5 - 0 ratings