teemtee / tmt

Test Management Tool
MIT License
84 stars 125 forks source link

[feature request] Possibility to use ansible playbooks in finish step #919

Closed fernflower closed 2 years ago

fernflower commented 3 years ago

Complex setup cases (where ansible can be used in prepare step) sometimes require a non-trivial teardown, but unfortunately now only how: bash is allowed in finish step.

/tests/plans/integration/postupgrade/e2e/7to8sap
Unsupported finish method 'ansible' in the '/tests/plans/integration/postupgrade/e2e/7to8sap' plan.
lukaszachy commented 3 years ago

Naive solution would be to copy ansible.py to steps/finish. (similar to how shell.py is almost identical in finish and prepare steps)

lukaszachy commented 3 years ago

Went with naive way. @fernflower do you mind testing it? It should (tm) work but....

fernflower commented 3 years ago

@lukaszachy worked for me, instead of the error got a clean run. Thank you!

(.venv) [ivasilev@localhost plans]$ tmt run -a provision -h connect -g 10.0.137.67  plans --name 'answerfile'
/var/tmp/tmt/run-001

/tests/plans/integration/checkanswerfile/integration-checkanswerfile
    discover
        how: fmf
        directory: /home/ivasilev/projects/tmt-plans
        filter: tag: check-answerfile
        summary: 1 test selected
    provision
        how: connect
        guest: 10.0.137.67
        user: root
        key: not provided
        distro: Red Hat Enterprise Linux Server 7.9 (Maipo)
        summary: 1 guest provisioned
    prepare
        how: shell
        name: Install integration test framework dependencies
        overview: 1 script found
^C    finish
        how: ansible
        name: Run teardown
        playbook: ./tests/leapp-upgrade-test/tests/teardown.yml
        summary: 1 task completed

Aborted!

Checked that teardown was actually executed (excerpt from the log.txt)

14:19:33     finish
14:19:33         workdir: /var/tmp/tmt/run-001/tests/plans/integration/checkanswerfile/integration-checkanswerfile/finish
14:19:33         how: ansible
14:19:33         name: Run teardown
14:19:33         order: 50
14:19:33         playbook: ./tests/leapp-upgrade-test/tests/teardown.yml
14:19:33             Applying playbook './tests/leapp-upgrade-test/tests/teardown.yml' on guest '10.0.137.67'.
14:19:33             Playbook full path: '/home/ivasilev/projects/tmt-plans/./tests/leapp-upgrade-test/tests/teardown.yml'
14:19:33             Run command 'export DEBUG=1; stty cols 79; ansible-playbook --ssh-common-args="-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null"  -i root@10.0.137.67, /home/ivasilev/projects/tmt-plans/./tests/leapp-upgrade-test/tests/teardown.yml'.
14:19:33             environment: None
14:19:33             err: stty: 'standard input': Inappropriate ioctl for device
14:19:33             out: 
14:19:33             out: PLAY [all] *********************************************************************
14:19:33             out: 
14:19:43             out: TASK [Gathering Facts] *********************************************************
14:19:43             out: ok: [root@10.0.137.67]
14:19:43             out: 
14:19:43             out: TASK [teardown : Unsubscribe system] *******************************************
14:19:43             out: skipping: [root@10.0.137.67]
14:19:43             out: 
14:19:43             out: PLAY RECAP *********************************************************************
14:19:43             out: root@10.0.137.67           : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
14:19:43             out: 
14:19:43         ok: 1 task
14:19:43         skipped: 1 task
14:19:43             Doing nothing to stop guest '10.0.137.67'.
14:19:43             Doing nothing to remove guest '10.0.137.67'.
14:19:43         summary: 1 task completed
14:19:43         status: done