Created
March 23, 2015 16:33
-
-
Save rail/b17f8011ba632ca6d4f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lib/python/balrog/submitter/cli.py | 24 ++++++++-------------- | |
.../test/test_balrog_submitter_cli.py | 1 + | |
2 files changed, 9 insertions(+), 16 deletions(-) | |
diff --git a/lib/python/balrog/submitter/cli.py b/lib/python/balrog/submitter/cli.py | |
index 0d9e385..4d99d4a 100644 | |
--- a/lib/python/balrog/submitter/cli.py | |
+++ b/lib/python/balrog/submitter/cli.py | |
@@ -242,21 +242,22 @@ class NightlySubmitterBase(object): | |
def __init__(self, api_root, auth, dummy=False, url_replacements=None): | |
self.api_root = api_root | |
self.auth = auth | |
self.dummy = dummy | |
self.url_replacements = url_replacements | |
def _replace_canocical_url(self, url): | |
- for string_from, string_to in self.url_replacements: | |
- if string_from in url: | |
- new_url = url.replace(string_from, string_to) | |
- log.warning("Replacing %s with %s", url, new_url) | |
- return new_url | |
+ if self.url_replacements: | |
+ for string_from, string_to in self.url_replacements: | |
+ if string_from in url: | |
+ new_url = url.replace(string_from, string_to) | |
+ log.warning("Replacing %s with %s", url, new_url) | |
+ return new_url | |
return url | |
def run(self, platform, buildID, productName, branch, appVersion, locale, | |
hashFunction, extVersion, schemaVersion, isOSUpdate=None, **updateKwargs): | |
assert schemaVersion in (3,4), 'Unhandled schema version %s' % schemaVersion | |
targets = buildbot2updatePlatforms(platform) | |
build_target = targets[0] | |
@@ -300,25 +301,16 @@ class NightlySubmitterBase(object): | |
version=appVersion, locale=locale, | |
hashFunction=hashFunction, | |
buildData=data, copyTo=copyTo, alias=alias, | |
schemaVersion=schemaVersion) | |
class MultipleUpdatesNightlyMixin(object): | |
- def _maybe_replace_canocical_url(self, url): | |
- # self._replace_canocical_url() and self.url_replacements come from | |
- # NightlySubmitterBase. Make sure they exist in concrete classes | |
- if getattr(self, '_replace_canocical_url', None) and \ | |
- getattr(self, 'url_replacements', None): | |
- return self._replace_canocical_url(url) | |
- else: | |
- return url | |
- | |
def _get_update_data(self, productName, branch, completeInfo=None, | |
partialInfo=None): | |
data = {} | |
if completeInfo: | |
data["completes"] = [] | |
for info in completeInfo: | |
if "from_buildid" in info: | |
@@ -327,29 +319,29 @@ class MultipleUpdatesNightlyMixin(object): | |
info["from_buildid"], | |
self.dummy) | |
else: | |
from_ = "*" | |
data["completes"].append({ | |
"from": from_, | |
"filesize": info["size"], | |
"hashValue": info["hash"], | |
- "fileUrl": self._maybe_replace_canocical_url(info["url"]), | |
+ "fileUrl": self._replace_canocical_url(info["url"]), | |
}) | |
if partialInfo: | |
data["partials"] = [] | |
for info in partialInfo: | |
data["partials"].append({ | |
"from": get_nightly_blob_name(productName, branch, | |
self.build_type, | |
info["from_buildid"], | |
self.dummy), | |
"filesize": info["size"], | |
"hashValue": info["hash"], | |
- "fileUrl": self._maybe_replace_canocical_url(info["url"]), | |
+ "fileUrl": self._replace_canocical_url(info["url"]), | |
}) | |
return data | |
class NightlySubmitterV3(NightlySubmitterBase, MultipleUpdatesNightlyMixin): | |
def run(self, *args, **kwargs): | |
return NightlySubmitterBase.run(self, *args, schemaVersion=3, **kwargs) | |
diff --git a/lib/python/mozilla_buildtools/test/test_balrog_submitter_cli.py b/lib/python/mozilla_buildtools/test/test_balrog_submitter_cli.py | |
index 8231639..d5fa66b 100644 | |
--- a/lib/python/mozilla_buildtools/test/test_balrog_submitter_cli.py | |
+++ b/lib/python/mozilla_buildtools/test/test_balrog_submitter_cli.py | |
@@ -13,16 +13,17 @@ class TestNightlySubmitterBase(unittest.TestCase): | |
self.assertEqual( | |
'http://download.cdn.mozilla.net/pub/mozilla.org/some/file', | |
submitter._replace_canocical_url( | |
'http://ftp.mozilla.org/pub/mozilla.org/some/file') | |
) | |
class TestNightlySubmitterV4(unittest.TestCase): | |
+ | |
def test_canonical_ur_replacement(self): | |
url_replacements = [ | |
("ftp.mozilla.org", "download.cdn.mozilla.net") | |
] | |
submitter = NightlySubmitterV4(api_root=None, auth=None, | |
url_replacements=url_replacements) | |
completeInfo = [{ | |
'size': 123, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment