akondrahman / IaCTesting

Placeholder for the research study related to IaC testing anti-patterns
3 stars 256 forks source link

Assertion Roulette Behavior in Ansible 2.7 #23

Closed Talismanic closed 3 years ago

Talismanic commented 3 years ago

Dear @akondrahman Bhai, I have seen a different behavior of Ansible from 2.7. It does not require debug messages as mandatory parameter. If I put multiple asserts, ansible is showing which of the first assert failed and does not execute the rest of the assert cases. I have the following sample test script and output. Please let me know whether this finding should effect our research.

orange_test.yaml

- hosts: localhost
  vars:
    my_param: -5
  tasks:
     - name: Testing my_param
       assert:
         that:
           - my_param <= 100
           - my_param >= -3
           - my_param >= 0

This task will fail for both of the last two asserts. But when I have run this, I found below output:

PLAY [localhost] ********************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [localhost]

TASK [Testing my_param] *************************************************************************************************************************************
fatal: [localhost]: FAILED! => {
    "assertion": "my_param >= -3",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}
        to retry, use: --limit @/home/DABSP/ansible/playbooks/orange_test.retry

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

So, ansible did not run the last assert as the previous one failed. In my opinion, this is expected as ansible by design is not a test tool. Its a IaC tool. So to ansible, assertion 02 is an task which has failed, so it did not proceed for the next task. As we (practitioners) tend to exploit assertion module for testing, it will always bring problem. For example, we have to fix one by one to understand whether the next one will fail.

akondrahman commented 3 years ago

I think we do not need to change.

Sincerely, Akond Rahman Assistant Professor Department of Computer Science Tennessee Tech University Website: https://akondrahman.github.io

On Jan 12, 2021, at 10:23 PM, Mohammed Mehedi Hasan notifications@github.com wrote:

 Dear @akondrahman Bhai, I have seen a different behavior of Ansible from 2.7. It does not require debug messages as mandatory parameter. If I put multiple asserts, ansible is showing which of the first assert failed and do not execute the rest of the assert cases. I have the following sample test script and output. Please let me know whether this finding should effect our research.

orange_test.yaml

  • hosts: localhost vars: my_param: -5 tasks:
    • name: Testing my_param assert: that:
      • my_param <= 100
      • my_param >= -3
      • my_param >= 0 This task will fail for both of the last two asserts. But when I have run this, I found below output:

PLAY [localhost] ****

TASK [Gathering Facts] ** ok: [localhost]

TASK [Testing my_param] ***** fatal: [localhost]: FAILED! => { "assertion": "my_param >= -3", "changed": false, "evaluated_to": false, "msg": "Assertion failed" } to retry, use: --limit @/home/DABSP/ansible/playbooks/orange_test.retry

PLAY RECAP ** localhost : ok=1 changed=0 unreachable=0 failed=1 So, ansible did not run the last assert as the previous one failed. This is expected in my opinion as ansible by design is not a test tool. Its a IaC tool. So to ansible, assertion 02 is an task which has failed, so it did not proceed for the next task. As we (practitioners) tend to exploit assertion module for testing, it will always bring problem. For example, we have to fix one by one to understand whether the next one will fail.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Talismanic commented 3 years ago

Closing this issue then Bhaiya.