-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished adding code to do full coverage tests of the f5 modules usin…
…g ansible playbooks
- Loading branch information
1 parent
4a0e9e6
commit 88fb0a4
Showing
9 changed files
with
190 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
|
||
- include: process-module.yaml | ||
with_fileglob: | ||
- "{{ base_dir }}/library/bigip_*.py" | ||
loop_control: | ||
loop_var: f5_module_filename | ||
|
||
# This cannot be inside of the files loop (which, as a consequence | ||
# makes the overall role slower) because of the way that coverage works | ||
# | ||
# For example, upon the first run, the 'coverage combine' command will | ||
# merge all of the .coverage files. | ||
# | ||
# On following runs, the tasks looking for filenames to replace in the | ||
# coverage file, causing the same index to exist multiple times. When | ||
# coverage tries to iterate over the keys, only the last key will be | ||
# evaluated, so the whole set of coverage will be off. | ||
# | ||
# For example, running in parallel produces keys that look like this | ||
# | ||
# !coverage.py: This is a private format, don't read it directly! | ||
# { | ||
# "arcs": { | ||
# "/p...e/var/f...s/jc/9d1...m45/T/ansible_rZUTVv/ansible_module_bigip_vlan.py": | ||
# [[-136, 137],.... | ||
# ], | ||
# "/p...e/var/f...s/jc/9d1...m45/T/ansible_jhhs8v/ansible_module_bigip_vlan.py": | ||
# [[-143, 187],.... | ||
# ] | ||
# ... | ||
# | ||
# The renaming task makes all of these look like this | ||
# | ||
# !coverage.py: This is a private format, don't read it directly! | ||
# { | ||
# "arcs": { | ||
# "/Users/trupp/src/f5-ansible/library/bigip_vlan.py": | ||
# [[-136, 137],.... | ||
# ], | ||
# "/Users/trupp/src/f5-ansible/library/bigip_vlan.py": | ||
# [[-143, 187],.... | ||
# ] | ||
# ... | ||
- name: Combine coverage files | ||
shell: "coverage combine cache/coverage/" | ||
when: toggle == 'off' | ||
args: | ||
chdir: "{{ base_dir|abspath }}" | ||
executable: "/bin/bash" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
|
||
- name: Create some module shorthand variables | ||
set_fact: | ||
module_full_path: "{{ playbook_dir + '/../library/' + f5_module + '.py' }}" | ||
|
||
- name: Replace the name of the module in the coverage includes | ||
lineinfile: | ||
insertafter: "include =" | ||
regexp: "(MODULE_NAME|{{ f5_module }}\\*)" | ||
line: " *ansible_module_{{ f5_module }}*" | ||
state: "present" | ||
dest: "{{ base_dir|abspath }}/.coveragerc" | ||
when: toggle == 'on' | ||
run_once: true | ||
|
||
- name: Replace cache name in coverage file with module location | ||
replace: | ||
dest: "{{ item|abspath }}" | ||
regexp: '"([A-Za-z0-9_\./\\-]*{{ f5_module }}.py)"' | ||
replace: '"{{ module_full_path|abspath }}"' | ||
when: toggle == 'off' | ||
with_fileglob: | ||
- "{{ coverage_dir|abspath }}/.coverage.*" | ||
|
||
- name: Combine coverage files | ||
shell: "coverage combine cache/coverage/" | ||
when: toggle == 'off' | ||
args: | ||
chdir: "{{ base_dir|abspath }}" | ||
executable: "/bin/bash" | ||
run_once: true | ||
|
||
- name: Replace the name of the module to match original | ||
lineinfile: | ||
regexp: "\\*ansible_module_{{ f5_module }}\\*" | ||
line: " *{{ f5_module }}*" | ||
state: "present" | ||
dest: "{{ base_dir|abspath }}/.coveragerc" | ||
when: toggle == 'off' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
- name: Specify which module we are handling | ||
debug: | ||
msg: "Disabling coverage for module '{{ module_current }}'" | ||
|
||
- name: Fix module location to no longer be temporary path | ||
replace: | ||
dest: "{{ item|abspath }}" | ||
regexp: '"([A-Za-z0-9_\./\\-]*{{ module_current }}.py)"' | ||
replace: '"{{ module_full_path|abspath }}"' | ||
with_fileglob: | ||
- "{{ coverage_dir|abspath }}/.coverage*" | ||
|
||
- name: Replace the name of the module in .coveragerc to match original | ||
lineinfile: | ||
regexp: "\\*ansible_module_{{ module_current }}\\*" | ||
line: " *{{ module_current }}*" | ||
state: "present" | ||
dest: "{{ base_dir|abspath }}/.coveragerc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
|
||
- name: Specify which module we are handling | ||
debug: | ||
msg: "Enabling coverage for module '{{ module_current }}'" | ||
|
||
- name: Replace the name of the module in the coverage includes | ||
lineinfile: | ||
insertafter: "include =" | ||
regexp: "(MODULE_NAME|{{ module_current }}\\*)" | ||
line: " *ansible_module_{{ module_current }}*" | ||
state: "present" | ||
dest: "{{ base_dir|abspath }}/.coveragerc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
|
||
- name: Set some convenience facts for later usage | ||
set_fact: | ||
module_current: "{{ f5_module_filename|basename|splitext|first }}" | ||
|
||
- name: Create some module shorthand variables | ||
set_fact: | ||
module_full_path: "{{ playbook_dir + '/../library/' + module_current + '.py' }}" | ||
|
||
- name: Include tasks to enable coverage if requested | ||
include: "process-module-on.yaml" | ||
when: toggle == 'on' | ||
|
||
- name: Include tasks to disable coverage if requested | ||
include: "process-module-off.yaml" | ||
when: toggle == 'off' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[run] | ||
branch = True | ||
cover_pylib = False | ||
concurrency = multiprocessing | ||
data_file = COVERAGE_PATH | ||
include = | ||
MODULE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
|
||
# Test and measure coverage across all modules | ||
# | ||
# This playbook can be used to run all of the tests for the various modules. | ||
# Additionally, it will run the coverage tests of the modules so that that | ||
# can be represented on the Github page. | ||
# | ||
# Usage: | ||
# | ||
# export COVERAGE_PROCESS_START=${CURDIR}/.coveragerc | ||
# export ANSIBLE_KEEP_REMOTE_FILES=1 | ||
# ansible-playbook -i inventory/hosts tests/bigip.yaml [OPTIONS] | ||
# | ||
# Examples: | ||
# | ||
# Run all tests on the modules | ||
# | ||
# export COVERAGE_PROCESS_START=${CURDIR}/.coveragerc | ||
# export ANSIBLE_KEEP_REMOTE_FILES=1 | ||
# ansible-playbook -i inventory/hosts tests/bigip.yaml --vaukt-password-file ./vault.txt | ||
# | ||
|
||
# Leave these in alphabetical order for readability | ||
- include: bigip_selfip.yaml | ||
- include: bigip_vlan.yaml |