Closed Bug 1151954 Opened 9 years ago Closed 8 years ago

Migrate releases-related/get_apk.sh to mozharness

Categories

(Release Engineering :: Applications: MozharnessCore, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Sylvestre, Assigned: alex_johnson, Mentored)

References

Details

(Whiteboard: [good first bug][lang=Python])

Attachments

(1 file, 5 obsolete files)

This script allows release managers to download apk from our ftp:
http://hg.mozilla.org/build/braindump/file/tip/releases-related/get_apk.sh

We should convert it to a Python mozharness script.
Blocks: 1151955
I would like to take a look at. Please assign to me.
I would start to work on this bug, and I will commit first patch as soon as possible, Please assign it to me.
Well, you both asked for this bug. I will assign it to the one you write the first patch...
Flags: needinfo?(sifiebel)
Flags: needinfo?(sabergeass)
Oh, before I forget, managing the armv6 files is no longer necessary. This can be dropped. The code is going to be simplified.
For example:
http://hg.mozilla.org/build/braindump/file/tip/releases-related/get_apk.sh#l56
Sorry for the late reply. 
I haven't know much a bout shell, I can see three function in this shell script but I can't find where they be called. Could you offer me some document about that or tell me how these function works? Thank you very much!
Flags: needinfo?(sabergeass)
(In reply to MikeLing from comment #6)
> Sorry for the late reply. 
> I haven't know much a bout shell, I can see three function in this shell
> script but I can't find where they be called. Could you offer me some
> document about that or tell me how these function works? Thank you very much!

Hm, I think I figure out how bash function goes. I will commit my first version patch ASAP :)
Hello~ 

Could you tell me more about this line(http://hg.mozilla.org/build/braindump/file/tip/releases-related/get_apk.sh#l48)? I don't know how to apply the 'MAJOR' into python.

And I would like to use argparse to fix this issues like:

>def parse_args()
>    parser = argparse.ArgumentParser()
>    parser.add_argument('version number', dest='version_number',help='version number to download')
>    parser.add_argument('-b', '--build',default=1, help='specify build number and default is 1',
>   					 dest='specify_number')
>    return parser.parse_args()
>.......
>def main():
>    action = parse_args()
>    if action.version_number not None:
>               download_function_called()
>    else:
>               exit()

It's a lot different with the example you give. So,please tell me if I couldn't code like that. Thank you :)
> I don't know how to apply the 'MAJOR' into python.
The MAJOR variable is used to detect the major version of Firefox to manage the different layout.
As mentioned in comment #5, this can be dropped (and I think MAJOR might be useless in this context).

> please tell me if I couldn't code like that. 
The argument management is done by Mozharness, you should use this API and not argparse.
Flags: needinfo?(sifiebel)
Hi, aspiring new contributor here. I'm going to try tackling this.
Hi, I'm a new contributor. I'd like to try handling this bug.
Attached patch bug-1151954.patch (obsolete) — Splinter Review
Assignee: nobody → me
Status: NEW → ASSIGNED
Attachment #8703343 - Flags: review?(sledru)
Attached patch bug-1151954.patch (obsolete) — Splinter Review
Fixed some nits.
Attachment #8703343 - Attachment is obsolete: true
Attachment #8703343 - Flags: review?(sledru)
Attachment #8703368 - Flags: review?(sledru)
Comment on attachment 8703368 [details] [diff] [review]
bug-1151954.patch

Alex, great to see progress on this and it looks a first version!

Some comments:
* when getting a 404, we should not retry, just fail with an error
* when no version is provided, we should download the two arm and the i386
* I think we can download the apk in the current directory (not build/)
* having a test would be great
* flake8 founds two warnings:
 - get_apk.py:86:39: E126 continuation line over-indented for hanging indent
 - get_apk.py:161:28: W292 no newline at end of file
Attachment #8703368 - Flags: review?(sledru) → review-
Sylvestre, I'm having a hard time finding where the test for push_apk is located.  I want to use that as a reference to make a test for get_apk.  Could you point me in the right direction?
Flags: needinfo?(sledru)
For now, this is not great:
https://hg.mozilla.org/build/mozharness/file/tip/scripts/push_apk.py#l193

I think we need to experiment something better in the future!
Flags: needinfo?(sledru)
Attached patch bug-1151954.patch (obsolete) — Splinter Review
Attachment #8703368 - Attachment is obsolete: true
Attachment #8703743 - Flags: review?(sledru)
Attached patch bug-1151954.patch (obsolete) — Splinter Review
The change to the .hgignore would've caused a merge conflict, got that fixed.
Attachment #8703743 - Attachment is obsolete: true
Attachment #8703743 - Flags: review?(sledru)
Attachment #8703749 - Flags: review?(sledru)
About the test, we don't want to test the network (moreover, we don't want to update the code each time the mozilla favicon changes). We want to test the code itself (like with unit test)
Comment on attachment 8703749 [details] [diff] [review]
bug-1151954.patch



>+        apk_checksum = self.file_sha512sum(apk_file)
Could you display a message that we are checking the checksum?
>+    def download(self, filename, url):
>+        ScriptMixin.mkdir_p(self, self.download_dir)
>+
>+        apk_url = url + ".apk"
You can probably declare .apk as a member of the class and reuse it everywhere

>+    def download_all(self, version, build, locale):
>+        filename_x86 = "fennec-" + version + "." + locale + "." + "android-" + self.get_arch_file("x86")
>+        url = self.generate_url(version, "x86", build, locale, self.get_android_layout("x86"), self.get_arch_file("x86"))
>+        self.download(filename_x86, url)
What about adding a variable
commonFileName = "fennec-" + version + "." + locale + "." + "android-"
and reuse it?
(or move that into a method)


>+        filename_arm_v9 = "fennec-" + version + "." + locale + ".android-arm-api-9"
>+        url = self.generate_url(version, "arm", build, locale, "android-api-9", self.get_arch_file("arm"))
>+        self.download(filename_arm_v9, url)
>+
>+        filename_arm_v11 = "fennec-" + version + "." + locale + ".android-arm-api-11"
>+        url = self.generate_url(version, "arm", build, locale, "android-api-11", self.get_arch_file("arm"))
>+        self.download(filename_arm_v11, url)
>+
>+    def get_android_layout(self, arch):
>+        if arch == "arm":
>+            return "v9_v11"
>+        else:
>+            return "android-"+arch
>+
>+    def get_arch_file(self, arch):
>+        if arch == "x86":
>+            # the filename contains i386 instead of x86
>+            return "i386"
>+        else:
>+            return arch
>+
>+    def download_apk(self):
>+        self.check_argument()
>+        version = self.config["version"]
>+        arch = self.config["arch"]
>+        build = str(self.config["build"])
>+        locale = self.config["locale"]
>+
>+        android_layout = self.get_android_layout(arch)
>+
>+        arch_file = self.get_arch_file(arch)
>+
>+        self.info("Downloading version " + version + " build #" + build
>+                  + " for arch " + arch + " (locale " + locale + ")")
>+        if arch == "all":
>+            self.download_all(version, build, locale)
>+        elif android_layout == "v9_v11":
>+            # When dealing with API v9 & V11, we want to rename the file
>+            # until bug 1122059 is fixed
>+            # Also manage the KO locale
>+            filename_arm_v9 = "fennec-" + version + "." + locale + ".android-arm-api-9"
This looks like a duplicate declaration, isn't it?

Besides that, it looks good.
When fixed, do you need me to push the change for you?
Attachment #8703749 - Flags: review?(sledru) → feedback+
I'm trying to come up with a better test to write, but I can't think of a way to do that without downloading an apk file, which are pretty large. It would make the test long. Could we make a test-candidates directory path on the ftp server with a test.apk file and an associated checksums file?
Flags: needinfo?(sledru)
Sorry, I wasn't clear enough here.
You don't need to download actual file.
You could test the various method like get_arch_file, get_android_layout, this kind of method unit tests.
Flags: needinfo?(sledru)
Attached patch bug-1151954.patch (obsolete) — Splinter Review
I ended up changing a lot of the code in the process of subdiving the download() function into different functions for easy testing.  Could you review this again?  Sorry!  

And could you push it if it looks good? I only have LDAP level 1 access.
Attachment #8703749 - Attachment is obsolete: true
Attachment #8704975 - Flags: review?(sledru)
fyi - api-11 has changed to api-15 on trunk and will ride the trains

see: https://bugzilla.mozilla.org/show_bug.cgi?id=1219094
I have added a config to the top of the script to allow changing the multi api names pretty easily.  Sylvestre, what do you think?
Flags: needinfo?(sledru)
ScriptMixin doesn't need to be an argument for GetAPK.  Fixed that.
Attachment #8704975 - Attachment is obsolete: true
Attachment #8704975 - Flags: review?(sledru)
Attachment #8708741 - Flags: review?(sledru)
Comment on attachment 8708741 [details] [diff] [review]
bug-1151954.patch

This is great, many thanks. Need me to commit it for you?
Flags: needinfo?(sledru)
Attachment #8708741 - Flags: review?(sledru) → review+
Yes please!
Many thanks again, here it is:
https://hg.mozilla.org/build/mozharness/rev/15845edae9a1
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
I believe this was committed to the wrong repo -- all test scripts are in-tree now.

Please re-land where it will be of some use (I don't have the chops) ;)
Status: RESOLVED → REOPENED
Flags: needinfo?(sledru)
Resolution: FIXED → ---
Oh, crap... I didn't notice that the hgignore is incorrect and Alex is not marked as author ... :(
sorry Alex...
Status: REOPENED → RESOLVED
Closed: 8 years ago8 years ago
Flags: needinfo?(sledru)
Resolution: --- → FIXED
Sylvestre, would you like me to move the changes to mozinbound and submit another patch?
Flags: needinfo?(sledru)
I took care of that, don't worry :)
Flags: needinfo?(sledru)
Depends on: 1257605
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: