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
OpenEdx
configuration
Commits
c43656c7
Commit
c43656c7
authored
Dec 05, 2013
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a script that will check mongo for AMIs.
parent
50f158d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
0 deletions
+120
-0
requirements.txt
+2
-0
util/jenkins/monitor_repos.py
+118
-0
No files found.
requirements.txt
View file @
c43656c7
...
...
@@ -9,3 +9,5 @@ ecdsa==0.10
paramiko
==1.12.0
pycrypto
==2.6.1
wsgiref
==0.1.2
GitPython
==0.3.2.RC1
pymongo
==2.4.1
util/jenkins/monitor_repos.py
0 → 100644
View file @
c43656c7
import
argparse
import
yaml
from
git
import
*
from
pprint
import
pformat
from
pprint
import
pprint
from
pymongo
import
MongoClient
def
uri_from
(
doc_store_config
):
"""
Convert the below structure to a mongodb uri.
DOC_STORE_CONFIG:
hosts:
- 'host1.com'
- 'host2.com'
port: 10012
db: 'devops'
user: 'username'
password: 'password'
"""
uri_format
=
"mongodb://{user}:{password}@{hosts}/{db}"
host_format
=
"{host}:{port}"
port
=
doc_store_config
[
'port'
]
host_uris
=
[
host_format
.
format
(
host
=
host
,
port
=
port
)
for
host
in
doc_store_config
[
'hosts'
]]
return
uri_format
.
format
(
user
=
doc_store_config
[
'user'
],
password
=
doc_store_config
[
'password'
],
hosts
=
","
.
join
(
host_uris
),
db
=
doc_store_config
[
'db'
])
def
release_hashes
(
repo
):
for
ref
in
repo
.
remotes
.
origin
.
refs
:
if
ref
.
name
.
startswith
(
'origin/rc/'
):
yield
ref
.
commit
.
hexsha
def
check_all
(
config
):
client
=
MongoClient
(
uri_from
(
config
[
'DOC_STORE_CONFIG'
]))
repos
=
[
Repo
(
repo_dir
)
for
repo_dir
in
config
[
'repos'
]]
configuration_repo
=
Repo
(
config
[
'configuration_repo'
])
configuration_secure
=
Repo
(
config
[
'configuration_secure'
])
for
repo
in
repos
:
for
git_hash
in
release_hashes
(
repo
):
pass
def
have_ami
(
ami_signature
,
db
):
db
.
amis
.
find_one
(
ami_signature
)
pass
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"Monitor git repos for new rc branches."
)
parser
.
add_argument
(
'-c'
,
'--config'
,
required
=
True
,
help
=
"Config file."
)
subparsers
=
parser
.
add_subparsers
(
help
=
"The running mode of the script."
)
msg
=
"Check all rc branches of all repos specified in config."
parse_monitor
=
subparsers
.
add_parser
(
'all'
,
help
=
msg
)
parse_monitor
.
set_defaults
(
all
=
True
)
msg
=
"Manually trigger a build for a given play."
manual_monitor
=
subparsers
.
add_parser
(
'single'
,
help
=
msg
)
manual_monitor
.
set_defaults
(
all
=
False
)
manual_monitor
.
add_argument
(
"--env"
,
required
=
True
,
help
=
"The environment to build for."
)
manual_monitor
.
add_argument
(
"--deployment"
,
required
=
True
,
help
=
"e.g. edx, edge, etc."
)
manual_monitor
.
add_argument
(
"--play"
,
required
=
True
,
help
=
"The ansible play to run."
)
manual_monitor
.
add_argument
(
"--cfg-repo"
,
help
=
"Hash of the configuration repo to use."
)
manual_monitor
.
add_argument
(
"--cfg-secure-repo"
,
help
=
"Hash of the configuration-secure repo to use."
)
manual_monitor
.
add_argument
(
"VARS"
,
nargs
=
"+"
,
help
=
"Any number of var=value(no spcae around '='"
+
\
" e.g. 'edxapp=3233bac xqueue=92832ab'"
)
args
=
parser
.
parse_args
()
config
=
yaml
.
safe_load
(
open
(
args
.
config
))
if
args
.
all
:
check_all
(
config
)
else
:
client
=
MongoClient
(
uri_from
(
config
[
'DOC_STORE_CONFIG'
]))
db
=
client
[
config
[
'DOC_STORE_CONFIG'
][
'db'
]]
# Parse the vars.
var_array
=
map
(
lambda
key_value
:
key_value
.
split
(
'='
),
args
.
VARS
)
ansible_vars
=
{
item
[
0
]:
item
[
1
]
for
item
in
var_array
}
# Check the specified play.
if
not
args
.
cfg_repo
:
# Look up the config repo if it's not provided.
repo
=
Repo
(
config
[
'configuration_repo'
])
args
.
cfg_repo
=
repo
.
commit
()
.
hexsha
if
not
args
.
cfg_secure_repo
:
# Look up the configuration secure repo if it's not provided.
repo
=
Repo
(
config
[
'configuration_secure'
])
args
.
cfg_secure_repo
=
repo
.
commit
()
.
hexsha
ami_signature
=
{
'env'
:
args
.
env
,
'deployment'
:
args
.
deployment
,
'play'
:
args
.
play
,
'configuration_ref'
:
args
.
cfg_repo
,
'configuration_secure_ref'
:
args
.
cfg_secure_repo
,
'vars'
:
ansible_vars
,
}
ami_item
=
db
.
amis
.
find_one
(
ami_signature
)
if
not
ami_item
:
print
(
"Need ami for:
\n
{}"
.
format
(
pformat
(
ami_signature
)))
else
:
print
(
"Ami exists:
\n
{}"
.
format
(
pformat
(
ami_item
)))
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