diff options
author | Matt Martz <matt@sivel.net> | 2020-10-02 14:53:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 14:53:09 -0500 |
commit | ab2b339dd6d27c4b06001e88480eabe9a94a8e92 (patch) | |
tree | 1266060f33594477cb86dc2abf625505c2b54af8 /test/integration/targets | |
parent | a7170da851e2a3951311a3c78bcac5346b5edacd (diff) | |
download | ansible-ab2b339dd6d27c4b06001e88480eabe9a94a8e92.tar.gz |
More explicit argspec tests (#72064)
* Add more explicit coverage of argspec functionality
* fail_on_missing_params
* ci_complete ci_coverage
* Remove incidental_aws_step_functions_state_machine
* ci_complete ci_coverage
* Remove incidental_cs_service_offering
* ci_complete ci_coverage
Diffstat (limited to 'test/integration/targets')
13 files changed, 45 insertions, 721 deletions
diff --git a/test/integration/targets/argspec/library/argspec.py b/test/integration/targets/argspec/library/argspec.py index 077cd01c4e..e14df1eac9 100644 --- a/test/integration/targets/argspec/library/argspec.py +++ b/test/integration/targets/argspec/library/argspec.py @@ -42,6 +42,14 @@ def main(): 'another': {}, } }, + 'json': { + 'type': 'json', + }, + 'fail_on_missing_params': { + 'type': 'list', + 'default': [], + }, + 'needed_param': {}, }, required_if=( ('state', 'present', ('path', 'content'), True), @@ -51,6 +59,8 @@ def main(): ), ) + module.fail_on_missing_params(module.params['fail_on_missing_params']) + module.exit_json(**module.params) diff --git a/test/integration/targets/argspec/tasks/main.yml b/test/integration/targets/argspec/tasks/main.yml index f6672f4e0f..50c2855424 100644 --- a/test/integration/targets/argspec/tasks/main.yml +++ b/test/integration/targets/argspec/tasks/main.yml @@ -87,6 +87,31 @@ register: argpsec_required_if_fail ignore_errors: true +- argspec: + json: !!str '{"foo": "bar"}' + register: argspec_good_json_string + +- argspec: + json: + foo: bar + register: argspec_good_json_dict + +- argspec: + json: 1 + register: argspec_bad_json + ignore_errors: true + +- argspec: + fail_on_missing_params: + - needed_param + needed_param: whatever + +- argspec: + fail_on_missing_params: + - needed_param + register: argspec_fail_on_missing_params_bad + ignore_errors: true + - assert: that: - argspec_required_if_fail is failed @@ -109,3 +134,13 @@ - argspec_required_together_fail is failed - argpsec_required_if_fail is failed + + - argspec_good_json_string is successful + - > + argspec_good_json_string.json == '{"foo": "bar"}' + - argspec_good_json_dict is successful + - > + argspec_good_json_dict.json == '{"foo": "bar"}' + - argspec_bad_json is failed + + - argspec_fail_on_missing_params_bad is failed diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/aliases b/test/integration/targets/incidental_aws_step_functions_state_machine/aliases deleted file mode 100644 index 29f60feb44..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/aliases +++ /dev/null @@ -1,2 +0,0 @@ -cloud/aws -shippable/aws/incidental diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/defaults/main.yml b/test/integration/targets/incidental_aws_step_functions_state_machine/defaults/main.yml deleted file mode 100644 index 273a0c783b..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -# the random_num is generated in a set_fact task at the start of the testsuite -state_machine_name: "{{ resource_prefix }}_step_functions_state_machine_ansible_test_{{ random_num }}" -step_functions_role_name: "ansible-test-sts-{{ resource_prefix }}-step_functions-role" -execution_name: "{{ resource_prefix }}_sfn_execution" diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/files/alternative_state_machine.json b/test/integration/targets/incidental_aws_step_functions_state_machine/files/alternative_state_machine.json deleted file mode 100644 index 7b51bebb1a..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/files/alternative_state_machine.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "StartAt": "HelloWorld", - "States": { - "HelloWorld": { - "Type": "Pass", - "Result": "Some other result", - "Next": "Wait" - }, - "Wait": { - "Type": "Wait", - "Seconds": 30, - "End": true - } - } -}
\ No newline at end of file diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machine.json b/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machine.json deleted file mode 100644 index c07d5cebad..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machine.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "StartAt": "HelloWorld", - "States": { - "HelloWorld": { - "Type": "Pass", - "Result": "Hello World!", - "End": true - } - } -}
\ No newline at end of file diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machines_iam_trust_policy.json b/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machines_iam_trust_policy.json deleted file mode 100644 index 48d627220f..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/files/state_machines_iam_trust_policy.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "Service": "states.amazonaws.com" - }, - "Action": "sts:AssumeRole" - } - ] -}
\ No newline at end of file diff --git a/test/integration/targets/incidental_aws_step_functions_state_machine/tasks/main.yml b/test/integration/targets/incidental_aws_step_functions_state_machine/tasks/main.yml deleted file mode 100644 index 23e71dcebf..0000000000 --- a/test/integration/targets/incidental_aws_step_functions_state_machine/tasks/main.yml +++ /dev/null @@ -1,296 +0,0 @@ ---- - -- name: Integration test for AWS Step Function state machine module - module_defaults: - iam_role: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - aws_step_functions_state_machine: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - aws_step_functions_state_machine_execution: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - block: - - # ==== Setup ================================================== - - - name: Create IAM service role needed for Step Functions - iam_role: - name: "{{ step_functions_role_name }}" - description: Role with permissions for AWS Step Functions actions. - assume_role_policy_document: "{{ lookup('file', 'state_machines_iam_trust_policy.json') }}" - state: present - register: step_functions_role - - - name: Pause a few seconds to ensure IAM role is available to next task - pause: - seconds: 10 - - # ==== Tests =================================================== - - - name: Create a random component for state machine name - set_fact: - random_num: "{{ 999999999 | random }}" - - - name: Create a new state machine -- check_mode - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - project: helloWorld - state: present - register: creation_check - check_mode: yes - - - assert: - that: - - creation_check.changed == True - - creation_check.output == 'State machine would be created.' - - - name: Create a new state machine - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - project: helloWorld - state: present - register: creation_output - - - assert: - that: - - creation_output.changed == True - - - name: Pause a few seconds to ensure state machine role is available - pause: - seconds: 5 - - - name: Idempotent rerun of same state function -- check_mode - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - project: helloWorld - state: present - register: result - check_mode: yes - - - assert: - that: - - result.changed == False - - result.output == 'State is up-to-date.' - - - name: Idempotent rerun of same state function - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - project: helloWorld - state: present - register: result - - - assert: - that: - - result.changed == False - - - name: Update an existing state machine -- check_mode - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','alternative_state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - differentTag: different_tag - state: present - register: update_check - check_mode: yes - - - assert: - that: - - update_check.changed == True - - "update_check.output == 'State machine would be updated: {{ creation_output.state_machine_arn }}'" - - - name: Update an existing state machine - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - definition: "{{ lookup('file','alternative_state_machine.json') }}" - role_arn: "{{ step_functions_role.iam_role.arn }}" - tags: - differentTag: different_tag - state: present - register: update_output - - - assert: - that: - - update_output.changed == True - - update_output.state_machine_arn == creation_output.state_machine_arn - - - name: Start execution of state machine -- check_mode - aws_step_functions_state_machine_execution: - name: "{{ execution_name }}" - execution_input: "{}" - state_machine_arn: "{{ creation_output.state_machine_arn }}" - register: start_execution_output - check_mode: yes - - - assert: - that: - - start_execution_output.changed == True - - "start_execution_output.output == 'State machine execution would be started.'" - - - name: Start execution of state machine - aws_step_functions_state_machine_execution: - name: "{{ execution_name }}" - execution_input: "{}" - state_machine_arn: "{{ creation_output.state_machine_arn }}" - register: start_execution_output - - - assert: - that: - - start_execution_output.changed - - "'execution_arn' in start_execution_output" - - "'start_date' in start_execution_output" - - - name: Start execution of state machine (check for idempotency) (check mode) - aws_step_functions_state_machine_execution: - name: "{{ execution_name }}" - execution_input: "{}" - state_machine_arn: "{{ creation_output.state_machine_arn }}" - register: start_execution_output_idem_check - check_mode: yes - - - assert: - that: - - not start_execution_output_idem_check.changed - - "start_execution_output_idem_check.output == 'State machine execution already exists.'" - - - name: Start execution of state machine (check for idempotency) - aws_step_functions_state_machine_execution: - name: "{{ execution_name }}" - execution_input: "{}" - state_machine_arn: "{{ creation_output.state_machine_arn }}" - register: start_execution_output_idem - - - assert: - that: - - not start_execution_output_idem.changed - - - name: Stop execution of state machine -- check_mode - aws_step_functions_state_machine_execution: - action: stop - execution_arn: "{{ start_execution_output.execution_arn }}" - cause: "cause of the failure" - error: "error code of the failure" - register: stop_execution_output - check_mode: yes - - - name: Stop execution of state machine - aws_step_functions_state_machine_execution: - action: stop - execution_arn: "{{ start_execution_output.execution_arn }}" - cause: "cause of the failure" - error: "error code of the failure" - register: stop_execution_output - - - name: Stop execution of state machine (check for idempotency) - aws_step_functions_state_machine_execution: - action: stop - execution_arn: "{{ start_execution_output.execution_arn }}" - cause: "cause of the failure" - error: "error code of the failure" - register: stop_execution_output - - - name: Try stopping a non-running execution -- check_mode - aws_step_functions_state_machine_execution: - action: stop - execution_arn: "{{ start_execution_output.execution_arn }}" - cause: "cause of the failure" - error: "error code of the failure" - register: stop_execution_output - check_mode: yes - - - assert: - that: - - not stop_execution_output.changed - - "stop_execution_output.output == 'State machine execution is not running.'" - - - name: Try stopping a non-running execution - aws_step_functions_state_machine_execution: - action: stop - execution_arn: "{{ start_execution_output.execution_arn }}" - cause: "cause of the failure" - error: "error code of the failure" - register: stop_execution_output - check_mode: yes - - - assert: - that: - - not stop_execution_output.changed - - - name: Start execution of state machine with the same execution name - aws_step_functions_state_machine_execution: - name: "{{ execution_name }}" - state_machine_arn: "{{ creation_output.state_machine_arn }}" - register: start_execution_output_again - - - assert: - that: - - not start_execution_output_again.changed - - - name: Remove state machine -- check_mode - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - state: absent - register: deletion_check - check_mode: yes - - - assert: - that: - - deletion_check.changed == True - - "deletion_check.output == 'State machine would be deleted: {{ creation_output.state_machine_arn }}'" - - - name: Remove state machine - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - state: absent - register: deletion_output - - - assert: - that: - - deletion_output.changed == True - - deletion_output.state_machine_arn == creation_output.state_machine_arn - - - name: Non-existent state machine is absent - aws_step_functions_state_machine: - name: "non_existing_state_machine" - state: absent - register: result - - - assert: - that: - - result.changed == False - - # ==== Cleanup ==================================================== - - always: - - - name: Cleanup - delete state machine - aws_step_functions_state_machine: - name: "{{ state_machine_name }}" - state: absent - ignore_errors: true - - - name: Cleanup - delete IAM role needed for Step Functions test - iam_role: - name: "{{ step_functions_role_name }}" - state: absent - ignore_errors: true diff --git a/test/integration/targets/incidental_cs_service_offering/aliases b/test/integration/targets/incidental_cs_service_offering/aliases deleted file mode 100644 index e50e650e98..0000000000 --- a/test/integration/targets/incidental_cs_service_offering/aliases +++ /dev/null @@ -1,2 +0,0 @@ -cloud/cs -shippable/cs/incidental diff --git a/test/integration/targets/incidental_cs_service_offering/meta/main.yml b/test/integration/targets/incidental_cs_service_offering/meta/main.yml deleted file mode 100644 index d46613c55f..0000000000 --- a/test/integration/targets/incidental_cs_service_offering/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - incidental_cs_common diff --git a/test/integration/targets/incidental_cs_service_offering/tasks/guest_vm_service_offering.yml b/test/integration/targets/incidental_cs_service_offering/tasks/guest_vm_service_offering.yml deleted file mode 100644 index f7aee3c8a2..0000000000 --- a/test/integration/targets/incidental_cs_service_offering/tasks/guest_vm_service_offering.yml +++ /dev/null @@ -1,223 +0,0 @@ ---- -- name: setup service offering - cs_service_offering: - name: Micro - state: absent - register: so -- name: verify setup service offering - assert: - that: - - so is successful - -- name: create service offering in check mode - cs_service_offering: - name: Micro - display_text: Micro 512mb 1cpu - cpu_number: 1 - cpu_speed: 2198 - memory: 512 - host_tags: eco - storage_tags: - - eco - - backup - storage_type: local - register: so - check_mode: true -- name: verify create service offering in check mode - assert: - that: - - so is changed - -- name: create service offering - cs_service_offering: - name: Micro - display_text: Micro 512mb 1cpu - cpu_number: 1 - cpu_speed: 2198 - memory: 512 - host_tags: eco - storage_tags: - - eco - - backup - storage_type: local - register: so -- name: verify create service offering - assert: - that: - - so is changed - - so.name == "Micro" - - so.display_text == "Micro 512mb 1cpu" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: create service offering idempotence - cs_service_offering: - name: Micro - display_text: Micro 512mb 1cpu - cpu_number: 1 - cpu_speed: 2198 - memory: 512 - host_tags: eco - storage_tags: - - eco - - backup - storage_type: local - register: so -- name: verify create service offering idempotence - assert: - that: - - so is not changed - - so.name == "Micro" - - so.display_text == "Micro 512mb 1cpu" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: update service offering in check mode - cs_service_offering: - name: Micro - display_text: Micro RAM 512MB 1vCPU - register: so - check_mode: true -- name: verify create update offering in check mode - assert: - that: - - so is changed - - so.name == "Micro" - - so.display_text == "Micro 512mb 1cpu" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: update service offering - cs_service_offering: - name: Micro - display_text: Micro RAM 512MB 1vCPU - register: so -- name: verify update service offerin - assert: - that: - - so is changed - - so.name == "Micro" - - so.display_text == "Micro RAM 512MB 1vCPU" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: update service offering idempotence - cs_service_offering: - name: Micro - display_text: Micro RAM 512MB 1vCPU - register: so -- name: verify update service offering idempotence - assert: - that: - - so is not changed - - so.name == "Micro" - - so.display_text == "Micro RAM 512MB 1vCPU" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: remove service offering in check mode - cs_service_offering: - name: Micro - state: absent - check_mode: true - register: so -- name: verify remove service offering in check mode - assert: - that: - - so is changed - - so.name == "Micro" - - so.display_text == "Micro RAM 512MB 1vCPU" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: remove service offering - cs_service_offering: - name: Micro - state: absent - register: so -- name: verify remove service offering - assert: - that: - - so is changed - - so.name == "Micro" - - so.display_text == "Micro RAM 512MB 1vCPU" - - so.cpu_number == 1 - - so.cpu_speed == 2198 - - so.memory == 512 - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: remove service offering idempotence - cs_service_offering: - name: Micro - state: absent - register: so -- name: verify remove service offering idempotence - assert: - that: - - so is not changed - -- name: create custom service offering - cs_service_offering: - name: custom - display_text: custom offer - is_customized: yes - host_tags: eco - storage_tags: - - eco - - backup - storage_type: local - register: so -- name: verify create custom service offering - assert: - that: - - so is changed - - so.name == "custom" - - so.display_text == "custom offer" - - so.is_customized == True - - so.cpu_number is not defined - - so.cpu_speed is not defined - - so.memory is not defined - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" - -- name: remove custom service offering - cs_service_offering: - name: custom - state: absent - register: so -- name: verify remove service offering - assert: - that: - - so is changed - - so.name == "custom" - - so.display_text == "custom offer" - - so.host_tags == ['eco'] - - so.storage_tags == ['eco', 'backup'] - - so.storage_type == "local" diff --git a/test/integration/targets/incidental_cs_service_offering/tasks/main.yml b/test/integration/targets/incidental_cs_service_offering/tasks/main.yml deleted file mode 100644 index 581f7d74de..0000000000 --- a/test/integration/targets/incidental_cs_service_offering/tasks/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- import_tasks: guest_vm_service_offering.yml -- import_tasks: system_vm_service_offering.yml
\ No newline at end of file diff --git a/test/integration/targets/incidental_cs_service_offering/tasks/system_vm_service_offering.yml b/test/integration/targets/incidental_cs_service_offering/tasks/system_vm_service_offering.yml deleted file mode 100644 index 4c63a4b9c8..0000000000 --- a/test/integration/targets/incidental_cs_service_offering/tasks/system_vm_service_offering.yml +++ /dev/null @@ -1,151 +0,0 @@ ---- -- name: setup system offering - cs_service_offering: - name: System Offering for Ansible - is_system: true - state: absent - register: so -- name: verify setup system offering - assert: - that: - - so is successful - -- name: fail missing storage type and is_system - cs_service_offering: - name: System Offering for Ansible - cpu_number: 1 - cpu_speed: 500 - memory: 512 - host_tag: perf - storage_tag: perf - storage_type: shared - offer_ha: true - limit_cpu_usage: false - is_system: true - register: so - ignore_errors: true -- name: verify create system service offering in check mode - assert: - that: - - so is failed - - so.msg.startswith('missing required arguments:') - -- name: create system service offering in check mode - cs_service_offering: - name: System Offering for Ansible - cpu_number: 1 - cpu_speed: 500 - memory: 512 - host_tag: perf - storage_tag: perf - storage_type: shared - offer_ha: true - limit_cpu_usage: false - system_vm_type: domainrouter - is_system: true - register: so - check_mode: true -- name: verify create system service offering in check mode - assert: - that: - - so is changed - -- name: create system service offering - cs_service_offering: - name: System Offering for Ansible - cpu_number: 1 - cpu_speed: 500 - memory: 512 - host_tag: perf - storage_tag: perf - storage_type: shared - offer_ha: true - limit_cpu_usage: false - system_vm_type: domainrouter - is_system: true - register: so -- name: verify create system service offering - assert: - that: - - so is changed - - so.name == "System Offering for Ansible" - - so.display_text == "System Offering for Ansible" - - so.cpu_number == 1 - - so.cpu_speed == 500 - - so.memory == 512 - - so.host_tags == ['perf'] - - so.storage_tags == ['perf'] - - so.storage_type == "shared" - - so.offer_ha == true - - so.limit_cpu_usage == false - - so.system_vm_type == "domainrouter" - - so.is_system == true - -- name: create system service offering idempotence - cs_service_offering: - name: System Offering for Ansible - cpu_number: 1 - cpu_speed: 500 - memory: 512 - host_tag: perf - storage_tag: perf - storage_type: shared - offer_ha: true - limit_cpu_usage: false - system_vm_type: domainrouter - is_system: true - register: so -- name: verify create system service offering idempotence - assert: - that: - - so is not changed - - so.name == "System Offering for Ansible" - - so.display_text == "System Offering for Ansible" - - so.cpu_number == 1 - - so.cpu_speed == 500 - - so.memory == 512 - - so.host_tags == ['perf'] - - so.storage_tags == ['perf'] - - so.storage_type == "shared" - - so.offer_ha == true - - so.limit_cpu_usage == false - - so.system_vm_type == "domainrouter" - - so.is_system == true - -- name: remove system service offering in check mode - cs_service_offering: - name: System Offering for Ansible - is_system: true - state: absent - check_mode: true - register: so -- name: verify remove system service offering in check mode - assert: - that: - - so is changed - - so.name == "System Offering for Ansible" - - so.is_system == true - -- name: remove system service offering - cs_service_offering: - name: System Offering for Ansible - is_system: true - state: absent - register: so -- name: verify remove system service offering - assert: - that: - - so is changed - - so.name == "System Offering for Ansible" - - so.is_system == true - -- name: remove system service offering idempotence - cs_service_offering: - name: System Offering for Ansible - is_system: true - state: absent - register: so -- name: verify remove system service offering idempotence - assert: - that: - - so is not changed |