Skip to content

Commit

Permalink
Merge branch 'origin/mgirgis-OSPRH-8378' into efoley_add_test_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
elfiesmelfie committed Oct 21, 2024
2 parents a51dcb7 + e9dd798 commit dbb8dcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
25 changes: 3 additions & 22 deletions callback_plugins/custom_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ def __init__(self):
super(CallbackModule, self).__init__()

# Custom environment variable handling
# self._output_dir = os.getcwd()
# Update this to parse these values from the config file, as well as the env.
self._output_dir = os.path.expanduser("~/.ansible.log")
# self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', '[TEST]')
self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', 'TEST')
#self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower()
self._fail_on_ignore = 'true' # this is needed because we use "ignore_errors" on the playbooks so that all the tests are run
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'False').lower()
self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'True').lower()
Expand Down Expand Up @@ -62,7 +59,7 @@ def _finish_task(self, status, result):
if self._test_case_prefix in task_data.name:
task_data.add_host(HostData(host_uuid, host_name, status, result))

# This bit is new
# Debugging
if task_data.name.startswith(self._test_case_prefix):
print(f"This task ({task_data.name}) starts with the test_prefix({self._test_case_prefix})")
if self._test_case_prefix in task_data.name:
Expand All @@ -71,45 +68,30 @@ def _finish_task(self, status, result):
print(f"This task ({task_data.name}) failed, but may not be reported")

def mutate_task_name(self, task_name):
#print("enter mutate_task_name(task_name=%s)" % task_name)

# Debugging
if not self._test_case_prefix in task_name:
print("task_name (%s) does not contain prefix (%s)" % (task_name, self._test_case_prefix))

new_name = task_name
new_name = new_name.split("\n")[0] # only use the first line, so we can include IDs and additional description
#print("%s\t(take the first line of the task name)" % new_name)

# this covers when a task is included, but the including task is the one that is the test
new_name = new_name.split(":")[-1] # only provide the last part of the name when the role name is included
#print("%s\t(split at :, take last element)" % new_name)

if len(self._test_case_prefix) > 0:
# this one may not be needed...
new_name = new_name.split(self._test_case_prefix)[-1] # remove the test prefix and everything before it
#print("%s\t(remove test prefix)" % new_name)

new_name = new_name.lower()
#print("%s\t(lowercase)" % new_name)

new_name = re.sub(r'\W', ' ', new_name) # replace all non-alphanumeric characters (except _) with a space
#print("%s (Replace non-alphanumerics with a space)" % new_name)

new_name = re.sub(r'(^\W*|\W*$)', '', new_name) # trim any trailing or leading non-alphanumeric characters
#print("%s\t(trim leading or trailing characters" % new_name)

new_name = re.sub(r' +', '_', new_name) # replace any number of spaces with _
#print("%s\t(spaces -> _)" % new_name)

#print("exit mutate_task_name")
return new_name

def _build_test_case(self, task_data, host_data):
"""
This is used in generate_report. The task_data and host data will get passed.
"""
# Use the original task name to define the final name
#new_name = self.mutate_task_name(task_data.name)

print("%s\t(task_name, pre-_build_test_case)" % task_data.name)
tc = super()._build_test_case(task_data, host_data)
Expand All @@ -118,11 +100,10 @@ def _build_test_case(self, task_data, host_data):

print("%s\t(tc.name, post-mutate_task_name)" % tc.name)

# I don't want these properties for now; I may be able to omit them with a config option
# These can be able to omit with a config option
# These two control whether testcases contain the system_out and
# system_err elements that show STDOUT and STDERR
tc.system_out = None
tc.system_err = None

tc.classname = "openstack-observability"
return tc
12 changes: 6 additions & 6 deletions ci/report_result.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Create the output files
- name: "Create the output files"
hosts:
- controller
vars_files:
Expand All @@ -11,15 +11,15 @@
state: directory
mode: "0755"

- name: Run the log file collection
- name: "Run the log file collection"
hosts:
- controller
- compute
gather_facts: true
vars_files:
- vars/common.yml
tasks:
- name: "Where is that XML file!?"
- name: "Find the XML file"
ansible.builtin.shell:
cmd: |
find ~/.ansible.log/ -name *.xml
Expand All @@ -31,7 +31,7 @@
var: xml_file_list.stdout_lines
ignore_errors: true

- name: Collect the XML files, renaming them for the host that they are collected from
- name: "Collect the XML files, renaming them for the host that they are collected from"
delegate_to: controller
ansible.builtin.copy:
remote_src: true
Expand All @@ -40,14 +40,14 @@
with_items: "{{ xml_file_list.stdout_lines }}"
when: xml_file_list.stdout_lines | length != 0

- name: Collect the custom_logger results
- name: "Collect the custom_logger results"
delegate_to: controller
ansible.builtin.copy:
remote_src: true
src: "{{ ansible_env.HOME }}/test_run_result.out"
dest: "{{ logs_dir }}/test_run_result.out"

- name: Collect the results summary
- name: "Collect the results summary"
delegate_to: controller
ansible.builtin.copy:
remote_src: true
Expand Down

0 comments on commit dbb8dcd

Please sign in to comment.