Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 702595 - write initial balrog admin client to support nightly bui…
Browse files Browse the repository at this point in the history
…ld submissions. r=bhearsum
  • Loading branch information
Rail Aliiev committed Mar 27, 2012
1 parent 8971952 commit d3004c2
Show file tree
Hide file tree
Showing 51 changed files with 7,356 additions and 1 deletion.
Empty file added lib/python/balrog/__init__.py
Empty file.
Empty file.
60 changes: 60 additions & 0 deletions lib/python/balrog/client/api.py
@@ -0,0 +1,60 @@
# TODO: extend API to handle release blobs

import logging
import requests
import os

CA_BUNDLE = os.path.join(os.path.dirname(__file__),
'../../../../misc/mozilla-root.crt')


class API(object):

url_template = \
'%(api_root)s/releases/%(name)s/builds/%(build_target)s/%(locale)s'

verify = False
auth = None

def __init__(self, api_root='https://balrog.build.mozilla.org',
auth=None, ca_certs=CA_BUNDLE, timeout=60, raise_exceptions=True):
""" Creates an API object which wraps REST API of Balrog server.
api_root: API root URL of balrog server
auth : a tuple of (username, password) or None
ca_certs: CA bundle. It follows python-requests `verify' usage.
If set to False, no SSL verification is done.
If set to True, it tries to load a CA bundle from certifi
module.
If set to string, puthon-requests uses it as a pth to path to
CA bundle.
timeout : request timeout
raise_exceptions: Sets danger_mode parameter of python-requests config
which controls excpetion raising.
"""
self.api_root = api_root.rstrip('/')
self.verify = ca_certs
assert isinstance(auth, tuple) or auth == None, \
"auth should be set to tuple or None"
self.auth = auth
self.timeout = timeout
self.config = dict(danger_mode=raise_exceptions)

def request(self, url, data=None, method='GET'):
logging.debug('Balrog request to %s' % url)
logging.debug('Data sent: %s' % data)
return requests.request(method=method, url=url, data=data,
config=self.config, timeout=self.timeout,
verify=self.verify, auth=self.auth)

def update_build(self, name, product, version, build_target, locale,
details, copy_to=None):
url_template_vars = dict(api_root=self.api_root, name=name,
locale=locale, build_target=build_target)
url = self.url_template % url_template_vars
data = dict(product=product, version=version,
details=details)
if copy_to:
data['copy_to'] = copy_to

return self.request(method='PUT', url=url, data=data)
80 changes: 80 additions & 0 deletions lib/python/balrog/client/cli.py
@@ -0,0 +1,80 @@
try:
import simplejson as json
except ImportError:
import json

from release.platforms import buildbot2updatePlatforms
from balrog.client.api import API


def get_nightly_blob_name(appName, branch, build_type, suffix, dummy=False):
if dummy:
branch = '%s-dummy' % branch
return '%s-%s-%s-%s' % (appName, branch, build_type, suffix)


class NightlyRunner(object):

build_type = 'nightly'
appName = None
branch = None
build_target = None
appVersion = None
name = None
locale = None

def __init__(self, buildprops_file, api_root, auth, dummy=False):
self.buildbprops_file = buildprops_file
self.api_root = api_root
self.auth = auth
self.dummy = dummy

def generate_blob(self):
fp = open(self.buildbprops_file)
bp = json.load(fp)
fp.close()

props = bp['properties']
self.build_target = buildbot2updatePlatforms(props['platform'])[0]
buildID = props['buildid']

self.appName = props['appName']
self.branch = props['branch']
self.appVersion = props['appVersion']
self.name = get_nightly_blob_name(self.appName, self.branch,
self.build_type, buildID, self.dummy)
self.locale = props.get('locale', 'en-US')
blob = {
'appv': self.appVersion,
'extv': props.get('extVersion', self.appVersion),
'buildID': props['buildid'],
}
blob['complete'] = {
'from': '*',
'filesize': props['completeMarSize'],
'hashValue': props['completeMarHash'],
'fileUrl': props['completeMarUrl']
}
if props.get('partialMarFilename'):
blob['partial'] = {
'from': get_nightly_blob_name(self.appName, self.branch,
self.build_type,
props['previous_buildid'],
self.dummy),
'filesize': props['partialMarSize'],
'hashValue': props['partialMarHash'],
'fileUrl': props['partialMarUrl']
}
return blob

def run(self):
blob = self.generate_blob()
blob = json.dumps(blob)
api = API(auth=self.auth, api_root=self.api_root)
copy_to = [get_nightly_blob_name(
self.appName, self.branch, self.build_type, 'latest', self.dummy)]
copy_to = repr(copy_to)
api.update_build(name=self.name, product=self.appName,
build_target=self.build_target,
version=self.appVersion, locale=self.locale,
details=blob, copy_to=copy_to)
2 changes: 1 addition & 1 deletion lib/python/release/platforms.py
Expand Up @@ -49,7 +49,7 @@ def shippedlocales2buildbot(platform):
return [platform] return [platform]


def buildbot2updatePlatforms(platform): def buildbot2updatePlatforms(platform):
return update_platform_map.get(platform, platform) return update_platform_map.get(platform, [platform])


def getPlatformLocales(shipped_locales, platforms): def getPlatformLocales(shipped_locales, platforms):
platform_locales = {} platform_locales = {}
Expand Down

0 comments on commit d3004c2

Please sign in to comment.