Skip to content

Commit

Permalink
fix: foreman_heal non current schedule clean up
Browse files Browse the repository at this point in the history
when a cloud didn't have a schedule we were not removing pre-existing
roles.

closes: #306
Change-Id: Ife2f62125b23a590add4623094b6a6f7dc44ad37
  • Loading branch information
grafuls committed Jan 21, 2020
1 parent ee93443 commit 596e04d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions quads/tools/foreman_heal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def main():
loop=loop,
)

ignore = []
ignore = ["cloud01"]
foreman_rbac_exclude = conf.get("foreman_rbac_exclude")
if foreman_rbac_exclude:
ignore = foreman_rbac_exclude.split("|")
ignore.extend(foreman_rbac_exclude.split("|"))
clouds = Cloud.objects()
for cloud in clouds:
if cloud.name != "cloud01" and cloud.name not in ignore:
if cloud.name not in ignore:
logger.info(f"Processing {cloud.name}")
user_id = loop.run_until_complete(foreman.get_user_id(cloud.name))
roles = loop.run_until_complete(foreman.get_user_roles(user_id))
Expand Down Expand Up @@ -62,7 +62,13 @@ def main():
)
logger.info(f"* Added role {schedule.host.name}")
else:
logger.info(" No active schedule.")
if roles:
logger.info(" No active schedule, removing pre-existing roles.")
for role, data in roles.items():
loop.run_until_complete(foreman.remove_role(cloud.name, role))
logger.info(f"* Removed role {role}")
else:
logger.info(" No active schedule nor roles assigned.")


if __name__ == "__main__":
Expand Down

0 comments on commit 596e04d

Please sign in to comment.