Merge lp:~javier.collado/utah/bug1152216 into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: no longer in the source branch.
Merged at revision: 869
Proposed branch: lp:~javier.collado/utah/bug1152216
Merge into: lp:utah
Diff against target: 88 lines (+29/-1)
5 files modified
debian/changelog (+1/-0)
debian/control (+1/-1)
debian/rules (+7/-0)
examples/run_utah_tests.py (+2/-0)
utah/__init__.py (+18/-0)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1152216
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Approve
Review via email: mp+158437@code.launchpad.net

Description of the change

This branch writes to log the utah version number as soon as logging is
configured. Besides this, two new attributes have been created for the utah
module: __revno__ and __version__.

The idea is to reproduce the same version number as the one for the packages in
the launchpad PPA in a way that doesn't need to check the apt cache and with a
fallback version number when running the code from the branch:

$ python -c "import utah; print utah.__version__"
dev-r865~quantal

$ python -c "import utah; print utah.__version__"
0.10ubuntu1-r865~quantal

The new logging statement has only been added to run_utah_test.py, since the
other scripts are now considered to be deprecated.

To post a comment you must log in.
lp:~javier.collado/utah/bug1152216 updated
861. By Max Brustkern

Fixing call to sshcheck that doesn't match function signature

Revision history for this message
Javier Collado (javier.collado) wrote :

There's a problem with `bzr revno` when building the package with pbuilder. I'm
looking into it, so that the version number is correctly generated when
building in a PPA.

review: Needs Fixing
Revision history for this message
Javier Collado (javier.collado) wrote :

I've verified that the problem found with pbuilder is fixed and also used a
recipe to create a package in my ppa:
https://code.launchpad.net/~javier.collado/+archive/ppa

with the same format as the recipe being used for lp:utah.

After that, the version number using the code from the branch and the code in
the package version match the values in the original description of the merge
request.

Note that for a package that is built locally, the version number won't be the
same as if the package is built in the PPA because debian/changelog isn't
updated in the same way.

review: Needs Resubmitting
Revision history for this message
Max Brustkern (nuclearbob) wrote :

If I export the utah directory outside of a branch and try to import anything from the utah module, bzr revno fails, giving something like:
>>> import utah
bzr: ERROR: Not a branch: "/home/max/bzr/merges/utah/".
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "utah/__init__.py", line 22, in <module>
    __revno__ = check_output(['bzr', 'revno'], cwd=dirname(__file__)).rstrip()
  File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bzr', 'revno']' returned non-zero exit status 3

Maybe a try that catches CalledProcessError and sets __revno__ to None or 'unknown' in case of an exception would be good.

review: Needs Fixing
Revision history for this message
Javier Collado (javier.collado) wrote :

@Max

Thanks for your feedback. I've added a try/except block as you suggested using
'unknown' as a default value and now the implementation covers also the case in
which the branch isn't available.

review: Needs Resubmitting
lp:~javier.collado/utah/bug1152216 updated
862. By Max Brustkern

Merged iso squashfs validation update

863. By Javier Collado

Merged documentation string fixes

Source branch: lp:~javier.collado/utah/documentation_fixes

864. By Javier Collado

Merged changes to validate master runlist before provisioning (LP: #1082087)

Source branch: lp:~javier.collado/utah/bug1082087

865. By Javier Collado

Fix broken build

The package build is broken because a weird exception:
RuntimeError: sys.path must be a list of directory names

Looking in python source code I see this change:
http://hg.python.org/cpython/rev/c9bb16b7d148

that indeed changes what it was an ImportError to a RuntimeError. However, it's
not clear why PyList_Check(path) is failing because I'm pretty sure that
sys.path is a list (I even tried to filter it with os.path.isdir). Hence, I
guess that path in that code isn't really sys.path under some circumstances.

Anyway, catching that exception and handling it the same way as ImportError
works fine.

866. By Javier Collado

Merged changes to use socket timeout in SSH commands instead of SIGALRM (LP: #1169510)

Source branch: lp:~javier.collado/utah/bug1169510

Revision history for this message
Max Brustkern (nuclearbob) wrote :

I still get
bzr: ERROR: Not a branch: "/home/max/bzr/build/utah/".
but the imports work now. I'm not sure if we want to be passing that error through. If I set stderr to open('/dev/null', 'w') in the check_output call, it suppresses the output. If you think it makes sense to have that output, I'm fine either way.

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

Thanks for your feedback.

I didn't consider that important; but, given that the exception is caught, it
makes sense to discard the error using `os.devnull` to avoid confusion. I'll
update that and merge.

lp:~javier.collado/utah/bug1152216 updated
867. By Javier Collado

Merged changes to make rsyslog timeout error message clearer (LP: #1169846)

Source branch: lp:~javier.collado/utah/bug1169846

868. By Javier Collado

Merged changes to choose battery implementation for a test run

Source branch: lp:~doanac/utah/pluggable-battery

874. By Javier Collado

Avoid using `bzr revno` when getting the version number from the package

The branch is might not be available when building the package, so calling
`bzr` will fail in such a case. However, given that the revision number is
already added to the changelog by the recipe, it's not really needed.

875. By Javier Collado

Added missing build dependency

876. By Javier Collado

Make sure __init__ is updated before make is executed

877. By Javier Collado

Removed distro from version in package since it's added by the PPA

878. By Javier Collado

Remove all imports in the packaged utah.__init__.py file

Since both revision number and distro are already in the changelog when the
package is built in the PPA, none of the imports is used.

879. By Javier Collado

Use fallback value if now bzr branch is available

As pointed out by Max, it might happen that no bzr branch is available when
getting the version information from the source.

880. By Javier Collado

Fixed escape dollar sign

881. By Javier Collado

Fixed regular expression

882. By Javier Collado

Discard bzr error when branch is not found

Revision history for this message
Javier Collado (javier.collado) wrote :

Rebased changes to fix conflict in debian/changelog

Revision history for this message
Javier Collado (javier.collado) wrote :

I successfully tested locally and with a package build in a PPA.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-04-19 15:39:55 +0000
3+++ debian/changelog 2013-04-19 16:14:26 +0000
4@@ -7,6 +7,7 @@
5 [ Javier Collado ]
6 * Use socket timeout in SSH commands instead of SIGALRM (LP: #1169510)
7 * Make rsyslog timeout error message clearer (LP: #1169846)
8+ * Write to log UTAH version as soon as possible (LP: #1152216)
9
10 -- Max Brustkern <max@canonical.com> Tue, 16 Apr 2013 09:21:19 -0400
11
12
13=== modified file 'debian/control'
14--- debian/control 2013-04-01 11:19:35 +0000
15+++ debian/control 2013-04-19 16:14:26 +0000
16@@ -3,7 +3,7 @@
17 X-Python-Version: >= 2.5
18 Priority: optional
19 Maintainer: Max Brustkern <max@canonical.com>
20-Build-Depends: debhelper (>= 7.0.50~), devscripts,
21+Build-Depends: debhelper (>= 7.0.50~), devscripts, gawk,
22 python-all, python-bzrlib, python-netifaces, python-psutil,
23 python-sphinx, python-jsonschema (>= 0.5~)
24 Standards-Version: 3.9.3
25
26=== modified file 'debian/rules'
27--- debian/rules 2012-12-12 22:34:14 +0000
28+++ debian/rules 2013-04-19 16:14:26 +0000
29@@ -12,6 +12,13 @@
30 dh_auto_clean
31
32 override_dh_auto_build:
33+ # Set __version__ in utah package to version number in debian/changelog
34+ sed -i -r "\
35+ s/^(__version__ =) .*/\1 \
36+ '$(shell dpkg-parsechangelog | gawk '/^Version:/ {print $$2}')'/;\
37+ /^import/,/__revno__ = 'unknown'$$/d;\
38+ " \
39+ utah/__init__.py
40 make
41 set -e && for pyvers in $(PYVERS); do python$$pyvers setup.py build; done
42 dh_auto_build
43
44=== modified file 'examples/run_utah_tests.py'
45--- examples/run_utah_tests.py 2013-04-19 11:42:45 +0000
46+++ examples/run_utah_tests.py 2013-04-19 16:14:26 +0000
47@@ -22,6 +22,7 @@
48 import sys
49 from traceback import format_exception
50
51+import utah
52 from utah import config
53 from utah.cleanup import cleanup
54 from utah.group import check_user_group, print_group_error_message
55@@ -84,6 +85,7 @@
56 machinetype = args.machinetype
57
58 configure_logging(args.debug)
59+ logging.info('UTAH version: %s', utah.__version__)
60
61 # Default is now CustomVM
62 function = run_install_test
63
64=== modified file 'utah/__init__.py'
65--- utah/__init__.py 2013-04-04 13:42:40 +0000
66+++ utah/__init__.py 2013-04-19 16:14:26 +0000
67@@ -14,3 +14,21 @@
68 # with this program. If not, see <http://www.gnu.org/licenses/>.
69
70 """utah"""
71+
72+import os
73+import os.path
74+from platform import linux_distribution as distro
75+from subprocess import (
76+ CalledProcessError,
77+ check_output,
78+)
79+
80+try:
81+ with open(os.devnull, 'w') as devnull:
82+ __revno__ = check_output(['bzr', 'revno'],
83+ cwd=os.path.dirname(__file__),
84+ stderr=devnull).rstrip()
85+except CalledProcessError:
86+ __revno__ = 'unknown'
87+
88+__version__ = 'dev-r{}~{}'.format(__revno__, distro()[-1])

Subscribers

People subscribed via source and target branches