Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
configuration
Commits
8ffe85ab
Commit
8ffe85ab
authored
Aug 12, 2016
by
MichaelRoytman
Committed by
GitHub
Aug 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3309 from edx/michael/fix-script
Michael/fix script
parents
598db995
74c439b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
21 deletions
+41
-21
util/parsefiles.py
+41
-21
No files found.
util/parsefiles.py
View file @
8ffe85ab
...
...
@@ -81,8 +81,8 @@ def _map_roles_to_roles(graph, dirs, git_dir, key, type_1, type_2):
# add node for type_2, typically dependent role
node_2
=
Node
(
name
,
type_2
)
# add edge, typically
role - dependent
role
graph
.
add_edge
(
node_
1
,
node_2
)
# add edge, typically
dependent role -
role
graph
.
add_edge
(
node_
2
,
node_1
)
def
_map_plays_to_roles
(
graph
,
dirs
,
git_dir
,
key
,
type_1
,
type_2
):
"""
...
...
@@ -130,8 +130,8 @@ def _map_plays_to_roles(graph, dirs, git_dir, key, type_1, type_2):
# add node for type_2, typically for role
node_2
=
Node
(
name
,
type_2
)
# add edge, typically
playbook - role it uses
graph
.
add_edge
(
node_
1
,
node_2
)
# add edge, typically
role - playbook that uses it
graph
.
add_edge
(
node_
2
,
node_1
)
def
_open_yaml_file
(
file_str
):
"""
...
...
@@ -178,7 +178,20 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph):
# if the change set file is in the set of role files
if
file_path
in
candidate_files
:
# 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_role_name_from_file
(
file_path
))
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
play_dir
in
playbooks_dirs
:
...
...
@@ -192,33 +205,35 @@ def change_set_to_roles(files, git_dir, roles_dirs, playbooks_dirs, graph):
for
f
in
files
:
file_path
=
pathlib2
.
Path
(
git_dir
,
f
)
# if the change set file is in t
eh
set of playbook files
# if the change set file is in t
he
set of playbook files
if
file_path
in
candidate_files
:
plays
.
add
(
_get_playbok_name_from_file
(
file_path
))
# gets first level of children of playbook in graph, which represents
# all roles the playbook uses
descendants
=
nx
.
all_neighbors
(
graph
,
(
file_path
.
stem
,
"aws_playbook"
))
return
plays
def
_get_playbook_name_from_file
(
path
):
"""
Gets name of playbook from the filepath, which is the last part of the filepath.
# adds all the roles that a playbook uses to set of roles of the change set
items
|=
{
desc
.
name
for
desc
in
descendants
}
return
items
Input:
path: A path to the playbook
"""
# get last part of filepath
return
path
.
stem
def
_get_r
esource_name
(
path
,
kind
):
def
_get_r
ole_name_from_file
(
path
):
"""
Gets name of r
esource from the filepath, which is the directory following occurence of kind
.
Gets name of r
ole from the filepath, which is the directory following occurence of the word "roles"
.
Input:
path: A path to the resource (e.g. a role or a playbook)
kind: A description of the type of resource; this keyword precedes the name of a role or a playbook
in a file path and allows for the separation of its name;
e.g. for "configuration/playbooks/roles/discovery/...", kind = "roles" returns
"discovery" as the role name
path: A path to the role
"""
# get individual parts of a file path
dirs
=
path
.
parts
#
type of resource is the next part of the file path after kind (e.g. after "roles" or "playbooks")
return
dirs
[
dirs
.
index
(
kind
)
+
1
]
#
name of role is the next part of the file path after "roles"
return
dirs
[
dirs
.
index
(
"roles"
)
+
1
]
def
get_dependencies
(
roles
,
graph
):
"""
...
...
@@ -355,6 +370,9 @@ if __name__ == '__main__':
# build graph
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
roles
=
change_set_to_roles
(
change_set
,
TRAVIS_BUILD_DIR
,
config
[
"roles_paths"
],
config
[
"aws_plays_paths"
],
graph
)
...
...
@@ -364,6 +382,8 @@ if __name__ == '__main__':
# determine which docker plays cover at least one role
docker_plays
=
get_docker_plays
(
dependent_roles
,
graph
)
docker_plays
=
docker_plays
|
plays
# filter out docker plays without a Dockerfile
docker_plays
=
filter_docker_plays
(
docker_plays
,
TRAVIS_BUILD_DIR
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment