manage_projects: exit with error code
* Currently, manage_projects always perform `exit 0`, even if some errors were. * Patch would add `exit 1` beh., in case any issues were during processing. It would affect only exit code , and will not stop processing. * Misc: perform auto-ident Change-Id: I50d425e5a9e02441a50f7b1d32219485f80e6632
This commit is contained in:
parent
0673abe338
commit
dcd2739069
|
@ -59,6 +59,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import gerritlib.gerrit
|
import gerritlib.gerrit
|
||||||
|
@ -92,6 +93,14 @@ class CopyACLException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessACLException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class PushToGerritException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CreateGroupException(Exception):
|
class CreateGroupException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -358,6 +367,7 @@ def push_to_gerrit(repo_path, project, push_string, remote_url, ssh_env):
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
log.exception(
|
||||||
"Error pushing %s to Gerrit." % project)
|
"Error pushing %s to Gerrit." % project)
|
||||||
|
raise PushToGerritException()
|
||||||
|
|
||||||
|
|
||||||
def process_acls(acl_config, project, ACL_DIR, section,
|
def process_acls(acl_config, project, ACL_DIR, section,
|
||||||
|
@ -375,6 +385,7 @@ def process_acls(acl_config, project, ACL_DIR, section,
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
log.exception(
|
||||||
"Exception processing ACLS for %s." % project)
|
"Exception processing ACLS for %s." % project)
|
||||||
|
raise ProcessACLException()
|
||||||
finally:
|
finally:
|
||||||
u.git_command(repo_path, 'reset --hard')
|
u.git_command(repo_path, 'reset --hard')
|
||||||
u.git_command(repo_path, 'checkout master')
|
u.git_command(repo_path, 'checkout master')
|
||||||
|
@ -395,7 +406,6 @@ def create_gerrit_project(project, project_list, gerrit):
|
||||||
|
|
||||||
def create_local_mirror(local_git_dir, project_git,
|
def create_local_mirror(local_git_dir, project_git,
|
||||||
gerrit_system_user, gerrit_system_group):
|
gerrit_system_user, gerrit_system_group):
|
||||||
|
|
||||||
git_mirror_path = os.path.join(local_git_dir, project_git)
|
git_mirror_path = os.path.join(local_git_dir, project_git)
|
||||||
if not os.path.exists(git_mirror_path):
|
if not os.path.exists(git_mirror_path):
|
||||||
(ret, output) = u.run_command_status(
|
(ret, output) = u.run_command_status(
|
||||||
|
@ -462,6 +472,8 @@ def main():
|
||||||
project_list = gerrit.listProjects()
|
project_list = gerrit.listProjects()
|
||||||
ssh_env = u.make_ssh_wrapper(GERRIT_USER, GERRIT_KEY)
|
ssh_env = u.make_ssh_wrapper(GERRIT_USER, GERRIT_KEY)
|
||||||
try:
|
try:
|
||||||
|
# Collect processed errors,if any
|
||||||
|
process_errors = []
|
||||||
for section in registry.configs_list:
|
for section in registry.configs_list:
|
||||||
project = section['project']
|
project = section['project']
|
||||||
if args.projects and project not in args.projects:
|
if args.projects and project not in args.projects:
|
||||||
|
@ -569,8 +581,9 @@ def main():
|
||||||
project_cache[project]['created-in-github'] = created
|
project_cache[project]['created-in-github'] = created
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
msg = "Problems creating %s, moving on." % project
|
||||||
"Problems creating %s, moving on." % project)
|
log.exception(msg)
|
||||||
|
process_errors.append(msg)
|
||||||
continue
|
continue
|
||||||
finally:
|
finally:
|
||||||
# Clean up after ourselves - this repo has no use
|
# Clean up after ourselves - this repo has no use
|
||||||
|
@ -582,6 +595,11 @@ def main():
|
||||||
cache_out.write(json.dumps(
|
cache_out.write(json.dumps(
|
||||||
project_cache, sort_keys=True, indent=2))
|
project_cache, sort_keys=True, indent=2))
|
||||||
os.unlink(ssh_env['GIT_SSH'])
|
os.unlink(ssh_env['GIT_SSH'])
|
||||||
|
if len(process_errors) > 0:
|
||||||
|
log.error("%d problems has been caught during run:\n %s" % (
|
||||||
|
len(process_errors), process_errors))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue