Monday 6 February 2012

Testing BuildRequires with Mock

Recently working with spec files I've learned BuildRequires are packages required to build the software. In this post I will give my experience using Mock which is used to test a packages BuildRequires. This will help us test that the BuildRequires are complete and accurate without anything missing.

To get started setting up Mock, I installed the mock package with this command:
yum install mock

Then I had to add my username to the mock group:
usermod -aG mock namnguyen

After adding my username to the mock group I ran mock as superuser and received this error message as I did not change to my regular account which I had just added to the mock group.

[root@timeline ~]# mock -r fedora-16-x86_64 ~/rpmbuild/SRPMS/gnuchess-6.0.1-1.fc16.src.rpm
ERROR: mock will not run from the root account (needs an unprivileged uid so it can drop privs)

I then changed to the regular user account that I added to the mock group and was then able to run mock on my SRPM.

[namnguyen@timeline ~]$ mock -r fedora-16-x86_64 ~/rpmbuild/SRPMS/gnuchess-6.0.1-1.fc16.src.rpm
INFO: mock.py version 1.1.19 starting...
State Changed: init plugins
INFO: selinux enabled
State Changed: start
INFO: Start(/home/namnguyen/rpmbuild/SRPMS/gnuchess-6.0.1-1.fc16.src.rpm)  Config(fedora-16-x86_64)
State Changed: lock buildroot
State Changed: clean
INFO: chroot (/var/lib/mock/fedora-16-x86_64) unlocked and deleted
State Changed: unlock buildroot
State Changed: init
State Changed: lock buildroot
Mock Version: 1.1.19
INFO: Mock Version: 1.1.19
INFO: calling preinit hooks
INFO: enabled root cache
INFO: enabled yum cache
State Changed: cleaning yum metadata
INFO: enabled ccache
State Changed: running yum
State Changed: creating cache
State Changed: unlock buildroot
INFO: Installed packages:
State Changed: setup
State Changed: build
INFO: Done(/home/namnguyen/rpmbuild/SRPMS/gnuchess-6.0.1-1.fc16.src.rpm) Config(fedora-16-x86_64) 2 minutes 34 seconds
INFO: Results and/or logs in: /var/lib/mock/fedora-16-x86_64/result
State Changed: end

The first time I had ran this command it hung on "State Changed: running yum" for 10 minutes before I interrupt and exited. Not really sure why it hung there I checked /var/lib/mock/fedora-16-x86_64/result/build.log for any info and results. The only info within build.log was one line that showed Mock Version: 1.1.19. I gave mock another try and this time it continued on past "Stage Changed: running yum" and continued until it was done.

The second attempt had only taken 2 minutes 34 seconds and right now I'm not really sure why mock was not successful on the first attempt but was successful on the second attempt. My experience using mock in this process had taken an hour and a half of which a lot of time was spent on searching for the reason for my issue that I mentioned above.


1 comment:

  1. It hangs the first time you run it because yum needs to build up the package cache (downloading and installing all of the required packages takes a long time!).

    ReplyDelete