Closed Bug 796017 Opened 12 years ago Closed 11 years ago

mozinstall needs tests

Categories

(Testing :: Mozbase, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: k0scist, Assigned: ffledgling)

References

Details

Attachments

(5 files, 3 obsolete files)

mozinstall currently has no tests:
https://github.com/mozilla/mozbase/tree/master/mozinstall

Instead, it should have tests.
Attached file Stub installer for dmg
This is the .dmg I'm currently using. It was made on MacOSX (10.7).
The contents are 4 files, namely - 'foo', 'bar', 'f00' and 'b4r'
For posterity; ht tp://pastebin.mozilla.org/2569897 ->

  File "/Users/Jain/anhad/lulz2/bin/mozinstall", line 8, in <module>
    load_entry_point('mozInstall==1.6', 'console_scripts', 'mozinstall')()
  File "/Users/Jain/anhad/lulz2/mozbase/mozinstall/mozinstall/mozinstall.py", line 300, in install_cli
    install_path = install(src, options.dest)
  File "/Users/Jain/anhad/lulz2/mozbase/mozinstall/mozinstall/mozinstall.py", line 118, in install
    install_dir = _install_dmg(src, dest)
  File "/Users/Jain/anhad/lulz2/mozbase/mozinstall/mozinstall/mozinstall.py", line 235, in _install_dmg
    mounted_path = os.path.join(appDir, appName)
mozinstall.mozinstall.InstallError: Failed to install "/Users/Jain/anhad/firefox-installer-stub-compressed.dmg"
I was able to mount the firefox .dmg using dmg2img:

│dmg2img Firefox\ 22.0.dmg 

dmg2img v1.6.2 is derived from dmg2iso by vu1tur (to@vu1tur.eu.org)

Firefox 22.0.dmg --> Firefox 22.0.img

reading property list, 27293 bytes from address 42270950 ...

decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok

Archive successfully decompressed as Firefox 22.0.img

You should be able to mount the image [as root] by:

modprobe hfsplus
mount -t hfsplus -o loop Firefox 22.0.img /mnt

│sudo su
[sudo] password for jhammel: 
root@jhammel-ThinkPad-X230:/home/jhammel/tmp# modprobe hfsplus
root@jhammel-ThinkPad-X230:/home/jhammel/tmp# mount -t hfsplus -o loop 'Firefox 22.0.img' /mnt
root@jhammel-ThinkPad-X230:/home/jhammel/tmp# mount
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfsd-fuse on /run/user/jhammel/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=jhammel)
/home/jhammel/tmp/Firefox 22.0.img on /mnt type hfsplus (rw)
root@jhammel-ThinkPad-X230:/home/jhammel/tmp# ls /mnt/
                  .DS_Store         .VolumeIcon.icns  
.background/      Firefox.app/      
root@jhammel-ThinkPad-X230:/home/jhammel/tmp# ls /mnt/Firefox.app/
Contents  precomplete
Depends on: 888741, 888756
Attached patch Patch for mozinstall tests (obsolete) — Splinter Review
This is the text-only patch for the added tests for mozinstall. They depend on the existance of 4 stub installers in a directory `mozinstall/tests/Installer-Stubs`.

This patch is also dependent on two other small bugs Bug 888741 and Bug 888756, and assumes that the patches for those have been applied.

I have tested the working of this patch on WindowsXP, Linux and MacOSX and all tests are passing for me locally.
Attachment #769519 - Flags: review?(wlachance)
Attachment #769519 - Flags: feedback?(jhammel)
These are the stubs in 4 formats, .dmg, .exe, .tar.bz2 and .zip. These are  used by the tests for mozinstall. These 4 stub files should be placed under mozinstall/tests/Installer-Stubs/ .

:jhammel could be please take a look at these and tell me if this is what you had in mind for the stub installers? Thanks!
Attachment #769520 - Flags: feedback?(jhammel)
Assignee: nobody → ffledgling
Comment on attachment 769520 [details]
Tarball of the stubs used by mozinstall patch

Looks fine at a glance.  As long as it works!
Attachment #769520 - Flags: feedback?(jhammel) → feedback+
Comment on attachment 769519 [details] [diff] [review]
Patch for mozinstall tests

Review of attachment 769519 [details] [diff] [review]:
-----------------------------------------------------------------

::: mozinstall/tests/test.py
@@ +1,1 @@
> +import mozinfo

shebang please

@@ +3,5 @@
> +import mozfile
> +import os
> +import tarfile
> +import tempfile
> +import urllib2

unused

@@ +11,5 @@
> +
> +class TestMozInstall(unittest.TestCase):
> +
> +    @classmethod
> +    def setUpClass(self):

cls, not self
Attachment #769519 - Flags: feedback?(jhammel) → feedback+
Fixed corrections pointed out by :jhammel
Attachment #769519 - Attachment is obsolete: true
Attachment #769519 - Flags: review?(wlachance)
Attachment #769823 - Flags: feedback?(jhammel)
Attachment #769823 - Flags: feedback?(jhammel) → review?(jhammel)
Comment on attachment 769823 [details] [diff] [review]
Updated patch with corrections for mozinstall tests

Review of attachment 769823 [details] [diff] [review]:
-----------------------------------------------------------------

Pretty good, but please fix the listed nits.

::: mozinstall/tests/test.py
@@ +18,5 @@
> +
> +    @classmethod
> +    def setUpClass(cls):
> +        """ Setting up stub installers """
> +        cls.dmg = os.path.join('Installer-Stubs', 'firefox.dmg')

These should be relative to the file, AIUI; can you make these absolute paths?

@@ +59,5 @@
> +
> +    def test_get_binary_error(self):
> +        """ Test an InvalidBinary error is raised """
> +
> +        tempdir_empty = tempfile.mkdtemp()

You'll need to clean up this directory.

@@ +141,5 @@
> +
> +        elif mozinfo.isMac:
> +            installdir = mozinstall.install(self.dmg, self.tempdir)
> +            mozinstall.uninstall(installdir)
> +            self.assertFalse(os.path.exists(installdir))

You'll need a section for running manually:

if __name__ == '__main__':
    unittest.main()
Attachment #769823 - Flags: review?(jhammel) → review-
Attached patch Patch for mozinstall tests (obsolete) — Splinter Review
Attachment #769823 - Attachment is obsolete: true
Attachment #769916 - Flags: review?(jhammel)
(In reply to Anhad Jai Singh (:ffledgling) from comment #12)
> Created attachment 769916 [details] [diff] [review]
> Patch for mozinstall tests

should be checked in with the stubs: 

(mozbase)│curl https://bug796017.bugzilla.mozilla.org/attachment.cgi?id=769520 | tar xvf -
Attachment #769916 - Flags: review?(jhammel) → review+
hmmm....it runs fine from the directory, but from test.py 


======================================================================
ERROR: test_get_binary (test.TestMozInstall)
Test mozinstall's get_binary method
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 38, in test_get_binary
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
ERROR: test_install (test.TestMozInstall)
Test mozinstall's install capability
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 103, in test_install
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
ERROR: test_uninstall (test.TestMozInstall)
Test mozinstall's uninstall capabilites
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 127, in test_uninstall
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
ERROR: test_get_binary (test.TestMozInstall)
Test mozinstall's get_binary method
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 38, in test_get_binary
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
ERROR: test_install (test.TestMozInstall)
Test mozinstall's install capability
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 103, in test_install
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
ERROR: test_uninstall (test.TestMozInstall)
Test mozinstall's uninstall capabilites
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 127, in test_uninstall
    installdir = mozinstall.install(self.bz2, self.tempdir)
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/mozinstall/mozinstall.py", line 107, in install
    '(zip, exe, tar.gz, tar.bz2 or dmg)')
InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)

======================================================================
FAIL: test_is_installer (test.TestMozInstall)
Test we can identify a correct installer
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 73, in test_is_installer
    self.assertTrue(mozinstall.is_installer(self.bz2))
AssertionError: False is not true

======================================================================
FAIL: test_is_installer (test.TestMozInstall)
Test we can identify a correct installer
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jhammel/mozbase/src/mozbase/mozinstall/tests/test.py", line 73, in test_is_installer
    self.assertTrue(mozinstall.is_installer(self.bz2))
AssertionError: False is  not true

----------------------------------------------------------------------
Ran 151 tests in 16.198s

FAILED (failures=2, errors=6)


Can you confirm this ?
very suspicious: InvalidSource: /home/jhammel/mozbase/src/mozbase/moztest/tests/Installer-Stubs/firefox.tar.bz2 is not a recognized file type (zip, exe, tar.gz, tar.bz2 or dmg)
Confirming that I'm getting the same error when I run all tests together.

However, even more strange, when I run a custom manifest with only [include:mozinstall/tests/manifest.ini] in it, all tests pass again. Looking into what the problem could be.
:ahal pointed out that the issue was with setting the path for the stubs during class instantiation rather than at the time of module load. Changing it accordingly fixed the error.
Attachment #769916 - Attachment is obsolete: true
Attachment #770191 - Flags: review?(jhammel)
Attachment #770191 - Flags: review?(jhammel) → review+
pushed: https://github.com/mozilla/mozbase/commit/3b5a4ab279bd80c6101627c110472b59cd29424a
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Hey Jeff, The .exe from the stubs doesn't seem to have made it to the master in mozinstall, any idea about this?
Flags: needinfo?(jhammel)
(In reply to Anhad Jai Singh (:ffledgling) from comment #19)
> Hey Jeff, The .exe from the stubs doesn't seem to have made it to the master
> in mozinstall, any idea about this?

So this didn't get added because I did not notice in the adding the stubs that it was .gitignored : https://github.com/mozilla/mozbase/blob/master/.gitignore#L10
Flags: needinfo?(jhammel)
If approved, I'll commit along with the firefox.exe that got gitignored
Attachment #772730 - Flags: review?(wlachance)
Comment on attachment 772730 [details] [diff] [review]
git ignore moar better

This patch is fine.
Attachment #772730 - Flags: review?(wlachance) → review+
When I tested this on Friday on my Windows XP VM, the tests were failing, and not just because of missing exes (all the different mozinstall tests were failing). We need to figure out what's wrong here...
(In reply to William Lachance (:wlach) from comment #23)
> When I tested this on Friday on my Windows XP VM, the tests were failing,
> and not just because of missing exes (all the different mozinstall tests
> were failing). We need to figure out what's wrong here...

a traceback would be lovely; should we disable the tests for the time being?
(In reply to William Lachance (:wlach) from comment #22)
> Comment on attachment 772730 [details] [diff] [review]
> git ignore moar better
> 
> This patch is fine.

pushed: https://github.com/mozilla/mozbase/commit/9fc4e9bd544092167edeefeac2cd0c963649700a
(In reply to Jeff Hammel [:jhammel] from comment #24)
> (In reply to William Lachance (:wlach) from comment #23)
> > When I tested this on Friday on my Windows XP VM, the tests were failing,
> > and not just because of missing exes (all the different mozinstall tests
> > were failing). We need to figure out what's wrong here...
> 
> a traceback would be lovely; should we disable the tests for the time being?

Attached a traceback. I'd prefer to fix the tests assuming the problem isn't that difficult to resolve. Any ideas :ffledgling?
Flags: needinfo?(ffledgling)
We should reopen the bug given that the work hasn't been finished yet.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
I'm not very sure why the tests are failing for :wlach the way they are, I'm wasn't getting any errors on my local VM after the .exe fix, so as :wlach has suggested earlier pushed to try with the new tests. I did a run on WinXP, OSX10.7 and 64-bitFedora. All the tests seemed to have passed on try.

So I'm still not really sure what might be causing the problem.

https://tbpl.mozilla.org/?tree=Try&rev=d6a06ca47811

http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/ffledgling@gmail.com-d6a06ca47811/
On closer inspection, it appears the issue was that I was using an old version of mozilla-build with Python 2.6. After upgrading to the newest with Python 2.7, everything works fine.

The underlying issue is that mozinstall's test case uses a method called setupClass, which is only called in 2.7 or greater. That's not a problem though, since we're (AFAIK) only running these tests in a 2.7 environment:

http://docs.python.org/2/library/unittest.html#unittest.TestCase.setUpClass

(In reply to Anhad Jai Singh (:ffledgling) from comment #29)
> I'm not very sure why the tests are failing for :wlach the way they are, I'm
> wasn't getting any errors on my local VM after the .exe fix, so as :wlach
> has suggested earlier pushed to try with the new tests. I did a run on
> WinXP, OSX10.7 and 64-bitFedora. All the tests seemed to have passed on try.
> 
> So I'm still not really sure what might be causing the problem.
> 
> https://tbpl.mozilla.org/?tree=Try&rev=d6a06ca47811
> 
> http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/ffledgling@gmail.
> com-d6a06ca47811/
Status: REOPENED → RESOLVED
Closed: 11 years ago11 years ago
Resolution: --- → FIXED
Flags: needinfo?(ffledgling)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: