aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-09-11 15:14:38 +0000
committerGerrit Code Review <review@openstack.org>2023-09-11 15:14:38 +0000
commit59514880271d734efdce5de624d7c59134c38bef (patch)
treec317effde4905d9b023daf0e964b113b82a7b2ff /tools
parentcc73e9ee71fb0b2121b15d846ffef1328faf3f6b (diff)
parent49cb1ce4b01cfd2e02d6f474fb324f24ed7060f4 (diff)
downloadkolla-ansible-59514880271d734efdce5de624d7c59134c38bef.tar.gz
kolla-ansible-59514880271d734efdce5de624d7c59134c38bef.zip
Merge "CI: add block support to validate-all-file.py"
Diffstat (limited to 'tools')
-rwxr-xr-xtools/validate-all-file.py72
1 files changed, 45 insertions, 27 deletions
diff --git a/tools/validate-all-file.py b/tools/validate-all-file.py
index 33d3032bf..0b6007053 100755
--- a/tools/validate-all-file.py
+++ b/tools/validate-all-file.py
@@ -148,16 +148,14 @@ def check_json_j2():
return return_code
-def check_docker_become():
+def check_task_contents():
"""All tasks that use Docker should have 'become: true'."""
includes = r'|'.join([fnmatch.translate(x)
for x in YAML_INCLUDE_PATTERNS])
excludes = r'|'.join([fnmatch.translate(x)
for x in YAML_EXCLUDE_PATTERNS])
- ce_modules = ('kolla_docker', 'kolla_container_facts', 'kolla_toolbox')
- cmd_modules = ('command', 'shell')
- return_code = 0
roles_path = os.path.join(PROJECT_ROOT, 'ansible', 'roles')
+ return_code = 0
for root, dirs, files in os.walk(roles_path):
dirs[:] = [d for d in dirs if not re.match(excludes, d)]
for filename in files:
@@ -168,30 +166,50 @@ def check_docker_become():
tasks = yaml.safe_load(fp)
tasks = tasks or []
for task in tasks:
- for module in ce_modules:
- if module in task and not task.get('become'):
- return_code = 1
- LOG.error("Use of %s module without become in "
- "task %s in %s",
- module, task['name'], fullpath)
- for module in cmd_modules:
- ce_without_become = False
- if (module in task and not task.get('become')):
- if (isinstance(task[module], str) and
- ((task[module]).startswith('docker') or
- (task[module]).startswith('podman'))):
- ce_without_become = True
- if (isinstance(task[module], dict) and
- (task[module]['cmd'].startswith('docker') or
- task[module]['cmd'].startswith('podman'))):
- ce_without_become = True
- if ce_without_become:
+ if task.get('block'):
+ block = task
+ for task in task['block']:
+ if check_docker_become(fullpath, task, block):
return_code = 1
- LOG.error("Use of container engine in %s "
- "module without "
- "become in task %s in %s",
- module, task['name'], fullpath)
+ else:
+ if check_docker_become(fullpath, task):
+ return_code = 1
+
+ return return_code
+
+
+def check_docker_become(fullpath, task, block=''):
+
+ ce_modules = ('kolla_docker', 'kolla_container_facts', 'kolla_toolbox')
+ cmd_modules = ('command', 'shell')
+ return_code = 0
+ for module in ce_modules:
+ if (module in task and not task.get('become') and
+ not block.get('become')):
+ return_code = 1
+ LOG.error("Use of %s module without become in "
+ "task %s in %s",
+ module, task['name'], fullpath)
+ for module in cmd_modules:
+ ce_without_become = False
+ if (module in task and not task.get('become')):
+ if (isinstance(task[module], str) and
+ (task[module].startswith('docker') or
+ task[module].startswith('podman')) and
+ not block.get('become')):
+ ce_without_become = True
+ if (isinstance(task[module], dict) and
+ (task[module]['cmd'].startswith('docker') or
+ task[module]['cmd'].startswith('podman')) and
+ not block.get('become')):
+ ce_without_become = True
+ if ce_without_become:
+ return_code = 1
+ LOG.error("Use of container engine in %s "
+ "module without "
+ "become in task %s in %s block %s",
+ module, task['name'], fullpath, block)
return return_code
@@ -199,7 +217,7 @@ def main():
checks = (
check_newline_eof,
check_json_j2,
- check_docker_become,
+ check_task_contents,
)
return sum([check() for check in checks])