limit-log-files: allow unlimited files
Currently the role requieres a file limit to be set which is always enforced. This change allows the value 0 to not enforce any file limit. Change-Id: I589e0bbf8656e80c5d66a207674ae16a499e81cc
This commit is contained in:
@@ -14,9 +14,10 @@ and reports a warning to Zuul.
|
||||
|
||||
.. zuul:rolevar:: limit_log_files_file_limit:
|
||||
:type: int
|
||||
:default: 100
|
||||
:default: 0
|
||||
|
||||
Maximum number of files allowed in the logs directory.
|
||||
If set to 0, no limit is enforced on the number of files.
|
||||
|
||||
.. zuul:rolevar:: limit_log_files_file_rules:
|
||||
:type: string
|
||||
|
@@ -3,7 +3,7 @@ limit_log_files_log_dir: "{{ zuul.executor.log_root }}"
|
||||
|
||||
limit_log_files_fail: false
|
||||
|
||||
limit_log_files_file_limit: 100
|
||||
limit_log_files_file_limit: 0
|
||||
|
||||
limit_log_files_file_rules:
|
||||
- ".*job-output.json$ 500k"
|
||||
|
@@ -18,12 +18,16 @@
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Count files in target directory
|
||||
TOTAL_FILES=$(find "$TARGET_DIR" -type f | wc -l)
|
||||
# If FILE_LIMIT is 0 allow any number of files
|
||||
if (( FILE_LIMIT != 0 )); then
|
||||
# Count files in target directory
|
||||
TOTAL_FILES=$(find "$TARGET_DIR" -type f | wc -l)
|
||||
|
||||
if (( TOTAL_FILES > FILE_LIMIT )); then
|
||||
echo "Total number of files in '$TARGET_DIR' exceed limit: $TOTAL_FILES > $FILE_LIMIT"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if (( TOTAL_FILES > FILE_LIMIT )); then
|
||||
echo "Total number of files in '$TARGET_DIR' exceed limit: $TOTAL_FILES > $FILE_LIMIT"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
ERROR=0
|
||||
|
@@ -44,10 +44,10 @@
|
||||
limit_log_files_file_rules:
|
||||
- ".* 250c"
|
||||
- ".* 150c"
|
||||
# execute role with fail, should fail
|
||||
# execute role with big file, should fail
|
||||
- name: Block to rescue failing of role
|
||||
block:
|
||||
- name: Execute role in fail mode
|
||||
- name: Execute role with big file
|
||||
include_role:
|
||||
name: limit-log-files
|
||||
vars:
|
||||
@@ -59,6 +59,26 @@
|
||||
- name: Set fact for assertion
|
||||
set_fact:
|
||||
has_failed: true
|
||||
- name: Assert that second run failed
|
||||
- name: Assert that run failed
|
||||
assert:
|
||||
that: has_failed is defined
|
||||
|
||||
# execute too many files, should fail
|
||||
- name: Block to rescue failing of role
|
||||
block:
|
||||
- name: Execute role with too many files
|
||||
include_role:
|
||||
name: limit-log-files
|
||||
vars:
|
||||
limit_log_files_fail: true
|
||||
limit_log_files_file_limit: 1
|
||||
limit_log_files_log_dir: "{{ test_folder }}"
|
||||
limit_log_files_file_rules:
|
||||
- ".* 500c"
|
||||
rescue:
|
||||
- name: Set fact for assertion
|
||||
set_fact:
|
||||
has_failed: true
|
||||
- name: Assert that run failed
|
||||
assert:
|
||||
that: has_failed is defined
|
||||
|
Reference in New Issue
Block a user