Commit 397661d1 by Michael Roytman

Modify playbook case

parent 746ed762
...@@ -179,6 +179,19 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph): ...@@ -179,6 +179,19 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph):
if file_path in candidate_files: if file_path in candidate_files:
# get name of role and add it to set of roles of the change set # get name of role and add it to set of roles of the change set
items.add(_get_resource_name(file_path, "roles")) items.add(_get_resource_name(file_path, "roles"))
return items
def get_plays(files, git_dir, playbooks_dirs):
"""
Determines which files in the change set are aws playbooks
files: A list of files modified by a commit range.
git_dir: A path to the top-most directory in the local git repository tool is to be run in.
playbook_dirs: A list of relative paths to directories in which Ansible playbooks reside.
"""
plays = set()
# for all directories containing playbooks # for all directories containing playbooks
for play_dir in playbooks_dirs: for play_dir in playbooks_dirs:
...@@ -192,16 +205,20 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph): ...@@ -192,16 +205,20 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph):
for f in files: for f in files:
file_path = pathlib2.Path(git_dir, f) file_path = pathlib2.Path(git_dir, f)
# if the change set file is in teh set of playbook files # if the change set file is in the set of playbook files
if file_path in candidate_files: if file_path in candidate_files:
# if looking in playbooks directory
# gets first level of children of playbook in graph, which represents if play_dir == "playbooks":
# all roles the playbook uses play = _get_resource_name(file_path, "playbooks")
descendants = nx.all_neighbors(graph, (file_path.stem, "aws_playbook")) # remove ".yml" file ending
play = play[:-4]
# adds all the roles that a playbook uses to set of roles of the change set plays.add(play)
items |= {desc.name for desc in descendants} elif play_dir == "playbooks/edx-east":
return items play = _get_resource_name(file_path, "edx-east")
# remove ".yml" file ending
play = play[:-4]
plays.add(play)
return plays
def _get_resource_name(path, kind): def _get_resource_name(path, kind):
""" """
...@@ -355,6 +372,9 @@ if __name__ == '__main__': ...@@ -355,6 +372,9 @@ if __name__ == '__main__':
# build graph # build graph
graph = build_graph(TRAVIS_BUILD_DIR, config["roles_paths"], config["aws_plays_paths"], config["docker_plays_paths"]) graph = build_graph(TRAVIS_BUILD_DIR, config["roles_paths"], config["aws_plays_paths"], config["docker_plays_paths"])
# gets any playbooks in the commit range
plays = get_plays(change_set, TRAVIS_BUILD_DIR, config["aws_plays_paths"])
# transforms list of roles and plays into list of original roles and the roles contained in the plays # transforms list of roles and plays into list of original roles and the roles contained in the plays
roles = change_set_to_roles(change_set, TRAVIS_BUILD_DIR, config["roles_paths"], config["aws_plays_paths"], graph) roles = change_set_to_roles(change_set, TRAVIS_BUILD_DIR, config["roles_paths"], config["aws_plays_paths"], graph)
...@@ -364,6 +384,8 @@ if __name__ == '__main__': ...@@ -364,6 +384,8 @@ if __name__ == '__main__':
# determine which docker plays cover at least one role # determine which docker plays cover at least one role
docker_plays = get_docker_plays(dependent_roles, graph) docker_plays = get_docker_plays(dependent_roles, graph)
docker_plays = docker_plays | plays
# filter out docker plays without a Dockerfile # filter out docker plays without a Dockerfile
docker_plays = filter_docker_plays(docker_plays, TRAVIS_BUILD_DIR) docker_plays = filter_docker_plays(docker_plays, TRAVIS_BUILD_DIR)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment